@@ -22,6 +22,7 @@ import (
22
22
"github.com/openshift/library-go/pkg/operator/events"
23
23
24
24
"github.com/openshift/cluster-version-operator/lib/resourcemerge"
25
+ updatestatus "github.com/openshift/cluster-version-operator/pkg/updatestatus/api"
25
26
)
26
27
27
28
// controlPlaneInformerController is the controller that monitors health of the control plane-related resources
@@ -176,23 +177,23 @@ func (c *controlPlaneInformerController) sync(ctx context.Context, syncCtx facto
176
177
return nil
177
178
}
178
179
179
- func makeInsightMsgForClusterOperator (coInsight * ClusterOperatorStatusInsight , acquiredAt metav1.Time ) (informerMsg , error ) {
180
- insight := ControlPlaneInsight {
180
+ func makeInsightMsgForClusterOperator (coInsight * updatestatus. ClusterOperatorStatusInsight , acquiredAt metav1.Time ) (informerMsg , error ) {
181
+ insight := updatestatus. ControlPlaneInsight {
181
182
UID : fmt .Sprintf ("co-%s" , coInsight .Name ),
182
183
AcquiredAt : acquiredAt ,
183
- ControlPlaneInsightUnion : ControlPlaneInsightUnion {
184
- Type : ClusterOperatorStatusInsightType ,
184
+ ControlPlaneInsightUnion : updatestatus. ControlPlaneInsightUnion {
185
+ Type : updatestatus . ClusterOperatorStatusInsightType ,
185
186
ClusterOperatorStatusInsight : coInsight ,
186
187
},
187
188
}
188
189
return makeControlPlaneInsightMsg (insight , controlPlaneInformerName )
189
190
}
190
191
191
- func assessClusterOperator (ctx context.Context , operator * configv1.ClusterOperator , targetVersion string , appsClient appsv1client.AppsV1Interface , now metav1.Time ) (* ClusterOperatorStatusInsight , error ) {
192
+ func assessClusterOperator (ctx context.Context , operator * configv1.ClusterOperator , targetVersion string , appsClient appsv1client.AppsV1Interface , now metav1.Time ) (* updatestatus. ClusterOperatorStatusInsight , error ) {
192
193
updating := metav1.Condition {
193
- Type : string (ClusterOperatorStatusInsightUpdating ),
194
+ Type : string (updatestatus . ClusterOperatorStatusInsightUpdating ),
194
195
Status : metav1 .ConditionUnknown ,
195
- Reason : string (ClusterOperatorUpdatingCannotDetermine ),
196
+ Reason : string (updatestatus . ClusterOperatorUpdatingCannotDetermine ),
196
197
LastTransitionTime : now ,
197
198
}
198
199
@@ -219,7 +220,7 @@ func assessClusterOperator(ctx context.Context, operator *configv1.ClusterOperat
219
220
updated := (noOperatorImageVersion || operatorImageUpdated ) && versionUpdated
220
221
if updated {
221
222
updating .Status = metav1 .ConditionFalse
222
- updating .Reason = string (ClusterOperatorUpdatingReasonUpdated )
223
+ updating .Reason = string (updatestatus . ClusterOperatorUpdatingReasonUpdated )
223
224
}
224
225
225
226
var available * configv1.ClusterOperatorStatusCondition
@@ -241,40 +242,40 @@ func assessClusterOperator(ctx context.Context, operator *configv1.ClusterOperat
241
242
if ! updated && progressing != nil {
242
243
if progressing .Status == configv1 .ConditionTrue {
243
244
updating .Status = metav1 .ConditionTrue
244
- updating .Reason = string (ClusterOperatorUpdatingReasonProgressing )
245
+ updating .Reason = string (updatestatus . ClusterOperatorUpdatingReasonProgressing )
245
246
updating .Message = progressing .Message
246
247
}
247
248
if progressing .Status == configv1 .ConditionFalse {
248
249
updating .Status = metav1 .ConditionFalse
249
- updating .Reason = string (ClusterOperatorUpdatingReasonPending )
250
+ updating .Reason = string (updatestatus . ClusterOperatorUpdatingReasonPending )
250
251
updating .Message = progressing .Message
251
252
}
252
253
}
253
254
254
255
health := metav1.Condition {
255
- Type : string (ClusterOperatorStatusInsightHealthy ),
256
+ Type : string (updatestatus . ClusterOperatorStatusInsightHealthy ),
256
257
Status : metav1 .ConditionTrue ,
257
- Reason : string (ClusterOperatorHealthyReasonAsExpected ),
258
+ Reason : string (updatestatus . ClusterOperatorHealthyReasonAsExpected ),
258
259
LastTransitionTime : now ,
259
260
}
260
261
261
262
if available == nil {
262
263
health .Status = metav1 .ConditionUnknown
263
- health .Reason = string (ClusterOperatorHealthyReasonUnavailable )
264
+ health .Reason = string (updatestatus . ClusterOperatorHealthyReasonUnavailable )
264
265
health .Message = "The cluster operator is unavailable because the available condition is not found in the cluster operator's status"
265
266
} else if available .Status != configv1 .ConditionTrue {
266
267
health .Status = metav1 .ConditionFalse
267
- health .Reason = string (ClusterOperatorHealthyReasonUnavailable )
268
+ health .Reason = string (updatestatus . ClusterOperatorHealthyReasonUnavailable )
268
269
health .Message = available .Message
269
270
} else if degraded != nil && degraded .Status == configv1 .ConditionTrue {
270
271
health .Status = metav1 .ConditionFalse
271
- health .Reason = string (ClusterOperatorHealthyReasonDegraded )
272
+ health .Reason = string (updatestatus . ClusterOperatorHealthyReasonDegraded )
272
273
health .Message = degraded .Message
273
274
}
274
275
275
- return & ClusterOperatorStatusInsight {
276
+ return & updatestatus. ClusterOperatorStatusInsight {
276
277
Name : operator .Name ,
277
- Resource : ResourceRef {
278
+ Resource : updatestatus. ResourceRef {
278
279
Resource : "clusteroperators" ,
279
280
Group : configv1 .GroupName ,
280
281
Name : operator .Name ,
@@ -309,19 +310,19 @@ func getImagePullSpec(ctx context.Context, name string, appsClient appsv1client.
309
310
// makeInsightMsgForClusterVersion creates an informerMsg for the given ClusterVersionStatusInsight. It defines an uid
310
311
// name and serializes the insight as YAML. Serialization is convenient because it prevents any data sharing issues
311
312
// between controllers.
312
- func makeInsightMsgForClusterVersion (cvInsight * ClusterVersionStatusInsight , acquiredAt metav1.Time ) (informerMsg , error ) {
313
- insight := ControlPlaneInsight {
313
+ func makeInsightMsgForClusterVersion (cvInsight * updatestatus. ClusterVersionStatusInsight , acquiredAt metav1.Time ) (informerMsg , error ) {
314
+ insight := updatestatus. ControlPlaneInsight {
314
315
UID : fmt .Sprintf ("cv-%s" , cvInsight .Resource .Name ),
315
316
AcquiredAt : acquiredAt ,
316
- ControlPlaneInsightUnion : ControlPlaneInsightUnion {
317
- Type : ClusterVersionStatusInsightType ,
317
+ ControlPlaneInsightUnion : updatestatus. ControlPlaneInsightUnion {
318
+ Type : updatestatus . ClusterVersionStatusInsightType ,
318
319
ClusterVersionStatusInsight : cvInsight ,
319
320
},
320
321
}
321
322
return makeControlPlaneInsightMsg (insight , controlPlaneInformerName )
322
323
}
323
324
324
- func uidForHealthInsight (healthInsight * HealthInsight ) string {
325
+ func uidForHealthInsight (healthInsight * updatestatus. HealthInsight ) string {
325
326
hasher := md5 .New ()
326
327
hasher .Write ([]byte (healthInsight .Impact .Summary ))
327
328
for i := range healthInsight .Scope .Resources {
@@ -338,12 +339,12 @@ func uidForHealthInsight(healthInsight *HealthInsight) string {
338
339
return encoded
339
340
}
340
341
341
- func makeInsightMsgForHealthInsight (healthInsight * HealthInsight , acquiredAt metav1.Time ) (informerMsg , error ) {
342
- insight := ControlPlaneInsight {
342
+ func makeInsightMsgForHealthInsight (healthInsight * updatestatus. HealthInsight , acquiredAt metav1.Time ) (informerMsg , error ) {
343
+ insight := updatestatus. ControlPlaneInsight {
343
344
UID : uidForHealthInsight (healthInsight ),
344
345
AcquiredAt : acquiredAt ,
345
- ControlPlaneInsightUnion : ControlPlaneInsightUnion {
346
- Type : HealthInsightType ,
346
+ ControlPlaneInsightUnion : updatestatus. ControlPlaneInsightUnion {
347
+ Type : updatestatus . HealthInsightType ,
347
348
HealthInsight : healthInsight ,
348
349
},
349
350
}
@@ -354,7 +355,7 @@ func makeInsightMsgForHealthInsight(healthInsight *HealthInsight, acquiredAt met
354
355
// It does not take previous status insight into account. Many fields of the status insights (such as completion) cannot
355
356
// be properly calculated without also watching and processing ClusterOperators, so that functionality will need to be
356
357
// added later.
357
- func assessClusterVersion (cv * configv1.ClusterVersion , now metav1.Time ) (* ClusterVersionStatusInsight , []* HealthInsight ) {
358
+ func assessClusterVersion (cv * configv1.ClusterVersion , now metav1.Time ) (* updatestatus. ClusterVersionStatusInsight , []* updatestatus. HealthInsight ) {
358
359
359
360
var lastHistoryItem * configv1.UpdateHistory
360
361
if len (cv .Status .History ) > 0 {
@@ -367,24 +368,24 @@ func assessClusterVersion(cv *configv1.ClusterVersion, now metav1.Time) (*Cluste
367
368
368
369
klog .V (2 ).Infof ("CPI :: CV/%s :: Updating=%s Started=%s Completed=%s" , cv .Name , updating .Status , startedAt , completedAt )
369
370
370
- var assessment ControlPlaneAssessment
371
+ var assessment updatestatus. ControlPlaneAssessment
371
372
var completion int32
372
373
switch updating .Status {
373
374
case metav1 .ConditionTrue :
374
- assessment = ControlPlaneAssessmentProgressing
375
+ assessment = updatestatus . ControlPlaneAssessmentProgressing
375
376
case metav1 .ConditionFalse :
376
- assessment = ControlPlaneAssessmentCompleted
377
+ assessment = updatestatus . ControlPlaneAssessmentCompleted
377
378
completion = 100
378
379
case metav1 .ConditionUnknown :
379
- assessment = ControlPlaneAssessmentUnknown
380
+ assessment = updatestatus . ControlPlaneAssessmentUnknown
380
381
default :
381
- assessment = ControlPlaneAssessmentUnknown
382
+ assessment = updatestatus . ControlPlaneAssessmentUnknown
382
383
}
383
384
384
385
klog .V (2 ).Infof ("CPI :: CV/%s :: Assessment=%s" , cv .Name , assessment )
385
386
386
- insight := & ClusterVersionStatusInsight {
387
- Resource : ResourceRef {
387
+ insight := & updatestatus. ClusterVersionStatusInsight {
388
+ Resource : updatestatus. ResourceRef {
388
389
Resource : "clusterversions" ,
389
390
Group : configv1 .GroupName ,
390
391
Name : cv .Name ,
@@ -404,7 +405,7 @@ func assessClusterVersion(cv *configv1.ClusterVersion, now metav1.Time) (*Cluste
404
405
insight .EstimatedCompletedAt = & metav1.Time {Time : est }
405
406
}
406
407
407
- var healthInsights []* HealthInsight
408
+ var healthInsights []* updatestatus. HealthInsight
408
409
if forcedHealthInsight := forcedHealthInsight (cv , now ); forcedHealthInsight != nil {
409
410
healthInsights = append (healthInsights , forcedHealthInsight )
410
411
}
@@ -416,24 +417,24 @@ const (
416
417
uscForceHealthInsightAnnotation = "usc.openshift.io/force-health-insight"
417
418
)
418
419
419
- func forcedHealthInsight (cv * configv1.ClusterVersion , now metav1.Time ) * HealthInsight {
420
+ func forcedHealthInsight (cv * configv1.ClusterVersion , now metav1.Time ) * updatestatus. HealthInsight {
420
421
if _ , ok := cv .Annotations [uscForceHealthInsightAnnotation ]; ! ok {
421
422
return nil
422
423
}
423
424
424
- return & HealthInsight {
425
+ return & updatestatus. HealthInsight {
425
426
StartedAt : now ,
426
- Scope : InsightScope {
427
- Type : ControlPlaneScope ,
428
- Resources : []ResourceRef {{Resource : "clusterversions" , Group : configv1 .GroupName , Name : cv .Name }},
427
+ Scope : updatestatus. InsightScope {
428
+ Type : updatestatus . ControlPlaneScope ,
429
+ Resources : []updatestatus. ResourceRef {{Resource : "clusterversions" , Group : configv1 .GroupName , Name : cv .Name }},
429
430
},
430
- Impact : InsightImpact {
431
- Level : InfoImpactLevel ,
432
- Type : NoneImpactType ,
431
+ Impact : updatestatus. InsightImpact {
432
+ Level : updatestatus . InfoImpactLevel ,
433
+ Type : updatestatus . NoneImpactType ,
433
434
Summary : fmt .Sprintf ("Forced health insight for ClusterVersion %s" , cv .Name ),
434
435
Description : fmt .Sprintf ("The resource has a %q annotation which forces USC to generate this health insight for testing purposes." , uscForceHealthInsightAnnotation ),
435
436
},
436
- Remediation : InsightRemediation {
437
+ Remediation : updatestatus. InsightRemediation {
437
438
Reference : "https://issues.redhat.com/browse/OTA-1418" ,
438
439
},
439
440
}
@@ -451,7 +452,7 @@ func estimateCompletion(started time.Time) time.Time {
451
452
// Reason and Message fields will explain why.
452
453
func isControlPlaneUpdating (cvProgressing * configv1.ClusterOperatorStatusCondition , lastHistoryItem * configv1.UpdateHistory ) (metav1.Condition , metav1.Time , metav1.Time ) {
453
454
updating := metav1.Condition {
454
- Type : string (ClusterVersionStatusInsightUpdating ),
455
+ Type : string (updatestatus . ClusterVersionStatusInsightUpdating ),
455
456
}
456
457
457
458
if cvProgressing == nil {
@@ -495,7 +496,7 @@ func isControlPlaneUpdating(cvProgressing *configv1.ClusterOperatorStatusConditi
495
496
496
497
func setCannotDetermineUpdating (cond * metav1.Condition , message string ) {
497
498
cond .Status = metav1 .ConditionUnknown
498
- cond .Reason = string (ClusterVersionCannotDetermineUpdating )
499
+ cond .Reason = string (updatestatus . ClusterVersionCannotDetermineUpdating )
499
500
cond .Message = message
500
501
}
501
502
@@ -506,13 +507,13 @@ func cvProgressingToUpdating(cvProgressing configv1.ClusterOperatorStatusConditi
506
507
var reason string
507
508
switch status {
508
509
case metav1 .ConditionTrue :
509
- reason = string (ClusterVersionProgressing )
510
+ reason = string (updatestatus . ClusterVersionProgressing )
510
511
case metav1 .ConditionFalse :
511
- reason = string (ClusterVersionNotProgressing )
512
+ reason = string (updatestatus . ClusterVersionNotProgressing )
512
513
case metav1 .ConditionUnknown :
513
- reason = string (ClusterVersionCannotDetermineUpdating )
514
+ reason = string (updatestatus . ClusterVersionCannotDetermineUpdating )
514
515
default :
515
- reason = string (ClusterVersionCannotDetermineUpdating )
516
+ reason = string (updatestatus . ClusterVersionCannotDetermineUpdating )
516
517
}
517
518
518
519
message := fmt .Sprintf ("ClusterVersion has Progressing=%s(Reason=%s) | Message='%s'" , cvProgressing .Status , cvProgressing .Reason , cvProgressing .Message )
@@ -521,8 +522,8 @@ func cvProgressingToUpdating(cvProgressing configv1.ClusterOperatorStatusConditi
521
522
522
523
// versionsFromHistory returns a ControlPlaneUpdateVersions struct with the target version and metadata from the given
523
524
// history.
524
- func versionsFromHistory (history []configv1.UpdateHistory ) ControlPlaneUpdateVersions {
525
- var versions ControlPlaneUpdateVersions
525
+ func versionsFromHistory (history []configv1.UpdateHistory ) updatestatus. ControlPlaneUpdateVersions {
526
+ var versions updatestatus. ControlPlaneUpdateVersions
526
527
527
528
if len (history ) == 0 {
528
529
return versions
@@ -531,12 +532,12 @@ func versionsFromHistory(history []configv1.UpdateHistory) ControlPlaneUpdateVer
531
532
versions .Target .Version = history [0 ].Version
532
533
533
534
if len (history ) == 1 {
534
- versions .Target .Metadata = []VersionMetadata {{Key : InstallationMetadata }}
535
+ versions .Target .Metadata = []updatestatus. VersionMetadata {{Key : updatestatus . InstallationMetadata }}
535
536
}
536
537
if len (history ) > 1 {
537
538
versions .Previous .Version = history [1 ].Version
538
539
if history [1 ].State == configv1 .PartialUpdate {
539
- versions .Previous .Metadata = []VersionMetadata {{Key : PartialMetadata }}
540
+ versions .Previous .Metadata = []updatestatus. VersionMetadata {{Key : updatestatus . PartialMetadata }}
540
541
}
541
542
}
542
543
return versions
0 commit comments