From 5aa128b39092af7b1fe26495962a5f3caea93888 Mon Sep 17 00:00:00 2001 From: "Per G. da Silva" Date: Wed, 2 Dec 2026 10:31:23 +0100 Subject: [PATCH 1/2] Report missing referenced Secrets as PreconditionsNotMet on ClusterObjectSet A ClusterObjectSet whose referenced Secret does not exist was treated as a transient error: the Ready condition was left unchanged and the reconcile was retried with exponential backoff. The failure was only visible in controller logs, and an already-Ready revision kept reporting Ready=True. Referenced Secrets are read uncached, so a NotFound is authoritative. Classify it as a new missingReferencedSecretError, reported as Ready=False/PreconditionsNotMet with an actionable message. Because Secrets are not watched and the ref is immutable, the reconciler retries every validationRetryInterval so the revision recovers once the Secret is created. configValidationError was not used because it does not retry and would leave the revision stuck. Other Secret read errors remain transient. Add unit and e2e coverage for the missing-Secret case and its recovery, and update the large-bundle-support draft doc, which described the old behavior. Signed-off-by: Per G. da Silva --- docs/draft/concepts/large-bundle-support.md | 11 ++-- .../clusterobjectset_controller.go | 41 +++++++++--- .../clusterobjectset_controller_test.go | 66 +++++++++++++++++++ .../controllers/resolve_ref_test.go | 17 ++++- .../features/revision.feature | 52 +++++++++++++++ 5 files changed, 170 insertions(+), 17 deletions(-) diff --git a/docs/draft/concepts/large-bundle-support.md b/docs/draft/concepts/large-bundle-support.md index 1a12a3e3c2..9d59cdc6f2 100644 --- a/docs/draft/concepts/large-bundle-support.md +++ b/docs/draft/concepts/large-bundle-support.md @@ -454,10 +454,13 @@ Under normal operation, referenced Secrets are guaranteed to exist before the COS is created (see [Crash-safe creation sequence](#crash-safe-creation-sequence)). The reconciler distinguishes two failure modes: -- A referenced **Secret that does not exist yet** — for example, informer cache lag - after creation, or a partially completed creation sequence — is treated as a - transient error. The ClusterObjectSet leaves its `Ready` condition unchanged and the - controller returns the error so it retries with backoff. +- A referenced **Secret that does not exist** — for example, a partially completed + creation sequence, or a Secret deleted out from under the revision — is an unmet + precondition. Referenced Secrets are read without a cache, so a NotFound is + authoritative. The ClusterObjectSet reports `Ready=False, Reason=PreconditionsNotMet` + and the reconciler retries periodically so the revision recovers automatically once + the Secret is created. Other Secret read errors are transient: `Ready` is left + unchanged and the controller retries with backoff. - **Invalid referenced content** — a missing key, a malformed manifest, or content that has changed since first rollout — is an unmet precondition. The ClusterObjectSet reports `Ready=False, Reason=PreconditionsNotMet`. Because referenced Secrets are not diff --git a/internal/object-controller/controllers/clusterobjectset_controller.go b/internal/object-controller/controllers/clusterobjectset_controller.go index 784675b2e5..9e7fe15b9e 100644 --- a/internal/object-controller/controllers/clusterobjectset_controller.go +++ b/internal/object-controller/controllers/clusterobjectset_controller.go @@ -174,6 +174,14 @@ func (c *ClusterObjectSetReconciler) reconcile(ctx context.Context, cos *ocv1.Cl markAsNotReady(cos, ocv1.ClusterObjectSetReasonPreconditionsNotMet, fmt.Sprintf("Referenced content is invalid: %v. Fix the Secret content.", err)) return ctrl.Result{RequeueAfter: validationRetryInterval}, nil } + var missingErr *missingReferencedSecretError + if errors.As(err, &missingErr) { + // The referenced Secret does not exist. Secrets are not watched and the ref is + // immutable, so keep retrying so the revision can recover once it is created. + l.Error(err, "referenced Secret not found, marking revision not ready") + markAsNotReady(cos, ocv1.ClusterObjectSetReasonPreconditionsNotMet, fmt.Sprintf("Referenced Secret is missing: %v. Create the Secret.", err)) + return ctrl.Result{RequeueAfter: validationRetryInterval}, nil + } var cfgErr *configValidationError if errors.As(err, &cfgErr) { // Invalid revision spec; a spec edit (or a new revision) re-triggers reconciliation, @@ -183,7 +191,8 @@ func (c *ClusterObjectSetReconciler) reconcile(ctx context.Context, cos *ocv1.Cl return ctrl.Result{}, nil } // Invariant: the error sites in buildBoxcutterPhases classify every deterministic - // (spec/content) failure as a *configValidationError or *referencedContentError, + // (spec/content) failure as a *configValidationError, *referencedContentError, or + // *missingReferencedSecretError, // handled above. Anything reaching here is therefore a transient infrastructure // error (e.g. listing sibling revisions or reading a referenced Secret failed), so // leave Ready unchanged and return the error for a rate-limited backoff requeue. @@ -574,6 +583,13 @@ type configValidationError struct{ error } // so the revision can recover without a controller restart. type referencedContentError struct{ error } +// missingReferencedSecretError marks a referenced Secret that does not exist. Referenced +// Secrets are read uncached, so NotFound is authoritative. They are not watched and the +// ref is immutable, so the failure can only clear when the Secret is created. The reconciler +// reports it as Ready=False/PreconditionsNotMet but keeps retrying periodically so the +// revision can recover without a controller restart. +type missingReferencedSecretError struct{ error } + func (c *ClusterObjectSetReconciler) buildBoxcutterPhases(ctx context.Context, cos *ocv1.ClusterObjectSet) ([]boxcutter.Phase, []ocv1.ObservedPhase, []boxcutter.RevisionReconcileOption, error) { siblings, err := c.listSiblingRevisions(ctx, cos) if err != nil { @@ -601,6 +617,12 @@ func (c *ClusterObjectSetReconciler) buildBoxcutterPhases(ctx context.Context, c observedPhases := make([]ocv1.ObservedPhase, 0, len(cos.Spec.Phases)) for _, specPhase := range cos.Spec.Phases { objs := make([]client.Object, 0, len(specPhase.Objects)) + phaseStatus := ocv1.ObservedPhase{ + Name: specPhase.Name, + Status: ocv1.PhaseStatusUnknown, + LastTransitionTime: metav1.NewTime(c.Clock.Now()), + Message: "phase has not been evaluated", + } for _, specObj := range specPhase.Objects { var obj *unstructured.Unstructured switch specObj.Type { @@ -624,14 +646,10 @@ func (c *ClusterObjectSetReconciler) buildBoxcutterPhases(ctx context.Context, c if err != nil { return nil, nil, nil, fmt.Errorf("computing phase digest: %w", err) } + phaseStatus.Digest = digest + // Make sure we set all the required fields - observedPhases = append(observedPhases, ocv1.ObservedPhase{ - Name: specPhase.Name, - Digest: digest, - Status: ocv1.PhaseStatusUnknown, - LastTransitionTime: metav1.NewTime(c.Clock.Now()), - Message: "phase has not been evaluated", - }) + observedPhases = append(observedPhases, phaseStatus) // Managed objects are labeled app.kubernetes.io/managed-by by the boxcutter // revision engine; the controller does not add owner labels of its own. @@ -654,6 +672,9 @@ func (c *ClusterObjectSetReconciler) resolveSecretRef(ctx context.Context, ref o secret := &corev1.Secret{} key := client.ObjectKey{Name: ref.Name, Namespace: ref.Namespace} if err := c.Client.Get(ctx, key, secret); err != nil { + if apierrors.IsNotFound(err) { + return nil, &missingReferencedSecretError{fmt.Errorf("getting Secret %s/%s: %w", ref.Namespace, ref.Name, err)} + } return nil, fmt.Errorf("getting Secret %s/%s: %w", ref.Namespace, ref.Name, err) } @@ -887,8 +908,8 @@ func (c *ClusterObjectSetReconciler) verifyReferencedSecretsImmutable(ctx contex key := client.ObjectKey{Name: ref.name, Namespace: ref.namespace} if err := c.Client.Get(ctx, key, secret); err != nil { if apierrors.IsNotFound(err) { - // Secret not yet available — skip verification. - // resolveSecretRef will handle the not-found with a retryable error. + // Secret not yet available — skip verification. resolveSecretRef reports + // it as a *missingReferencedSecretError (Ready=False/PreconditionsNotMet). continue } // Remember the first read error but keep checking the remaining refs: a diff --git a/internal/object-controller/controllers/clusterobjectset_controller_test.go b/internal/object-controller/controllers/clusterobjectset_controller_test.go index 75b2f8749f..adc5af90e9 100644 --- a/internal/object-controller/controllers/clusterobjectset_controller_test.go +++ b/internal/object-controller/controllers/clusterobjectset_controller_test.go @@ -1069,6 +1069,72 @@ func Test_ClusterObjectSetReconciler_Reconcile_ReferencedContentValidationRecove require.Equal(t, ocv1.ClusterObjectSetReasonAllObjectsReady, cond.Reason) } +func Test_ClusterObjectSetReconciler_Reconcile_MissingReferencedSecretRecovers(t *testing.T) { + const clusterObjectSetName = "test-ext-1" + + testScheme := newScheme(t) + require.NoError(t, corev1.AddToScheme(testScheme)) + mockCtrl := gomock.NewController(t) + + ext := newTestClusterExtension() + rev1 := newTestClusterObjectSet(t, clusterObjectSetName, ext, testScheme) + rev1.Spec.Phases = []ocv1.ClusterObjectSetPhase{{ + Name: "everything", + Objects: []ocv1.ClusterObjectSetObject{ + {Type: ocv1.ObjectTypeSecretReference, SecretRef: ocv1.SecretSourceRef{Name: "manifest", Namespace: "ns", Key: "configmap"}}, + }, + }} + + // The referenced Secret does not exist yet. + testClient := testutil.WithIndexes(t, fake.NewClientBuilder().WithScheme(testScheme), controllers.SetupIndexes). + WithStatusSubresource(&ocv1.ClusterObjectSet{}). + WithObjects(ext, rev1). + Build() + + engine := newMockRevisionEngineWithReconcile(mockCtrl, + func(context.Context, machinerytypes.Revision, ...machinerytypes.RevisionReconcileOption) (machinery.RevisionResult, error) { + return newMockRevisionResult(mockCtrl, revisionResultConfig{isComplete: true}), nil + }, nil) + r := &controllers.ClusterObjectSetReconciler{ + Client: testClient, + RevisionEngineFactory: newMockRevisionEngineFactoryWithEngine(mockCtrl, engine, nil), + TrackingCache: newMockTrackingCache(mockCtrl, testClient, nil), + } + req := ctrl.Request{NamespacedName: types.NamespacedName{Name: clusterObjectSetName}} + + // A missing referenced Secret is an unmet precondition that is reported in status and + // keeps retrying (Secrets are not watched) so the revision can recover once it is created. + result, err := r.Reconcile(t.Context(), req) + require.NoError(t, err) + require.Equal(t, ctrl.Result{RequeueAfter: 10 * time.Second}, result) + + rev := &ocv1.ClusterObjectSet{} + require.NoError(t, testClient.Get(t.Context(), req.NamespacedName, rev)) + cond := meta.FindStatusCondition(rev.Status.Conditions, ocv1.ClusterObjectSetTypeReady) + require.NotNil(t, cond) + require.Equal(t, metav1.ConditionFalse, cond.Status) + require.Equal(t, ocv1.ClusterObjectSetReasonPreconditionsNotMet, cond.Reason) + require.Contains(t, cond.Message, "ns/manifest") + require.Contains(t, cond.Message, "Create the Secret") + require.Empty(t, rev.Status.ObservedPhases) + + immutable := true + require.NoError(t, testClient.Create(t.Context(), &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Name: "manifest", Namespace: "ns"}, + Immutable: &immutable, + Data: map[string][]byte{"configmap": []byte(`{"apiVersion":"v1","kind":"ConfigMap","metadata":{"name":"cm","namespace":"ns"}}`)}, + })) + + // The revision recovers on the next reconcile, without any change to the ClusterObjectSet itself. + _, err = r.Reconcile(t.Context(), req) + require.NoError(t, err) + require.NoError(t, testClient.Get(t.Context(), req.NamespacedName, rev)) + cond = meta.FindStatusCondition(rev.Status.Conditions, ocv1.ClusterObjectSetTypeReady) + require.NotNil(t, cond) + require.Equal(t, metav1.ConditionTrue, cond.Status) + require.Equal(t, ocv1.ClusterObjectSetReasonAllObjectsReady, cond.Reason) +} + func Test_ClusterObjectSetReconciler_Reconcile_BuildPhasesErrorClassification(t *testing.T) { const clusterObjectSetName = "test-ext-1" diff --git a/internal/object-controller/controllers/resolve_ref_test.go b/internal/object-controller/controllers/resolve_ref_test.go index f637c3f174..a3598ab5c2 100644 --- a/internal/object-controller/controllers/resolve_ref_test.go +++ b/internal/object-controller/controllers/resolve_ref_test.go @@ -6,6 +6,7 @@ import ( "context" "encoding/json" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -176,11 +177,21 @@ func TestResolveSecretRef_SecretNotFound(t *testing.T) { Clock: clocktesting.NewFakeClock(metav1.Now().Time), } - _, err := reconciler.Reconcile(context.Background(), ctrl.Request{ + // A missing referenced Secret is an unmet precondition: no error is returned, and Ready + // reports PreconditionsNotMet (retried until the Secret is created). + result, err := reconciler.Reconcile(context.Background(), ctrl.Request{ NamespacedName: types.NamespacedName{Name: cos.Name}, }) - require.Error(t, err) - assert.Contains(t, err.Error(), "resolving ref") + require.NoError(t, err) + assert.Equal(t, ctrl.Result{RequeueAfter: 10 * time.Second}, result) + + updated := &ocv1.ClusterObjectSet{} + require.NoError(t, fakeClient.Get(context.Background(), client.ObjectKey{Name: cos.Name}, updated)) + cond := meta.FindStatusCondition(updated.Status.Conditions, ocv1.ClusterObjectSetTypeReady) + require.NotNil(t, cond) + assert.Equal(t, metav1.ConditionFalse, cond.Status) + assert.Equal(t, ocv1.ClusterObjectSetReasonPreconditionsNotMet, cond.Reason) + assert.Contains(t, cond.Message, "olmv1-system/nonexistent-secret") } func TestResolveSecretRef_KeyNotFound(t *testing.T) { diff --git a/test/e2e/object-controller/features/revision.feature b/test/e2e/object-controller/features/revision.feature index acb76a323d..cc4dc1c4fc 100644 --- a/test/e2e/object-controller/features/revision.feature +++ b/test/e2e/object-controller/features/revision.feature @@ -646,6 +646,58 @@ Feature: Install ClusterObjectSet Referenced content is invalid: resolving ref in phase "resources": key "does-not-exist" not found in Secret ${TEST_NAMESPACE}/${COS_NAME}-missing-key-secret. Fix the Secret content. """ + Scenario: ClusterObjectSet reports PreconditionsNotMet when a referenced Secret does not exist and recovers once it is created + Given namespace "${TEST_NAMESPACE}" is available + When ClusterObjectSet is applied + """ + apiVersion: olm.operatorframework.io/v1 + kind: ClusterObjectSet + metadata: + name: ${COS_NAME} + spec: + group: ${NAME} + lifecycleState: Active + collisionProtection: Prevent + phases: + - name: resources + objects: + - type: SecretReference + secretRef: + name: ${COS_NAME}-absent-secret + namespace: ${TEST_NAMESPACE} + key: configmap + revision: 1 + """ + Then ClusterObjectSet "${COS_NAME}" reports Ready as False with Reason PreconditionsNotMet and Message includes: + """ + Referenced Secret is missing: resolving ref in phase "resources": getting Secret ${TEST_NAMESPACE}/${COS_NAME}-absent-secret + """ + When resource is applied + """ + apiVersion: v1 + kind: Secret + metadata: + name: ${COS_NAME}-absent-secret + namespace: ${TEST_NAMESPACE} + immutable: true + type: olm.operatorframework.io/object-data + stringData: + configmap: | + { + "apiVersion": "v1", + "kind": "ConfigMap", + "metadata": { + "name": "test-cm-absent-secret", + "namespace": "${TEST_NAMESPACE}" + }, + "data": { + "key": "value" + } + } + """ + Then ClusterObjectSet "${COS_NAME}" reports Ready as True with Reason AllObjectsReady + And resource "configmap/test-cm-absent-secret" is installed + Scenario: ClusterObjectSet reports PreconditionsNotMet when a referenced Secret has malformed content Given namespace "${TEST_NAMESPACE}" is available And resource is applied From 55f2de581eacc0340b03f9f1c0c38a48ef3a059b Mon Sep 17 00:00:00 2001 From: "Per G. da Silva" Date: Wed, 2 Dec 2026 10:56:32 +0100 Subject: [PATCH 2/2] Use errors.AsType for the missingReferencedSecretError check Match the errors.AsType style being adopted repo-wide. Place the check after the configValidationError branch, which leaves the neighbouring errors.As call sites unchanged so this change merges cleanly alongside the repo-wide conversion. The order does not matter: the error types are distinct and each branch returns. Signed-off-by: Per G. da Silva --- .../clusterobjectset_controller.go | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/internal/object-controller/controllers/clusterobjectset_controller.go b/internal/object-controller/controllers/clusterobjectset_controller.go index 9e7fe15b9e..f1b0e478f8 100644 --- a/internal/object-controller/controllers/clusterobjectset_controller.go +++ b/internal/object-controller/controllers/clusterobjectset_controller.go @@ -174,14 +174,6 @@ func (c *ClusterObjectSetReconciler) reconcile(ctx context.Context, cos *ocv1.Cl markAsNotReady(cos, ocv1.ClusterObjectSetReasonPreconditionsNotMet, fmt.Sprintf("Referenced content is invalid: %v. Fix the Secret content.", err)) return ctrl.Result{RequeueAfter: validationRetryInterval}, nil } - var missingErr *missingReferencedSecretError - if errors.As(err, &missingErr) { - // The referenced Secret does not exist. Secrets are not watched and the ref is - // immutable, so keep retrying so the revision can recover once it is created. - l.Error(err, "referenced Secret not found, marking revision not ready") - markAsNotReady(cos, ocv1.ClusterObjectSetReasonPreconditionsNotMet, fmt.Sprintf("Referenced Secret is missing: %v. Create the Secret.", err)) - return ctrl.Result{RequeueAfter: validationRetryInterval}, nil - } var cfgErr *configValidationError if errors.As(err, &cfgErr) { // Invalid revision spec; a spec edit (or a new revision) re-triggers reconciliation, @@ -190,12 +182,19 @@ func (c *ClusterObjectSetReconciler) reconcile(ctx context.Context, cos *ocv1.Cl markAsNotReady(cos, ocv1.ClusterObjectSetReasonInvalidSpecification, fmt.Sprintf("The object set spec is invalid: %v.", err)) return ctrl.Result{}, nil } + if _, ok := errors.AsType[*missingReferencedSecretError](err); ok { + // The referenced Secret does not exist. Secrets are not watched and the ref is + // immutable, so keep retrying so the revision can recover once it is created. + l.Error(err, "referenced Secret not found, marking revision not ready") + markAsNotReady(cos, ocv1.ClusterObjectSetReasonPreconditionsNotMet, fmt.Sprintf("Referenced Secret is missing: %v. Create the Secret.", err)) + return ctrl.Result{RequeueAfter: validationRetryInterval}, nil + } // Invariant: the error sites in buildBoxcutterPhases classify every deterministic // (spec/content) failure as a *configValidationError, *referencedContentError, or - // *missingReferencedSecretError, - // handled above. Anything reaching here is therefore a transient infrastructure - // error (e.g. listing sibling revisions or reading a referenced Secret failed), so - // leave Ready unchanged and return the error for a rate-limited backoff requeue. + // *missingReferencedSecretError, handled above. Anything reaching here is therefore + // a transient infrastructure error (e.g. listing sibling revisions or reading a + // referenced Secret failed), so leave Ready unchanged and return the error for a + // rate-limited backoff requeue. // New deterministic failure modes added to buildBoxcutterPhases must be wrapped in // one of those typed errors so they are reported rather than retried forever. return ctrl.Result{}, fmt.Errorf("converting to boxcutter revision: %v", err)