@@ -141,7 +141,7 @@ func (d *GatherJob) GatherAndUpload(kubeConfig, protoKubeConfig *rest.Config) er
141
141
return err
142
142
}
143
143
144
- dataGatherCR , err = updateDataGatherStatus (ctx , * insightClient , dataGatherCR .DeepCopy (), insightsv1alpha1 .Pending , nil )
144
+ dataGatherCR , err = status . UpdateDataGatherStatus (ctx , insightClient , dataGatherCR .DeepCopy (), insightsv1alpha1 .Pending , nil )
145
145
if err != nil {
146
146
klog .Error ("failed to update coresponding DataGather custom resource: %v" , err )
147
147
return err
@@ -180,7 +180,7 @@ func (d *GatherJob) GatherAndUpload(kubeConfig, protoKubeConfig *rest.Config) er
180
180
)
181
181
uploader := insightsuploader .New (nil , insightsClient , configObserver , nil , nil , 0 )
182
182
183
- dataGatherCR , err = updateDataGatherStatus (ctx , * insightClient , dataGatherCR , insightsv1alpha1 .Running , nil )
183
+ dataGatherCR , err = status . UpdateDataGatherStatus (ctx , insightClient , dataGatherCR , insightsv1alpha1 .Running , nil )
184
184
if err != nil {
185
185
klog .Error ("failed to update coresponding DataGather custom resource: %v" , err )
186
186
return err
@@ -214,7 +214,7 @@ func (d *GatherJob) GatherAndUpload(kubeConfig, protoKubeConfig *rest.Config) er
214
214
if err != nil {
215
215
conditions = append (conditions , status .DataRecordedCondition (metav1 .ConditionFalse , "RecordingFailed" ,
216
216
fmt .Sprintf ("Failed to record data: %v" , err )))
217
- _ , recErr := updateDataGatherStatus (ctx , * insightClient , dataGatherCR , insightsv1alpha1 .Failed , conditions )
217
+ _ , recErr := status . UpdateDataGatherStatus (ctx , insightClient , dataGatherCR , insightsv1alpha1 .Failed , conditions )
218
218
if recErr != nil {
219
219
klog .Error ("data recording failed and the update of DataGaher resource status failed as well: %v" , recErr )
220
220
}
@@ -229,7 +229,7 @@ func (d *GatherJob) GatherAndUpload(kubeConfig, protoKubeConfig *rest.Config) er
229
229
klog .Error (err )
230
230
conditions = append (conditions , status .DataUploadedCondition (metav1 .ConditionFalse , reason ,
231
231
fmt .Sprintf ("Failed to upload data: %v" , err )))
232
- _ , updateErr := updateDataGatherStatus (ctx , * insightClient , dataGatherCR , insightsv1alpha1 .Failed , conditions )
232
+ _ , updateErr := status . UpdateDataGatherStatus (ctx , insightClient , dataGatherCR , insightsv1alpha1 .Failed , conditions )
233
233
if updateErr != nil {
234
234
klog .Error ("data upload failed and the update of DataGaher resource status failed as well: %v" , updateErr )
235
235
}
@@ -240,7 +240,7 @@ func (d *GatherJob) GatherAndUpload(kubeConfig, protoKubeConfig *rest.Config) er
240
240
dataGatherCR .Status .InsightsRequestID = insightsRequestID
241
241
conditions = append (conditions , status .DataUploadedCondition (metav1 .ConditionTrue , reason , "" ))
242
242
243
- _ , err = updateDataGatherStatus (ctx , * insightClient , dataGatherCR , insightsv1alpha1 .Completed , conditions )
243
+ _ , err = status . UpdateDataGatherStatus (ctx , insightClient , dataGatherCR , insightsv1alpha1 .Completed , conditions )
244
244
if err != nil {
245
245
klog .Error (err )
246
246
return err
@@ -271,26 +271,3 @@ func record(functionReports []gather.GathererFunctionReport,
271
271
}
272
272
return recdriver .LastArchive ()
273
273
}
274
-
275
- // updateDataGatherStatus updates status' time attributes, state and conditions
276
- // of the provided DataGather resource
277
- func updateDataGatherStatus (ctx context.Context ,
278
- insightsClient insightsv1alpha1cli.InsightsV1alpha1Client ,
279
- dataGatherCR * insightsv1alpha1.DataGather ,
280
- newState insightsv1alpha1.DataGatherState , conditions []metav1.Condition ) (* insightsv1alpha1.DataGather , error ) {
281
- switch newState {
282
- case insightsv1alpha1 .Completed :
283
- dataGatherCR .Status .FinishTime = metav1 .Now ()
284
- case insightsv1alpha1 .Failed :
285
- dataGatherCR .Status .FinishTime = metav1 .Now ()
286
- case insightsv1alpha1 .Running :
287
- dataGatherCR .Status .StartTime = metav1 .Now ()
288
- case insightsv1alpha1 .Pending :
289
- // no op
290
- }
291
- dataGatherCR .Status .State = newState
292
- if conditions != nil {
293
- dataGatherCR .Status .Conditions = append (dataGatherCR .Status .Conditions , conditions ... )
294
- }
295
- return insightsClient .DataGathers ().UpdateStatus (ctx , dataGatherCR , metav1.UpdateOptions {})
296
- }
0 commit comments