@@ -65,21 +65,21 @@ func mergeEqualVersions(current *configv1.UpdateHistory, desired configv1.Releas
65
65
return false
66
66
}
67
67
68
- func mergeOperatorHistory (config * configv1.ClusterVersion , desired configv1.Release , verified bool , now metav1.Time ,
68
+ func mergeOperatorHistory (cvStatus * configv1.ClusterVersionStatus , desired configv1.Release , verified bool , now metav1.Time ,
69
69
completed bool , acceptedRisksMsg string , localPayload bool ) {
70
70
71
71
// if we have no image, we cannot reproduce the update later and so it cannot be part of the history
72
72
if len (desired .Image ) == 0 {
73
73
// make the array empty
74
- if config . Status .History == nil {
75
- config . Status .History = []configv1.UpdateHistory {}
74
+ if cvStatus .History == nil {
75
+ cvStatus .History = []configv1.UpdateHistory {}
76
76
}
77
77
return
78
78
}
79
79
80
- if len (config . Status .History ) == 0 {
80
+ if len (cvStatus .History ) == 0 {
81
81
klog .V (2 ).Infof ("initialize new history completed=%t desired=%#v" , completed , desired )
82
- config . Status . History = append (config . Status .History , configv1.UpdateHistory {
82
+ cvStatus . History = append (cvStatus .History , configv1.UpdateHistory {
83
83
Version : desired .Version ,
84
84
Image : desired .Image ,
85
85
@@ -89,7 +89,7 @@ func mergeOperatorHistory(config *configv1.ClusterVersion, desired configv1.Rele
89
89
})
90
90
}
91
91
92
- last := & config . Status .History [0 ]
92
+ last := & cvStatus .History [0 ]
93
93
94
94
if len (last .State ) == 0 {
95
95
last .State = configv1 .PartialUpdate
@@ -114,7 +114,7 @@ func mergeOperatorHistory(config *configv1.ClusterVersion, desired configv1.Rele
114
114
last .CompletionTime = & now
115
115
}
116
116
if completed {
117
- config . Status .History = append ([]configv1.UpdateHistory {
117
+ cvStatus .History = append ([]configv1.UpdateHistory {
118
118
{
119
119
Version : desired .Version ,
120
120
Image : desired .Image ,
@@ -124,9 +124,9 @@ func mergeOperatorHistory(config *configv1.ClusterVersion, desired configv1.Rele
124
124
CompletionTime : & now ,
125
125
AcceptedRisks : acceptedRisksMsg ,
126
126
},
127
- }, config . Status .History ... )
127
+ }, cvStatus .History ... )
128
128
} else {
129
- config . Status .History = append ([]configv1.UpdateHistory {
129
+ cvStatus .History = append ([]configv1.UpdateHistory {
130
130
{
131
131
Version : desired .Version ,
132
132
Image : desired .Image ,
@@ -135,27 +135,27 @@ func mergeOperatorHistory(config *configv1.ClusterVersion, desired configv1.Rele
135
135
StartedTime : now ,
136
136
AcceptedRisks : acceptedRisksMsg ,
137
137
},
138
- }, config . Status .History ... )
138
+ }, cvStatus .History ... )
139
139
}
140
140
}
141
141
142
142
// leave this here in case we find other future history bugs and need to debug it
143
- if klog .V (2 ).Enabled () && len (config . Status .History ) > 1 {
144
- if config . Status . History [0 ].Image == config . Status . History [1 ].Image && config . Status . History [0 ].Version == config . Status .History [1 ].Version {
145
- data , _ := json .MarshalIndent (config . Status .History , "" , " " )
143
+ if klog .V (2 ).Enabled () && len (cvStatus .History ) > 1 {
144
+ if cvStatus . History [0 ].Image == cvStatus . History [1 ].Image && cvStatus . History [0 ].Version == cvStatus .History [1 ].Version {
145
+ data , _ := json .MarshalIndent (cvStatus .History , "" , " " )
146
146
panic (fmt .Errorf ("tried to update cluster version history to contain duplicate image entries: %s" , string (data )))
147
147
}
148
148
}
149
149
150
150
// payloads can be verified during sync
151
151
if verified {
152
- config . Status .History [0 ].Verified = true
152
+ cvStatus .History [0 ].Verified = true
153
153
}
154
154
155
155
// Prune least informative history entry when at maxHistory.
156
- config . Status . History = prune (config . Status .History , MaxHistory )
156
+ cvStatus . History = prune (cvStatus .History , MaxHistory )
157
157
158
- config . Status .Desired = desired
158
+ cvStatus .Desired = desired
159
159
}
160
160
161
161
// ClusterVersionInvalid indicates that the cluster version has an error that prevents the server from
@@ -198,35 +198,49 @@ func (optr *Operator) syncStatus(ctx context.Context, original, config *configv1
198
198
original = config .DeepCopy ()
199
199
}
200
200
201
- config .Status .ObservedGeneration = status .Generation
201
+ updateClusterVersionStatus (& config .Status , status , optr .release , optr .getAvailableUpdates , validationErrs )
202
+
203
+ if klog .V (6 ).Enabled () {
204
+ klog .Infof ("Apply config: %s" , diff .ObjectReflectDiff (original , config ))
205
+ }
206
+ updated , err := applyClusterVersionStatus (ctx , optr .client .ConfigV1 (), config , original )
207
+ optr .rememberLastUpdate (updated )
208
+ return err
209
+ }
210
+
211
+ // updateClusterVersionStatus updates the passed cvStatus with the latest status information
212
+ func updateClusterVersionStatus (cvStatus * configv1.ClusterVersionStatus , status * SyncWorkerStatus ,
213
+ release configv1.Release , getAvailableUpdates func () * availableUpdates , validationErrs field.ErrorList ) {
214
+
215
+ cvStatus .ObservedGeneration = status .Generation
202
216
if len (status .VersionHash ) > 0 {
203
- config . Status .VersionHash = status .VersionHash
217
+ cvStatus .VersionHash = status .VersionHash
204
218
}
205
219
206
220
now := metav1 .Now ()
207
221
version := versionStringFromRelease (status .Actual )
208
- if status .Actual .Image == optr . release .Image {
222
+ if status .Actual .Image == release .Image {
209
223
// backfill any missing information from the operator (payload).
210
224
if status .Actual .Version == "" {
211
- status .Actual .Version = optr . release .Version
225
+ status .Actual .Version = release .Version
212
226
}
213
227
if len (status .Actual .URL ) == 0 {
214
- status .Actual .URL = optr . release .URL
228
+ status .Actual .URL = release .URL
215
229
}
216
230
if status .Actual .Channels == nil {
217
- status .Actual .Channels = append (optr . release .Channels [:0 :0 ], optr . release .Channels ... ) // copy
231
+ status .Actual .Channels = append (release .Channels [:0 :0 ], release .Channels ... ) // copy
218
232
}
219
233
}
220
- desired := optr . mergeReleaseMetadata (status .Actual )
234
+ desired := mergeReleaseMetadata (status .Actual , getAvailableUpdates )
221
235
222
236
risksMsg := ""
223
237
if desired .Image == status .loadPayloadStatus .Update .Image {
224
238
risksMsg = status .loadPayloadStatus .AcceptedRisks
225
239
}
226
240
227
- mergeOperatorHistory (config , desired , status .Verified , now , status .Completed > 0 , risksMsg , status .loadPayloadStatus .Local )
241
+ mergeOperatorHistory (cvStatus , desired , status .Verified , now , status .Completed > 0 , risksMsg , status .loadPayloadStatus .Local )
228
242
229
- config . Status .Capabilities = status .CapabilitiesStatus .Status
243
+ cvStatus .Capabilities = status .CapabilitiesStatus .Status
230
244
231
245
// update validation errors
232
246
var reason string
@@ -242,42 +256,42 @@ func (optr *Operator) syncStatus(ctx context.Context, original, config *configv1
242
256
}
243
257
reason = "InvalidClusterVersion"
244
258
245
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
259
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
246
260
Type : ClusterVersionInvalid ,
247
261
Status : configv1 .ConditionTrue ,
248
262
Reason : reason ,
249
263
Message : buf .String (),
250
264
LastTransitionTime : now ,
251
265
})
252
266
} else {
253
- resourcemerge .RemoveOperatorStatusCondition (& config . Status .Conditions , ClusterVersionInvalid )
267
+ resourcemerge .RemoveOperatorStatusCondition (& cvStatus .Conditions , ClusterVersionInvalid )
254
268
}
255
269
256
270
// set the implicitly enabled capabilities condition
257
- setImplicitlyEnabledCapabilitiesCondition (config , status .CapabilitiesStatus .ImplicitlyEnabledCaps , now )
271
+ setImplicitlyEnabledCapabilitiesCondition (cvStatus , status .CapabilitiesStatus .ImplicitlyEnabledCaps , now )
258
272
259
273
// set the desired release accepted condition
260
- setDesiredReleaseAcceptedCondition (config , status .loadPayloadStatus , now )
274
+ setDesiredReleaseAcceptedCondition (cvStatus , status .loadPayloadStatus , now )
261
275
262
276
// set the available condition
263
277
if status .Completed > 0 {
264
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
278
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
265
279
Type : configv1 .OperatorAvailable ,
266
280
Status : configv1 .ConditionTrue ,
267
281
Message : fmt .Sprintf ("Done applying %s" , version ),
268
282
LastTransitionTime : now ,
269
283
})
270
284
}
271
285
// default the available condition if not set
272
- if resourcemerge .FindOperatorStatusCondition (config . Status .Conditions , configv1 .OperatorAvailable ) == nil {
273
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
286
+ if resourcemerge .FindOperatorStatusCondition (cvStatus .Conditions , configv1 .OperatorAvailable ) == nil {
287
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
274
288
Type : configv1 .OperatorAvailable ,
275
289
Status : configv1 .ConditionFalse ,
276
290
LastTransitionTime : now ,
277
291
})
278
292
}
279
293
280
- progressReason , progressMessage , skipFailure := convertErrorToProgressing (config . Status .History , now .Time , status )
294
+ progressReason , progressMessage , skipFailure := convertErrorToProgressing (cvStatus .History , now .Time , status )
281
295
282
296
if err := status .Failure ; err != nil && ! skipFailure {
283
297
var reason string
@@ -292,7 +306,7 @@ func (optr *Operator) syncStatus(ctx context.Context, original, config *configv1
292
306
}
293
307
294
308
// set the failing condition
295
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
309
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
296
310
Type : ClusterStatusFailing ,
297
311
Status : configv1 .ConditionTrue ,
298
312
Reason : reason ,
@@ -302,15 +316,15 @@ func (optr *Operator) syncStatus(ctx context.Context, original, config *configv1
302
316
303
317
// update progressing
304
318
if status .Reconciling {
305
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
319
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
306
320
Type : configv1 .OperatorProgressing ,
307
321
Status : configv1 .ConditionFalse ,
308
322
Reason : reason ,
309
323
Message : fmt .Sprintf ("Error while reconciling %s: %s" , version , msg ),
310
324
LastTransitionTime : now ,
311
325
})
312
326
} else {
313
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
327
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
314
328
Type : configv1 .OperatorProgressing ,
315
329
Status : configv1 .ConditionTrue ,
316
330
Reason : reason ,
@@ -321,15 +335,15 @@ func (optr *Operator) syncStatus(ctx context.Context, original, config *configv1
321
335
322
336
} else {
323
337
// clear the failure condition
324
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {Type : ClusterStatusFailing , Status : configv1 .ConditionFalse , LastTransitionTime : now })
338
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {Type : ClusterStatusFailing , Status : configv1 .ConditionFalse , LastTransitionTime : now })
325
339
326
340
// update progressing
327
341
if status .Reconciling {
328
342
message := fmt .Sprintf ("Cluster version is %s" , version )
329
343
if len (validationErrs ) > 0 {
330
344
message = fmt .Sprintf ("Stopped at %s: the cluster version is invalid" , version )
331
345
}
332
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
346
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
333
347
Type : configv1 .OperatorProgressing ,
334
348
Status : configv1 .ConditionFalse ,
335
349
Reason : reason ,
@@ -355,7 +369,7 @@ func (optr *Operator) syncStatus(ctx context.Context, original, config *configv1
355
369
default :
356
370
message = fmt .Sprintf ("Working towards %s" , version )
357
371
}
358
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
372
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
359
373
Type : configv1 .OperatorProgressing ,
360
374
Status : configv1 .ConditionTrue ,
361
375
Reason : reason ,
@@ -366,23 +380,16 @@ func (optr *Operator) syncStatus(ctx context.Context, original, config *configv1
366
380
}
367
381
368
382
// default retrieved updates if it is not set
369
- if resourcemerge .FindOperatorStatusCondition (config . Status .Conditions , configv1 .RetrievedUpdates ) == nil {
370
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
383
+ if resourcemerge .FindOperatorStatusCondition (cvStatus .Conditions , configv1 .RetrievedUpdates ) == nil {
384
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
371
385
Type : configv1 .RetrievedUpdates ,
372
386
Status : configv1 .ConditionFalse ,
373
387
LastTransitionTime : now ,
374
388
})
375
389
}
376
-
377
- if klog .V (6 ).Enabled () {
378
- klog .Infof ("Apply config: %s" , diff .ObjectReflectDiff (original , config ))
379
- }
380
- updated , err := applyClusterVersionStatus (ctx , optr .client .ConfigV1 (), config , original )
381
- optr .rememberLastUpdate (updated )
382
- return err
383
390
}
384
391
385
- func setImplicitlyEnabledCapabilitiesCondition (config * configv1.ClusterVersion , implicitlyEnabled []configv1.ClusterVersionCapability ,
392
+ func setImplicitlyEnabledCapabilitiesCondition (cvStatus * configv1.ClusterVersionStatus , implicitlyEnabled []configv1.ClusterVersionCapability ,
386
393
now metav1.Time ) {
387
394
388
395
if len (implicitlyEnabled ) > 0 {
@@ -394,15 +401,15 @@ func setImplicitlyEnabledCapabilitiesCondition(config *configv1.ClusterVersion,
394
401
sort .Strings (caps )
395
402
message = message + strings .Join ([]string (caps ), ", " )
396
403
397
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
404
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
398
405
Type : ImplicitlyEnabledCapabilities ,
399
406
Status : configv1 .ConditionTrue ,
400
407
Reason : "CapabilitiesImplicitlyEnabled" ,
401
408
Message : message ,
402
409
LastTransitionTime : now ,
403
410
})
404
411
} else {
405
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
412
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
406
413
Type : ImplicitlyEnabledCapabilities ,
407
414
Status : configv1 .ConditionFalse ,
408
415
Reason : "AsExpected" ,
@@ -412,9 +419,9 @@ func setImplicitlyEnabledCapabilitiesCondition(config *configv1.ClusterVersion,
412
419
}
413
420
}
414
421
415
- func setDesiredReleaseAcceptedCondition (config * configv1.ClusterVersion , status LoadPayloadStatus , now metav1.Time ) {
422
+ func setDesiredReleaseAcceptedCondition (cvStatus * configv1.ClusterVersionStatus , status LoadPayloadStatus , now metav1.Time ) {
416
423
if status .Step == "PayloadLoaded" {
417
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
424
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
418
425
Type : DesiredReleaseAccepted ,
419
426
Status : configv1 .ConditionTrue ,
420
427
Reason : status .Step ,
@@ -423,15 +430,15 @@ func setDesiredReleaseAcceptedCondition(config *configv1.ClusterVersion, status
423
430
})
424
431
} else if status .Step != "" {
425
432
if status .Failure != nil {
426
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
433
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
427
434
Type : DesiredReleaseAccepted ,
428
435
Status : configv1 .ConditionFalse ,
429
436
Reason : status .Step ,
430
437
Message : status .Message ,
431
438
LastTransitionTime : now ,
432
439
})
433
440
} else {
434
- resourcemerge .SetOperatorStatusCondition (& config . Status .Conditions , configv1.ClusterOperatorStatusCondition {
441
+ resourcemerge .SetOperatorStatusCondition (& cvStatus .Conditions , configv1.ClusterOperatorStatusCondition {
435
442
Type : DesiredReleaseAccepted ,
436
443
Status : configv1 .ConditionUnknown ,
437
444
Reason : status .Step ,
@@ -534,7 +541,7 @@ func (optr *Operator) syncFailingStatus(ctx context.Context, original *configv1.
534
541
LastTransitionTime : now ,
535
542
})
536
543
537
- mergeOperatorHistory (config , optr .currentVersion (), false , now , false , "" , false )
544
+ mergeOperatorHistory (& config . Status , optr .currentVersion (), false , now , false , "" , false )
538
545
539
546
updated , err := applyClusterVersionStatus (ctx , optr .client .ConfigV1 (), config , original )
540
547
optr .rememberLastUpdate (updated )
0 commit comments