Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions pkg/operator/revisioncontroller/revision_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ func (c RevisionController) getLatestAvailableRevision(ctx context.Context) (int
var latestRevision int32
for _, configMap := range configMaps.Items {
if !strings.HasPrefix(configMap.Name, "revision-status-") {
// if it's not a revision status configmap, skip
continue
}
if configMap.Annotations["operator.openshift.io/revision-ready"] != "true" {
// we only want to include ready revisions.
Comment on lines +311 to +312
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the effect of backporting this on 4.16->4.17 upgrades? Are we relying on this controller decreasing latestAvailableRevision?

continue
}
if revision, ok := configMap.Data["revision"]; ok {
Expand All @@ -321,6 +326,39 @@ func (c RevisionController) getLatestAvailableRevision(ctx context.Context) (int
return latestRevision, nil
}

// fixOperatorLatestAvailableRevision checks the revision-status configmap
// corresponding to the LatestAvailableRevision seen by the operator and fix it
// if needed. There are two issues addressed by this function:
// 1. In previous versions of OCP, the LatestAvailableRevision could be set to a
// revision with "operator.openshift.io/revision-ready": "false".
// 2. The revision-status was deleted.
func (c RevisionController) fixOperatorLatestAvailableRevision(ctx context.Context, recorder events.Recorder, revision int32) error {
if revision == 0 {
return nil
}

configMap, err := c.configMapGetter.ConfigMaps(c.targetNamespace).Get(ctx, fmt.Sprintf("revision-status-%d", revision), metav1.GetOptions{})
if apierrors.IsNotFound(err) {
// Re-create the configmap and complete the revision.
_, err := c.createNewRevision(ctx, recorder, revision, "revision-status configmap missing")
return err
}

if err != nil {
return err
}

// If revision-ready is false, call createNewRevision to complete the revision.
if configMap.Annotations["operator.openshift.io/revision-ready"] != "true" {
_, err := c.createNewRevision(ctx, recorder, revision, configMap.Data["reason"])
if err != nil {
return err
}
}

return nil
}

func (c RevisionController) sync(ctx context.Context, syncCtx factory.SyncContext) error {
operatorSpec, _, latestAvailableRevisionSeenByOperator, resourceVersion, err := c.operatorClient.GetLatestRevisionState()
if err != nil {
Expand All @@ -331,6 +369,14 @@ func (c RevisionController) sync(ctx context.Context, syncCtx factory.SyncContex
return nil
}

// Past oversights caused the LatestAvailableRevision of the operator to
// target incomplete revisions. Calling fixOperatorLatestAvailableRevision
// will patch them so the revision controller can continue to operate.
err = c.fixOperatorLatestAvailableRevision(ctx, syncCtx.Recorder(), latestAvailableRevisionSeenByOperator)
if err != nil {
return err
}

// If the operator status's latest available revision is not the same as the observed latest revision, update the operator.
latestObservedRevision, err := c.getLatestAvailableRevision(ctx)
if err != nil {
Expand Down
14 changes: 10 additions & 4 deletions pkg/operator/revisioncontroller/revision_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,18 @@ func TestRevisionController(t *testing.T) {
&v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "test-config", Namespace: targetNamespace}},
&v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "revision-status", Namespace: targetNamespace}},
&v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: "revision-status-1", Namespace: targetNamespace},
Data: map[string]string{"revision": "1"},
ObjectMeta: metav1.ObjectMeta{
Name: "revision-status-1", Namespace: targetNamespace,
Annotations: map[string]string{"operator.openshift.io/revision-ready": "true"},
},
Data: map[string]string{"revision": "1"},
},
&v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: "revision-status-2", Namespace: targetNamespace},
Data: map[string]string{"revision": "2"},
ObjectMeta: metav1.ObjectMeta{
Name: "revision-status-2", Namespace: targetNamespace,
Annotations: map[string]string{"operator.openshift.io/revision-ready": "true"},
},
Data: map[string]string{"revision": "2"},
},
},
validateStatus: func(t *testing.T, status *operatorv1.StaticPodOperatorStatus) {
Expand Down