Skip to content

Commit

Permalink
Merge pull request #15 from sallyom/bz1822943
Browse files Browse the repository at this point in the history
Bug 1822943: return sync error to add to queue
  • Loading branch information
openshift-merge-robot committed Apr 27, 2020
2 parents 0dd767a + 30ad9c9 commit 27e98ad
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
5 changes: 4 additions & 1 deletion pkg/operator/targetcontroller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ func (c *TargetController) sync() error {
}

forceRequeue, err := c.syncKubeStorageVersionMigrator(spec, status, objectMetaGeneration)
if forceRequeue && err != nil {
if err != nil {
return err
}
if forceRequeue {
c.queue.AddRateLimited(workQueueKey)
}

Expand Down
17 changes: 13 additions & 4 deletions pkg/operator/targetcontroller/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *TargetController) syncKubeStorageVersionMigrator(spec *operatorv1.KubeS
}

manageOperatorStatusAvailable(deployment, operatorStatus)
manageOperatorStatusProgressing(deployment, operatorStatus, generation)
manageOperatorStatusProgressing(deployment, errors, operatorStatus, generation)
manageOperatorStatusDegraded(errors, operatorStatus)

// TODO this is changing too early and it was before too.
Expand Down Expand Up @@ -77,7 +77,7 @@ func (c *TargetController) syncKubeStorageVersionMigrator(spec *operatorv1.KubeS
}

if len(errors) > 0 {
return true, nil
return true, fmt.Errorf("sync error")
}
if !v1helpers.IsOperatorConditionFalse(operatorStatus.Conditions, operatorv1.OperatorStatusTypeDegraded) {
return true, nil
Expand Down Expand Up @@ -117,11 +117,20 @@ func manageOperatorStatusAvailable(deployment *appsv1.Deployment, status *operat
}
}

func manageOperatorStatusProgressing(deployment *appsv1.Deployment, status *operatorv1.KubeStorageVersionMigratorStatus, generation int64) {
func manageOperatorStatusProgressing(deployment *appsv1.Deployment, errors []error, status *operatorv1.KubeStorageVersionMigratorStatus, generation int64) {
// If the deployment is up to date and the operatorConfig are up to date, then we are no longer progressing
var progressingMessages []string
if len(errors) > 0 {
for _, err := range errors {
if deployment == nil {
progressingMessages = append(progressingMessages, fmt.Sprintf("syncing openshift-kube-storage-version-migrator resources: %v", err.Error()))
} else {
progressingMessages = append(progressingMessages, fmt.Sprintf("deployment/migrator.openshift-kube-storage-version-migrator: %v", err.Error()))
}
}
}
if deployment != nil && deployment.ObjectMeta.Generation != deployment.Status.ObservedGeneration {
progressingMessages = append(progressingMessages, fmt.Sprintf("deployment/migrator.openshift-kube-storage-version-migrator:: observed generation is %d, desired generation is %d.", deployment.Status.ObservedGeneration, deployment.ObjectMeta.Generation))
progressingMessages = append(progressingMessages, fmt.Sprintf("deployment/migrator.openshift-kube-storage-version-migrator: observed generation is %d, desired generation is %d.", deployment.Status.ObservedGeneration, deployment.ObjectMeta.Generation))
}
if generation != status.ObservedGeneration {
progressingMessages = append(progressingMessages, fmt.Sprintf("kubestorageversionmigrators/cluster: observed generation is %d, desired generation is %d.", status.ObservedGeneration, generation))
Expand Down
15 changes: 14 additions & 1 deletion pkg/operator/targetcontroller/sync_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package targetcontroller

import (
"fmt"
v12 "github.com/openshift/api/operator/v1"
v1 "k8s.io/api/apps/v1"
v13 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -66,6 +67,18 @@ func TestManageOperatorStatusProgressing(t *testing.T) {
ObservedGeneration: 1,
},
}
manageOperatorStatusProgressing(deployment, status, 1)
manageOperatorStatusProgressing(deployment, nil, status, 1)
t.Log(mergepatch.ToYAMLOrError(status))
}

func TestManageOperatorStatusProgressingSyncErr(t *testing.T) {
var errors []error
errors = append(errors, fmt.Errorf("syncErr"))
var statusTrue v12.ConditionStatus = "True"
status := &v12.KubeStorageVersionMigratorStatus{}
manageOperatorStatusProgressing(nil, errors, status, 1)
if status.OperatorStatus.Conditions[0].Status != statusTrue {
t.Errorf("Expected Progressing %v, got %v", statusTrue, status.OperatorStatus.Conditions[0].Status)
}
t.Log(mergepatch.ToYAMLOrError(status))
}

0 comments on commit 27e98ad

Please sign in to comment.