Skip to content
Merged
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
11 changes: 7 additions & 4 deletions docs/draft/concepts/large-bundle-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +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))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P2] Preserve the completed Archived condition when the Secret is missing

If a COS has already finished archiving (Ready=False/Archived), deleting its referenced Secret and reconciling again (for example, after a controller restart) now replaces Archived with PreconditionsNotMet. archivedTeardownComplete requires the Archived reason, so deployment garbage collection can no longer prune this revision even when it exceeds revisionHistoryLimit.

The previous transient-error path preserved Archived, so this is a new regression separate from the acknowledged inability to finish archiving without the Secret. Please preserve the completed archival condition while retaining the new status and retry behavior for active revisions.

Confirmed with a targeted regression test: it passes against the base controller and fails at this head because Archived becomes PreconditionsNotMet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this problem currently exists on main with or without this change since we have to build the boxcutter revision before tearing down. I'll merge this and fix this issue on a separate PR.

return ctrl.Result{RequeueAfter: validationRetryInterval}, nil
}
// Invariant: the error sites in buildBoxcutterPhases classify every deterministic
// (spec/content) failure as a *configValidationError or *referencedContentError,
// 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.
// (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.
// 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)
Expand Down Expand Up @@ -574,6 +582,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 {
Expand Down Expand Up @@ -601,6 +616,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 {
Expand All @@ -624,14 +645,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.
Expand All @@ -654,6 +671,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)
}

Expand Down Expand Up @@ -887,8 +907,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
17 changes: 14 additions & 3 deletions internal/object-controller/controllers/resolve_ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"encoding/json"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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) {
Expand Down
52 changes: 52 additions & 0 deletions test/e2e/object-controller/features/revision.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading