From b8fdc27b29024a3839afdb5c662fe1386c8bf011 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Mon, 11 Feb 2019 23:14:50 +0100 Subject: [PATCH] pkg/operator: correctly sync status for the CVO Based on: - https://github.com/openshift/cluster-version-operator/blob/master/docs/dev/clusteroperator.md#conditions - Slack conversation with Clayton We should correctly report Progressing only when really progressing towards something. Re-syncing, reconciling, drift detections verifying everything is still where you left it is not _changing_ something, thus is not progressing. Signed-off-by: Antonio Murdaca --- pkg/operator/status.go | 36 ++++++++++++++++++++++++------------ pkg/operator/sync.go | 4 ++-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pkg/operator/status.go b/pkg/operator/status.go index 066f289c96..defc364025 100644 --- a/pkg/operator/status.go +++ b/pkg/operator/status.go @@ -28,15 +28,22 @@ func (optr *Operator) syncAvailableStatus() error { } optrVersion, _ := optr.vStore.Get("operator") + progressing := cov1helpers.IsStatusConditionTrue(co.Status.Conditions, configv1.OperatorProgressing) + failing := cov1helpers.IsStatusConditionTrue(co.Status.Conditions, configv1.OperatorFailing) + message := fmt.Sprintf("Cluster has deployed %s", optrVersion) + + available := configv1.ConditionTrue + + if failing && !progressing { + available = configv1.ConditionFalse + message = fmt.Sprintf("Cluster not available for %s", optrVersion) + } + // set available cov1helpers.SetStatusCondition(&co.Status.Conditions, configv1.ClusterOperatorStatusCondition{ - Type: configv1.OperatorAvailable, Status: configv1.ConditionTrue, - Message: fmt.Sprintf("Cluster is available at %s", optrVersion), + Type: configv1.OperatorAvailable, Status: available, + Message: message, }) - // clear progressing - cov1helpers.SetStatusCondition(&co.Status.Conditions, configv1.ClusterOperatorStatusCondition{Type: configv1.OperatorProgressing, Status: configv1.ConditionFalse}) - // clear failure - cov1helpers.SetStatusCondition(&co.Status.Conditions, configv1.ClusterOperatorStatusCondition{Type: configv1.OperatorFailing, Status: configv1.ConditionFalse}) co.Status.Versions = optr.vStore.GetAll() optr.setMachineConfigPoolStatuses(&co.Status) @@ -55,15 +62,20 @@ func (optr *Operator) syncProgressingStatus() error { } optrVersion, _ := optr.vStore.Get("operator") - var message string + progressing := configv1.ConditionFalse + message := fmt.Sprintf("Cluster version is %s", optrVersion) + if optr.vStore.Equal(co.Status.Versions) { - // syncing the state to existing version. - message = fmt.Sprintf("Running resync for %s", optrVersion) + if optr.inClusterBringup { + progressing = configv1.ConditionTrue + } } else { - message = fmt.Sprintf("Progressing towards %s", optrVersion) + message = fmt.Sprintf("Working towards %s", optrVersion) + progressing = configv1.ConditionTrue } + cov1helpers.SetStatusCondition(&co.Status.Conditions, configv1.ClusterOperatorStatusCondition{ - Type: configv1.OperatorProgressing, Status: configv1.ConditionTrue, + Type: configv1.OperatorProgressing, Status: progressing, Message: message, }) @@ -91,7 +103,7 @@ func (optr *Operator) syncFailingStatus(ierr error) error { // syncing the state to exiting version. message = fmt.Sprintf("Failed to resync %s because: %v", optrVersion, ierr.Error()) } else { - message = fmt.Sprintf("Failed when progressing towards %s because: %v", optrVersion, ierr.Error()) + message = fmt.Sprintf("Unable to apply %s: %v", optrVersion, ierr.Error()) } // set failing condition cov1helpers.SetStatusCondition(&co.Status.Conditions, configv1.ClusterOperatorStatusCondition{ diff --git a/pkg/operator/sync.go b/pkg/operator/sync.go index b64b7383b6..053ca0d2fc 100644 --- a/pkg/operator/sync.go +++ b/pkg/operator/sync.go @@ -47,7 +47,6 @@ func (optr *Operator) syncAll(rconfig renderConfig) error { if optr.inClusterBringup { glog.Infof("[init mode] synced %s in %v", sf.name, time.Since(startTime)) } - optr.syncProgressingStatus() } agg := utilerrors.NewAggregate(errs) @@ -55,7 +54,8 @@ func (optr *Operator) syncAll(rconfig renderConfig) error { errs = append(errs, optr.syncFailingStatus(agg)) agg = utilerrors.NewAggregate(errs) return fmt.Errorf("error syncing: %v", agg.Error()) - } else if optr.inClusterBringup { + } + if optr.inClusterBringup { glog.Infof("Initialization complete") optr.inClusterBringup = false }