@@ -30,6 +30,8 @@ const (
30
30
// OCMAPIFailureCountThreshold defines how many unsuccessful responses from the OCM API in a row is tolerated
31
31
// before the operator is marked as Degraded
32
32
OCMAPIFailureCountThreshold = 5
33
+
34
+ insightsAvailableMessage = "Insights works as expected"
33
35
)
34
36
35
37
type Reported struct {
@@ -146,10 +148,6 @@ func (c *Controller) merge(clusterOperator *configv1.ClusterOperator) *configv1.
146
148
// cluster operator conditions
147
149
cs := newConditions (& clusterOperator .Status , metav1.Time {Time : now })
148
150
updateControllerConditions (cs , c .ctrlStatus , isInitializing , lastTransition )
149
-
150
- // once the operator is running it is always considered available
151
- cs .setCondition (configv1 .OperatorAvailable , configv1 .ConditionTrue , "AsExpected" , "" , metav1 .Now ())
152
-
153
151
updateControllerConditionsByStatus (cs , c .ctrlStatus , isInitializing , lastTransition )
154
152
155
153
// all status conditions from conditions to cluster operator
@@ -265,7 +263,7 @@ func (c *Controller) Start(ctx context.Context) error {
265
263
}
266
264
}
267
265
if err := c .updateStatus (ctx , false ); err != nil {
268
- klog .Errorf ("Unable to write cluster operator statusMessage : %v" , err )
266
+ klog .Errorf ("Unable to write cluster operator status : %v" , err )
269
267
}
270
268
}
271
269
}, time .Second , ctx .Done ())
@@ -285,32 +283,31 @@ func (c *Controller) updateStatus(ctx context.Context, initial bool) error {
285
283
var reported Reported
286
284
if len (existing .Status .Extension .Raw ) > 0 {
287
285
if err := json .Unmarshal (existing .Status .Extension .Raw , & reported ); err != nil { //nolint: govet
288
- klog .Errorf ("The initial operator extension statusMessage is invalid: %v" , err )
286
+ klog .Errorf ("The initial operator extension status is invalid: %v" , err )
289
287
}
290
288
}
291
289
c .SetLastReportedTime (reported .LastReportTime .Time .UTC ())
292
290
cs := newConditions (& existing .Status , metav1 .Now ())
293
291
if con := cs .findCondition (configv1 .OperatorDegraded ); con == nil ||
294
292
con != nil && con .Status == configv1 .ConditionFalse {
295
- klog .Info ("The initial operator extension statusMessage is healthy" )
293
+ klog .Info ("The initial operator extension status is healthy" )
296
294
}
297
295
}
298
296
}
299
297
300
- updated := c .merge (existing )
298
+ updatedClusterOperator := c .merge (existing )
301
299
if existing == nil {
302
- created , err := c .client .ClusterOperators ().Create (ctx , updated , metav1.CreateOptions {}) //nolint: govet
300
+ created , err := c .client .ClusterOperators ().Create (ctx , updatedClusterOperator , metav1.CreateOptions {}) //nolint: govet
303
301
if err != nil {
304
302
return err
305
303
}
306
- updated .ObjectMeta = created .ObjectMeta
307
- updated .Spec = created .Spec
308
- } else if reflect .DeepEqual (updated .Status , existing .Status ) {
309
- klog .V (4 ).Infof ("No statusMessage update necessary, objects are identical" )
304
+ updatedClusterOperator .ObjectMeta = created .ObjectMeta
305
+ updatedClusterOperator .Spec = created .Spec
306
+ } else if reflect .DeepEqual (updatedClusterOperator .Status , existing .Status ) {
307
+ klog .V (4 ).Infof ("No status update necessary, objects are identical" )
310
308
return nil
311
309
}
312
-
313
- _ , err = c .client .ClusterOperators ().UpdateStatus (ctx , updated , metav1.UpdateOptions {})
310
+ _ , err = c .client .ClusterOperators ().UpdateStatus (ctx , updatedClusterOperator , metav1.UpdateOptions {})
314
311
return err
315
312
}
316
313
@@ -339,7 +336,7 @@ func updateControllerConditions(cs *conditions, ctrlStatus *controllerStatus,
339
336
if es := ctrlStatus .getStatus (ErrorStatus ); es != nil {
340
337
cs .setCondition (configv1 .OperatorDegraded , configv1 .ConditionTrue , es .reason , es .message , metav1.Time {Time : lastTransition })
341
338
} else {
342
- cs .setCondition (configv1 .OperatorDegraded , configv1 .ConditionFalse , "AsExpected" , "" , metav1 .Now ())
339
+ cs .setCondition (configv1 .OperatorDegraded , configv1 .ConditionFalse , "AsExpected" , insightsAvailableMessage , metav1 .Now ())
343
340
}
344
341
345
342
// handle when upload fails
@@ -379,6 +376,8 @@ func updateControllerConditionsByStatus(cs *conditions, ctrlStatus *controllerSt
379
376
if es := ctrlStatus .getStatus (ErrorStatus ); es != nil {
380
377
klog .V (4 ).Infof ("The operator has some internal errors: %s" , es .message )
381
378
cs .setCondition (configv1 .OperatorProgressing , configv1 .ConditionFalse , "Degraded" , "An error has occurred" , metav1 .Now ())
379
+ cs .setCondition (configv1 .OperatorAvailable , configv1 .ConditionFalse , es .reason , es .message , metav1 .Now ())
380
+ cs .setCondition (configv1 .OperatorUpgradeable , configv1 .ConditionFalse , "InsightsNotUpgradeable" , es .message , metav1 .Now ())
382
381
}
383
382
384
383
if ds := ctrlStatus .getStatus (DisabledStatus ); ds != nil {
@@ -389,6 +388,9 @@ func updateControllerConditionsByStatus(cs *conditions, ctrlStatus *controllerSt
389
388
if ctrlStatus .isHealthy () {
390
389
klog .V (4 ).Infof ("The operator is healthy" )
391
390
cs .setCondition (configv1 .OperatorProgressing , configv1 .ConditionFalse , "AsExpected" , "Monitoring the cluster" , metav1 .Now ())
391
+ cs .setCondition (configv1 .OperatorAvailable , configv1 .ConditionTrue , "AsExpected" , insightsAvailableMessage , metav1 .Now ())
392
+ cs .setCondition (configv1 .OperatorUpgradeable , configv1 .ConditionTrue , "InsightsUpgradeable" ,
393
+ "Insights operator can be upgraded" , metav1 .Now ())
392
394
}
393
395
}
394
396
@@ -403,6 +405,7 @@ func handleControllerStatusError(errs []string, errorReason string) (reason, mes
403
405
reason = "UnknownError"
404
406
}
405
407
message = errs [0 ]
408
+ reason = errorReason
406
409
}
407
410
return reason , message
408
411
}
0 commit comments