From 44ce194d2c486669fef61d6a280556780e06c3a8 Mon Sep 17 00:00:00 2001 From: "Per G. da Silva" Date: Wed, 2 Dec 2026 12:24:36 +0100 Subject: [PATCH] Add superseded and colliding counts to ClusterObjectSet objectCounts Add two counts to status.objectCounts, as proposed in the GA API shape in #3190, following the conventions of the existing count fields (required, always reported including zeros, 0-1000): - superseded: objects observed under the control of a newer sibling revision in the same group (boxcutter ActionProgressed). They also count as present, but not as synced. - colliding: objects whose adoption is refused by the collision protection policy (ActionCollision). They count as neither present, synced, nor superseded. Collisions in paused later phases are counted too, since they do not resolve by rolling out earlier phases. This replaces the TODO to surface collisions. Both are set to zero during teardown. Extend the "reports aggregate object counts" e2e step to cover the new counts, assert them in the collision and blocked-handoff scenarios, and add unit and CRD validation coverage. Signed-off-by: Per G. da Silva --- api/v1/clusterobjectset_types.go | 19 ++++++ api/v1/clusterobjectset_types_test.go | 10 +-- api/v1/validation_test.go | 66 +++++++++++++++++++ api/v1/zz_generated.deepcopy.go | 10 +++ applyconfigurations/api/v1/objectcounts.go | 27 ++++++++ applyconfigurations/internal/internal.go | 6 ++ ...peratorframework.io_clusterobjectsets.yaml | 23 +++++++ .../clusterobjectdeployment_ownership_test.go | 6 +- internal/object-controller/status/status.go | 35 +++++----- .../object-controller/status/status_test.go | 57 ++++++++++++---- manifests/experimental-e2e.yaml | 23 +++++++ manifests/experimental.yaml | 23 +++++++ .../features/cod_handoff.feature | 5 ++ .../cos_object_collision_and_adoption.feature | 1 + .../features/cos_object_lifecycle.feature | 4 +- .../features/revision.feature | 4 +- .../e2e/object-controller/steps/steps.go | 8 ++- 17 files changed, 284 insertions(+), 43 deletions(-) diff --git a/api/v1/clusterobjectset_types.go b/api/v1/clusterobjectset_types.go index 0e09c83df5..9548bbb75f 100644 --- a/api/v1/clusterobjectset_types.go +++ b/api/v1/clusterobjectset_types.go @@ -707,6 +707,25 @@ type ObjectCounts struct { // +kubebuilder:validation:Minimum:=0 // +kubebuilder:validation:Maximum:=1000 Ready *int64 `json:"ready,omitempty"` + + // superseded is the number of objects in this object set that are observed + // under the control of another object set in the same group with a higher + // revision. These objects also count as present, but not as synced. This + // describes observed ownership, not a cumulative count of transfers. + // Set to zero during teardown. + // +required + // +kubebuilder:validation:Minimum:=0 + // +kubebuilder:validation:Maximum:=1000 + Superseded *int64 `json:"superseded,omitempty"` + + // colliding is the number of objects in this object set whose adoption is + // refused by the configured collision protection policy. The conflicting + // resources exist on the cluster but do not count as present, synced, or + // superseded. Set to zero during teardown. + // +required + // +kubebuilder:validation:Minimum:=0 + // +kubebuilder:validation:Maximum:=1000 + Colliding *int64 `json:"colliding,omitempty"` } // ObjectStatus identifies a managed object and its failure messages. diff --git a/api/v1/clusterobjectset_types_test.go b/api/v1/clusterobjectset_types_test.go index 9f2929365f..ca9bdda65d 100644 --- a/api/v1/clusterobjectset_types_test.go +++ b/api/v1/clusterobjectset_types_test.go @@ -1107,7 +1107,7 @@ func configMap() unstructured.Unstructured { } // TestObjectCountsSerialization verifies the per-count serialization semantics of -// the required *int64 count fields. total/present/synced/ready are all required but +// the required *int64 count fields. total/present/synced/ready/superseded/colliding are all required but // are pointers with omitempty so the controller can distinguish a count it has not // computed (nil) from one it has computed as zero (a pointer to 0): // - A count explicitly set to 0 (e.g. ready=0 while a phase is rolling out, or @@ -1115,14 +1115,14 @@ func configMap() unstructured.Unstructured { // - A count left unset (nil) is omitted entirely, not serialized as 0. func TestObjectCountsSerialization(t *testing.T) { // A count explicitly set to 0 serializes as 0 rather than being omitted. - data, err := json.Marshal(ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(0))}) + data, err := json.Marshal(ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(0)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}) require.NoError(t, err) - require.JSONEq(t, `{"total":1,"present":1,"synced":1,"ready":0}`, string(data)) + require.JSONEq(t, `{"total":1,"present":1,"synced":1,"ready":0,"superseded":0,"colliding":0}`, string(data)) // Every count explicitly set to 0 is serialized; none is omitted. - data, err = json.Marshal(ObjectCounts{Total: ptr.To(int64(0)), Present: ptr.To(int64(0)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0))}) + data, err = json.Marshal(ObjectCounts{Total: ptr.To(int64(0)), Present: ptr.To(int64(0)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}) require.NoError(t, err) - require.JSONEq(t, `{"total":0,"present":0,"synced":0,"ready":0}`, string(data)) + require.JSONEq(t, `{"total":0,"present":0,"synced":0,"ready":0,"superseded":0,"colliding":0}`, string(data)) // An unset (nil) count is omitted rather than serialized as 0. data, err = json.Marshal(ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1))}) diff --git a/api/v1/validation_test.go b/api/v1/validation_test.go index 9304206b08..11177d1f98 100644 --- a/api/v1/validation_test.go +++ b/api/v1/validation_test.go @@ -413,3 +413,69 @@ func TestClusterObjectSetDigestImmutable(t *testing.T) { err := c.Status().Update(t.Context(), cos) require.True(t, errors.IsInvalid(err), "expected update to fail as invalid, but got: %v", err) } + +func TestClusterObjectSetObjectCountsValidation(t *testing.T) { + c := newClient(t) + + for _, tc := range []struct { + name string + cosName string + counts ObjectCounts + wantInvalid string + }{ + { + name: "all counts set is valid", + cosName: "cos-objectcounts-valid-1", + counts: ObjectCounts{Total: ptr.To(int64(3)), Present: ptr.To(int64(2)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(1)), Superseded: ptr.To(int64(1)), Colliding: ptr.To(int64(1))}, + }, + { + name: "superseded is required", + cosName: "cos-objectcounts-nosuperseded-1", + counts: ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(1)), Colliding: ptr.To(int64(0))}, + wantInvalid: "status.objectCounts.superseded: Required value", + }, + { + name: "colliding is required", + cosName: "cos-objectcounts-nocolliding-1", + counts: ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(1)), Superseded: ptr.To(int64(0))}, + wantInvalid: "status.objectCounts.colliding: Required value", + }, + { + name: "superseded must be at most 1000", + cosName: "cos-objectcounts-supersededmax-1", + counts: ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(1)), Superseded: ptr.To(int64(1001)), Colliding: ptr.To(int64(0))}, + wantInvalid: "status.objectCounts.superseded: Invalid value", + }, + { + name: "colliding must not be negative", + cosName: "cos-objectcounts-collidingmin-1", + counts: ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(1)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(-1))}, + wantInvalid: "status.objectCounts.colliding: Invalid value", + }, + } { + t.Run(tc.name, func(t *testing.T) { + cos := &ClusterObjectSet{ + ObjectMeta: metav1.ObjectMeta{Name: tc.cosName}, + Spec: ClusterObjectSetSpec{ + Group: strings.TrimSuffix(tc.cosName, "-1"), + Revision: 1, + LifecycleState: ClusterObjectSetLifecycleStateActive, + ClusterObjectSetContent: ClusterObjectSetContent{ + CollisionProtection: CollisionProtectionPrevent, + Phases: []ClusterObjectSetPhase{{Name: "deploy", Objects: []ClusterObjectSetObject{}}}, + }, + }, + } + require.NoError(t, c.Create(t.Context(), cos)) + + cos.Status.ObjectCounts = tc.counts + err := c.Status().Update(t.Context(), cos) + if tc.wantInvalid == "" { + require.NoError(t, err) + return + } + require.True(t, errors.IsInvalid(err), "expected update to fail as invalid, but got: %v", err) + require.ErrorContains(t, err, tc.wantInvalid) + }) + } +} diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index e5627866a4..a0a35b8add 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -842,6 +842,16 @@ func (in *ObjectCounts) DeepCopyInto(out *ObjectCounts) { *out = new(int64) **out = **in } + if in.Superseded != nil { + in, out := &in.Superseded, &out.Superseded + *out = new(int64) + **out = **in + } + if in.Colliding != nil { + in, out := &in.Colliding, &out.Colliding + *out = new(int64) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ObjectCounts. diff --git a/applyconfigurations/api/v1/objectcounts.go b/applyconfigurations/api/v1/objectcounts.go index 9f2421ccdd..35d7c93b02 100644 --- a/applyconfigurations/api/v1/objectcounts.go +++ b/applyconfigurations/api/v1/objectcounts.go @@ -36,6 +36,17 @@ type ObjectCountsApplyConfiguration struct { // ready is the number of objects in this object set that are synced // and pass their assertions. Ready *int64 `json:"ready,omitempty"` + // superseded is the number of objects in this object set that are observed + // under the control of another object set in the same group with a higher + // revision. These objects also count as present, but not as synced. This + // describes observed ownership, not a cumulative count of transfers. + // Set to zero during teardown. + Superseded *int64 `json:"superseded,omitempty"` + // colliding is the number of objects in this object set whose adoption is + // refused by the configured collision protection policy. The conflicting + // resources exist on the cluster but do not count as present, synced, or + // superseded. Set to zero during teardown. + Colliding *int64 `json:"colliding,omitempty"` } // ObjectCountsApplyConfiguration constructs a declarative configuration of the ObjectCounts type for use with @@ -75,3 +86,19 @@ func (b *ObjectCountsApplyConfiguration) WithReady(value int64) *ObjectCountsApp b.Ready = &value return b } + +// WithSuperseded sets the Superseded field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Superseded field is set to the value of the last call. +func (b *ObjectCountsApplyConfiguration) WithSuperseded(value int64) *ObjectCountsApplyConfiguration { + b.Superseded = &value + return b +} + +// WithColliding sets the Colliding field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Colliding field is set to the value of the last call. +func (b *ObjectCountsApplyConfiguration) WithColliding(value int64) *ObjectCountsApplyConfiguration { + b.Colliding = &value + return b +} diff --git a/applyconfigurations/internal/internal.go b/applyconfigurations/internal/internal.go index a628fe4149..07631e6fec 100644 --- a/applyconfigurations/internal/internal.go +++ b/applyconfigurations/internal/internal.go @@ -466,12 +466,18 @@ var schemaYAML = typed.YAMLObject(`types: - name: com.github.operator-framework.operator-controller.api.v1.ObjectCounts map: fields: + - name: colliding + type: + scalar: numeric - name: present type: scalar: numeric - name: ready type: scalar: numeric + - name: superseded + type: + scalar: numeric - name: synced type: scalar: numeric diff --git a/helm/olmv1/base/object-controller/crd/experimental/olm.operatorframework.io_clusterobjectsets.yaml b/helm/olmv1/base/object-controller/crd/experimental/olm.operatorframework.io_clusterobjectsets.yaml index 002716a92b..7eace96101 100644 --- a/helm/olmv1/base/object-controller/crd/experimental/olm.operatorframework.io_clusterobjectsets.yaml +++ b/helm/olmv1/base/object-controller/crd/experimental/olm.operatorframework.io_clusterobjectsets.yaml @@ -730,6 +730,16 @@ spec: It is omitted until counts have been computed; when present, all count fields are reported (including zeros). properties: + colliding: + description: |- + colliding is the number of objects in this object set whose adoption is + refused by the configured collision protection policy. The conflicting + resources exist on the cluster but do not count as present, synced, or + superseded. Set to zero during teardown. + format: int64 + maximum: 1000 + minimum: 0 + type: integer present: description: |- present is the number of objects in this object set that exist on the @@ -748,6 +758,17 @@ spec: maximum: 1000 minimum: 0 type: integer + superseded: + description: |- + superseded is the number of objects in this object set that are observed + under the control of another object set in the same group with a higher + revision. These objects also count as present, but not as synced. This + describes observed ownership, not a cumulative count of transfers. + Set to zero during teardown. + format: int64 + maximum: 1000 + minimum: 0 + type: integer synced: description: |- synced is the number of objects in this object set whose cluster state @@ -763,8 +784,10 @@ spec: minimum: 0 type: integer required: + - colliding - present - ready + - superseded - synced - total type: object diff --git a/internal/object-controller/controllers/clusterobjectdeployment_ownership_test.go b/internal/object-controller/controllers/clusterobjectdeployment_ownership_test.go index c67871f4fd..191976f3b2 100644 --- a/internal/object-controller/controllers/clusterobjectdeployment_ownership_test.go +++ b/internal/object-controller/controllers/clusterobjectdeployment_ownership_test.go @@ -55,7 +55,7 @@ func TestClusterObjectDeploymentGroupEvents(t *testing.T) { assert.NoError(collect, cl.Get(t.Context(), client.ObjectKey{Name: cod.Name + "-1"}, owned)) }, 10*time.Second, 10*time.Millisecond) owned.Status.CompletedAt = metav1.Now() - owned.Status.ObjectCounts = ocv1.ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(1))} + owned.Status.ObjectCounts = ocv1.ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(1)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))} setCOSReady(owned, metav1.ConditionTrue, ocv1.ClusterObjectSetReasonAllObjectsReady) require.NoError(t, cl.Status().Update(t.Context(), owned)) waitForCODCondition(t, cl, cod.Name, ocv1.ClusterObjectDeploymentTypeAvailable, @@ -75,7 +75,7 @@ func TestClusterObjectDeploymentGroupEvents(t *testing.T) { // A ready foreign revision cannot supply the COD's availability. setCOSReady(foreign, metav1.ConditionTrue, ocv1.ClusterObjectSetReasonAllObjectsReady) - foreign.Status.ObjectCounts = ocv1.ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(1))} + foreign.Status.ObjectCounts = ocv1.ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(1)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))} require.NoError(t, cl.Status().Update(t.Context(), foreign)) markCOSReady(t, cl, owned.Name, false) waitForCODCondition(t, cl, cod.Name, ocv1.ClusterObjectDeploymentTypeAvailable, @@ -91,7 +91,7 @@ func TestClusterObjectDeploymentGroupEvents(t *testing.T) { metav1.ConditionFalse, ocv1.ClusterObjectDeploymentReasonOwnerConflict, cod.Generation) require.True(t, apierrors.IsNotFound(cl.Get(t.Context(), client.ObjectKey{Name: cod.Name + "-4"}, &ocv1.ClusterObjectSet{}))) require.NoError(t, cl.Get(t.Context(), client.ObjectKeyFromObject(owned), owned)) - require.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(1))}, owned.Status.ObjectCounts) + require.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(1)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}, owned.Status.ObjectCounts) // Only the foreign COS changes here. Its group event must release the // conflict and reconcile the already-updated COD template. diff --git a/internal/object-controller/status/status.go b/internal/object-controller/status/status.go index cbeb247d34..c683f15fa8 100644 --- a/internal/object-controller/status/status.go +++ b/internal/object-controller/status/status.go @@ -21,10 +21,12 @@ import ( // zeroObjectCounts returns an ObjectCounts aggregate initialized to zero. func zeroObjectCounts() ocv1.ObjectCounts { return ocv1.ObjectCounts{ - Total: new(int64(0)), - Present: new(int64(0)), - Synced: new(int64(0)), - Ready: new(int64(0)), + Total: new(int64(0)), + Present: new(int64(0)), + Synced: new(int64(0)), + Ready: new(int64(0)), + Superseded: new(int64(0)), + Colliding: new(int64(0)), } } @@ -37,6 +39,8 @@ func addObjectCounts(agg *ocv1.ObjectCounts, counts ocv1.ObjectCounts) { *agg.Present += ptr.Deref(counts.Present, 0) *agg.Synced += ptr.Deref(counts.Synced, 0) *agg.Ready += ptr.Deref(counts.Ready, 0) + *agg.Superseded += ptr.Deref(counts.Superseded, 0) + *agg.Colliding += ptr.Deref(counts.Colliding, 0) } func UpdateObservedPhasesForReconcile(mapper apimeta.RESTMapper, objSet *ocv1.ClusterObjectSet, rres machinery.RevisionResult, now metav1.Time) { @@ -71,12 +75,8 @@ func UpdateObservedPhasesForReconcile(mapper apimeta.RESTMapper, objSet *ocv1.Cl } // Per-phase counts are computed locally to derive the phase status and to // feed the object-set aggregate; they are not persisted on the phase status. - phaseObjectCounts := ocv1.ObjectCounts{ - Total: new(phaseTotals[pres.GetName()]), - Present: new(int64(0)), - Synced: new(int64(0)), - Ready: new(int64(0)), - } + phaseObjectCounts := zeroObjectCounts() + phaseObjectCounts.Total = new(phaseTotals[pres.GetName()]) if pres.GetValidationError() != nil { if !precedingPhasesComplete { @@ -115,14 +115,18 @@ func UpdateObservedPhasesForReconcile(mapper apimeta.RESTMapper, objSet *ocv1.Cl *phaseObjectCounts.Present++ *phaseObjectCounts.Synced++ case machinery.ActionProgressed: + // Adopted by a newer sibling revision: present, but not synced to this one. *phaseObjectCounts.Present++ + *phaseObjectCounts.Superseded++ case machinery.ActionUpdated, machinery.ActionRecovered: *phaseObjectCounts.Present++ if !pobj.IsPaused() { *phaseObjectCounts.Synced++ } case machinery.ActionCollision: - // TODO: collect object collisions and put in status + // Adoption refused by collision protection. Counted even in a paused phase: + // a collision does not resolve by rolling out earlier phases. + *phaseObjectCounts.Colliding++ } // track for phase status derivation @@ -193,12 +197,9 @@ func UpdateObservedPhasesForTeardown(mapper apimeta.RESTMapper, objSet *ocv1.Clu // Per-phase counts feed the object-set aggregate but are not persisted // on the phase status. - counts := ocv1.ObjectCounts{ - Total: new(phaseTotals[pres.GetName()]), - Present: new(int64(len(pres.Waiting()))), - Synced: new(int64(0)), - Ready: new(int64(0)), - } + counts := zeroObjectCounts() + counts.Total = new(phaseTotals[pres.GetName()]) + counts.Present = new(int64(len(pres.Waiting()))) addObjectCounts(&aggregate, counts) if name, ok := tres.GetActivePhaseName(); ok && name == pres.GetName() { diff --git a/internal/object-controller/status/status_test.go b/internal/object-controller/status/status_test.go index 98bd76ecfb..e6014170ca 100644 --- a/internal/object-controller/status/status_test.go +++ b/internal/object-controller/status/status_test.go @@ -227,7 +227,7 @@ func TestUpdateObservedPhasesForReconcile(t *testing.T) { assert.Equal(t, ocv1.PhaseStatusSuperseded, cos.Status.ObservedPhases[0].Status) }) - t.Run("collision object is not counted as Present and phase reports Reconciling", func(t *testing.T) { + t.Run("collision object is counted as Colliding but not Present and phase reports Reconciling", func(t *testing.T) { cos := cosWithPhaseObjects(struct { name string objects int @@ -243,10 +243,42 @@ func TestUpdateObservedPhasesForReconcile(t *testing.T) { } UpdateObservedPhasesForReconcile(testMapper, &cos, result, now) require.NotNil(t, cos.Status.ObservedPhases) - assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(0)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0))}, cos.Status.ObjectCounts) + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(1)), Present: ptr.To(int64(0)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(1))}, cos.Status.ObjectCounts) assert.Equal(t, ocv1.PhaseStatusReconciling, cos.Status.ObservedPhases[0].Status) }) + t.Run("collision in a paused later phase is counted as Colliding", func(t *testing.T) { + // A collision does not resolve by rolling out earlier phases, so it is counted + // even while its phase is only observed read-only. + cos := cosWithPhaseObjects( + struct { + name string + objects int + }{"p1", 1}, + struct { + name string + objects int + }{"p2", 1}, + ) + result := &fakeRevisionResult{ + phases: []machinery.PhaseResult{ + &fakePhaseResult{name: "p1", complete: false, objects: []machinery.ObjectResult{ + &fakeObjectResult{obj: obj, complete: false, action: machinery.ActionIdle}, + }}, + &fakePhaseResult{name: "p2", complete: false, objects: []machinery.ObjectResult{ + &fakeCollisionResult{ + fakeObjectResult: fakeObjectResult{obj: obj, complete: false, paused: true, probes: boxcuttertypes.ProbeResultContainer{}}, + }, + }}, + }, + } + UpdateObservedPhasesForReconcile(testMapper, &cos, result, now) + require.Len(t, cos.Status.ObservedPhases, 2) + assert.Equal(t, ocv1.PhaseStatusPending, cos.Status.ObservedPhases[1].Status) + // p1: Present1,Synced1 — p2: Colliding1 + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(2)), Present: ptr.To(int64(1)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(0)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(1))}, cos.Status.ObjectCounts) + }) + t.Run("complete phase reports Ready with full counts", func(t *testing.T) { cos := cosWithPhaseObjects(struct { name string @@ -262,7 +294,7 @@ func TestUpdateObservedPhasesForReconcile(t *testing.T) { } UpdateObservedPhasesForReconcile(testMapper, &cos, result, now) assert.Equal(t, ocv1.PhaseStatusReady, cos.Status.ObservedPhases[0].Status) - assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(2)), Present: ptr.To(int64(2)), Synced: ptr.To(int64(2)), Ready: ptr.To(int64(2))}, cos.Status.ObjectCounts) + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(2)), Present: ptr.To(int64(2)), Synced: ptr.To(int64(2)), Ready: ptr.To(int64(2)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}, cos.Status.ObjectCounts) }) t.Run("all idle objects reports Stabilizing", func(t *testing.T) { @@ -280,7 +312,7 @@ func TestUpdateObservedPhasesForReconcile(t *testing.T) { } UpdateObservedPhasesForReconcile(testMapper, &cos, result, now) assert.Equal(t, ocv1.PhaseStatusStabilizing, cos.Status.ObservedPhases[0].Status) - assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(2)), Present: ptr.To(int64(2)), Synced: ptr.To(int64(2)), Ready: ptr.To(int64(1))}, cos.Status.ObjectCounts) + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(2)), Present: ptr.To(int64(2)), Synced: ptr.To(int64(2)), Ready: ptr.To(int64(1)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}, cos.Status.ObjectCounts) }) t.Run("write actions (Created, Updated, Recovered) count as Synced for non-paused objects", func(t *testing.T) { @@ -301,7 +333,7 @@ func TestUpdateObservedPhasesForReconcile(t *testing.T) { } UpdateObservedPhasesForReconcile(testMapper, &cos, result, now) assert.Equal(t, ocv1.PhaseStatusStabilizing, cos.Status.ObservedPhases[0].Status) - assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(3)), Present: ptr.To(int64(3)), Synced: ptr.To(int64(3)), Ready: ptr.To(int64(0))}, cos.Status.ObjectCounts) + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(3)), Present: ptr.To(int64(3)), Synced: ptr.To(int64(3)), Ready: ptr.To(int64(0)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}, cos.Status.ObjectCounts) }) t.Run("all-paused phase reports Pending with write actions not counted as Synced", func(t *testing.T) { @@ -324,7 +356,7 @@ func TestUpdateObservedPhasesForReconcile(t *testing.T) { // isPaused=true → default case → Pending (read-only while earlier phase is rolling out) assert.Equal(t, ocv1.PhaseStatusPending, cos.Status.ObservedPhases[0].Status) // ActionUpdated+paused: Present; ActionRecovered+paused: Present; ActionCreated+paused: nothing - assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(3)), Present: ptr.To(int64(2)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0))}, cos.Status.ObjectCounts) + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(3)), Present: ptr.To(int64(2)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}, cos.Status.ObjectCounts) }) t.Run("phase with paused objects from blocked preceding phase reports Pending", func(t *testing.T) { @@ -355,7 +387,7 @@ func TestUpdateObservedPhasesForReconcile(t *testing.T) { require.Len(t, cos.Status.ObservedPhases, 2) assert.Equal(t, ocv1.PhaseStatusPending, cos.Status.ObservedPhases[1].Status) // p1: Total2,Present2,Synced2,Ready2 — p2: Total3,Present2,Synced1,Ready1 - assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(5)), Present: ptr.To(int64(4)), Synced: ptr.To(int64(3)), Ready: ptr.To(int64(3))}, cos.Status.ObjectCounts) + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(5)), Present: ptr.To(int64(4)), Synced: ptr.To(int64(3)), Ready: ptr.To(int64(3)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}, cos.Status.ObjectCounts) assert.Len(t, cos.Status.ObservedPhases[1].ObjectDetails, 2) }) @@ -393,6 +425,8 @@ func TestUpdateObservedPhasesForReconcile(t *testing.T) { UpdateObservedPhasesForReconcile(testMapper, &cos, result, now) assert.Equal(t, ocv1.PhaseStatusSuperseded, cos.Status.ObservedPhases[0].Status) assert.Empty(t, cos.Status.ObservedPhases[0].ObjectDetails) + // Objects adopted by a newer revision count as Present and Superseded, but not Synced. + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(2)), Present: ptr.To(int64(2)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0)), Superseded: ptr.To(int64(2)), Colliding: ptr.To(int64(0))}, cos.Status.ObjectCounts) }) t.Run("Stabilizing phase populates objectDetails", func(t *testing.T) { @@ -430,6 +464,7 @@ func TestUpdateObservedPhasesForReconcile(t *testing.T) { UpdateObservedPhasesForReconcile(testMapper, &cos, result, now) assert.Equal(t, ocv1.PhaseStatusReconciling, cos.Status.ObservedPhases[0].Status) assert.Len(t, cos.Status.ObservedPhases[0].ObjectDetails, 1) + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(2)), Present: ptr.To(int64(2)), Synced: ptr.To(int64(1)), Ready: ptr.To(int64(0)), Superseded: ptr.To(int64(1)), Colliding: ptr.To(int64(0))}, cos.Status.ObjectCounts) }) t.Run("ActionProgressed objects are excluded from objectDetails", func(t *testing.T) { @@ -476,7 +511,7 @@ func TestUpdateObservedPhasesForReconcile(t *testing.T) { } UpdateObservedPhasesForReconcile(testMapper, &cos, result, now) // p1: Total=2,Present=2,Synced=2,Ready=2 — p2: Total=3,Present=1,Synced=1,Ready=0 - assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(5)), Present: ptr.To(int64(3)), Synced: ptr.To(int64(3)), Ready: ptr.To(int64(2))}, cos.Status.ObjectCounts) + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(5)), Present: ptr.To(int64(3)), Synced: ptr.To(int64(3)), Ready: ptr.To(int64(2)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}, cos.Status.ObjectCounts) }) } @@ -499,7 +534,7 @@ func TestUpdateObservedPhasesForTeardown(t *testing.T) { phase := cos.Status.ObservedPhases[0] assert.Equal(t, ocv1.PhaseStatusArchiving, phase.Status) assert.Equal(t, "removing all phase objects owned by this object set", phase.Message) - assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(3)), Present: ptr.To(int64(2)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0))}, cos.Status.ObjectCounts) + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(3)), Present: ptr.To(int64(2)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}, cos.Status.ObjectCounts) assert.Len(t, phase.ObjectDetails, 2) }) @@ -545,7 +580,7 @@ func TestUpdateObservedPhasesForTeardown(t *testing.T) { require.Len(t, cos.Status.ObservedPhases, 1) phase := cos.Status.ObservedPhases[0] assert.Equal(t, ocv1.PhaseStatusArchived, phase.Status) - assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(5)), Present: ptr.To(int64(0)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0))}, cos.Status.ObjectCounts) + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(5)), Present: ptr.To(int64(0)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}, cos.Status.ObjectCounts) assert.Empty(t, phase.ObjectDetails) }) @@ -595,7 +630,7 @@ func TestUpdateObservedPhasesForTeardown(t *testing.T) { assert.Empty(t, phases[2].ObjectDetails) // aggregate - assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(9)), Present: ptr.To(int64(4)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0))}, cos.Status.ObjectCounts) + assert.Equal(t, ocv1.ObjectCounts{Total: ptr.To(int64(9)), Present: ptr.To(int64(4)), Synced: ptr.To(int64(0)), Ready: ptr.To(int64(0)), Superseded: ptr.To(int64(0)), Colliding: ptr.To(int64(0))}, cos.Status.ObjectCounts) }) t.Run("phase absent from GetPhases retains its previous status", func(t *testing.T) { diff --git a/manifests/experimental-e2e.yaml b/manifests/experimental-e2e.yaml index 2a46fc9cdf..d6027b5bae 100644 --- a/manifests/experimental-e2e.yaml +++ b/manifests/experimental-e2e.yaml @@ -2818,6 +2818,16 @@ spec: It is omitted until counts have been computed; when present, all count fields are reported (including zeros). properties: + colliding: + description: |- + colliding is the number of objects in this object set whose adoption is + refused by the configured collision protection policy. The conflicting + resources exist on the cluster but do not count as present, synced, or + superseded. Set to zero during teardown. + format: int64 + maximum: 1000 + minimum: 0 + type: integer present: description: |- present is the number of objects in this object set that exist on the @@ -2836,6 +2846,17 @@ spec: maximum: 1000 minimum: 0 type: integer + superseded: + description: |- + superseded is the number of objects in this object set that are observed + under the control of another object set in the same group with a higher + revision. These objects also count as present, but not as synced. This + describes observed ownership, not a cumulative count of transfers. + Set to zero during teardown. + format: int64 + maximum: 1000 + minimum: 0 + type: integer synced: description: |- synced is the number of objects in this object set whose cluster state @@ -2851,8 +2872,10 @@ spec: minimum: 0 type: integer required: + - colliding - present - ready + - superseded - synced - total type: object diff --git a/manifests/experimental.yaml b/manifests/experimental.yaml index 41381a93f0..edbc401783 100644 --- a/manifests/experimental.yaml +++ b/manifests/experimental.yaml @@ -2779,6 +2779,16 @@ spec: It is omitted until counts have been computed; when present, all count fields are reported (including zeros). properties: + colliding: + description: |- + colliding is the number of objects in this object set whose adoption is + refused by the configured collision protection policy. The conflicting + resources exist on the cluster but do not count as present, synced, or + superseded. Set to zero during teardown. + format: int64 + maximum: 1000 + minimum: 0 + type: integer present: description: |- present is the number of objects in this object set that exist on the @@ -2797,6 +2807,17 @@ spec: maximum: 1000 minimum: 0 type: integer + superseded: + description: |- + superseded is the number of objects in this object set that are observed + under the control of another object set in the same group with a higher + revision. These objects also count as present, but not as synced. This + describes observed ownership, not a cumulative count of transfers. + Set to zero during teardown. + format: int64 + maximum: 1000 + minimum: 0 + type: integer synced: description: |- synced is the number of objects in this object set whose cluster state @@ -2812,8 +2833,10 @@ spec: minimum: 0 type: integer required: + - colliding - present - ready + - superseded - synced - total type: object diff --git a/test/e2e/object-controller/features/cod_handoff.feature b/test/e2e/object-controller/features/cod_handoff.feature index 90da51aec3..de92924d73 100644 --- a/test/e2e/object-controller/features/cod_handoff.feature +++ b/test/e2e/object-controller/features/cod_handoff.feature @@ -100,9 +100,14 @@ Feature: ClusterObjectDeployment multi-revision handoff spec: lifecycleState: Active """ + # The successor has adopted the shared object (superseding the predecessor's + # claim to it) and is refused the pre-existing blocking object. + And ClusterObjectSet "${NAME}-1" reports aggregate object counts: total=1, present=1, synced=0, ready=1, superseded=1, colliding=0 + And ClusterObjectSet "${NAME}-2" reports aggregate object counts: total=2, present=1, synced=1, ready=1, superseded=0, colliding=1 # Unblock: remove the conflicting object so the successor can adopt its objects. When resource "configmap/cod-block-cm" is removed Then ClusterObjectSet "${NAME}-2" reports Ready as True with Reason AllObjectsReady + And ClusterObjectSet "${NAME}-2" reports aggregate object counts: total=2, present=2, synced=2, ready=2, superseded=0, colliding=0 And ClusterObjectSet "${NAME}-1" is archived And resource "configmap/cod-shared-cm" keeps its UID diff --git a/test/e2e/object-controller/features/cos_object_collision_and_adoption.feature b/test/e2e/object-controller/features/cos_object_collision_and_adoption.feature index c15c72e879..3cd90fe6ea 100644 --- a/test/e2e/object-controller/features/cos_object_collision_and_adoption.feature +++ b/test/e2e/object-controller/features/cos_object_collision_and_adoption.feature @@ -53,6 +53,7 @@ Feature: ClusterObjectSet object collision and adoption """ Cannot take ownership of 1 object(s) in phase "resources" because they are owned by another controller or already exist. """ + And ClusterObjectSet "${COS_NAME}" reports aggregate object counts: total=1, present=0, synced=0, ready=0, superseded=0, colliding=1 And resource "configmap/shared-cm" matches """ data: diff --git a/test/e2e/object-controller/features/cos_object_lifecycle.feature b/test/e2e/object-controller/features/cos_object_lifecycle.feature index c6f9bd2429..01f2f10d60 100644 --- a/test/e2e/object-controller/features/cos_object_lifecycle.feature +++ b/test/e2e/object-controller/features/cos_object_lifecycle.feature @@ -76,7 +76,7 @@ Feature: Standalone ClusterObjectSet object lifecycle data: value: unchanged """ - And ClusterObjectSet "${NAME}-2" reports aggregate object counts: total=1, present=1, synced=1, ready=1 + And ClusterObjectSet "${NAME}-2" reports aggregate object counts: total=1, present=1, synced=1, ready=1, superseded=0, colliding=0 Scenario: Later phases stay blocked across reconciles until each earlier probe passes When ClusterObjectSet is applied @@ -171,4 +171,4 @@ Feature: Standalone ClusterObjectSet object lifecycle | ready | true | Then ClusterObjectSet "${COS_NAME}" reports Ready as True with Reason AllObjectsReady And resource "configmap/third" is installed - And ClusterObjectSet "${COS_NAME}" reports aggregate object counts: total=3, present=3, synced=3, ready=3 + And ClusterObjectSet "${COS_NAME}" reports aggregate object counts: total=3, present=3, synced=3, ready=3, superseded=0, colliding=0 diff --git a/test/e2e/object-controller/features/revision.feature b/test/e2e/object-controller/features/revision.feature index acb76a323d..fe02e12f7e 100644 --- a/test/e2e/object-controller/features/revision.feature +++ b/test/e2e/object-controller/features/revision.feature @@ -759,6 +759,6 @@ Feature: Install ClusterObjectSet revision: 1 """ Then resource "deployment/test-deployment" is installed - And ClusterObjectSet "${COS_NAME}" reports aggregate object counts: total=2, present=1, synced=1, ready=0 + And ClusterObjectSet "${COS_NAME}" reports aggregate object counts: total=2, present=1, synced=1, ready=0, superseded=0, colliding=0 And ClusterObjectSet "${COS_NAME}" reports Ready as True with Reason AllObjectsReady - And ClusterObjectSet "${COS_NAME}" reports aggregate object counts: total=2, present=2, synced=2, ready=2 + And ClusterObjectSet "${COS_NAME}" reports aggregate object counts: total=2, present=2, synced=2, ready=2, superseded=0, colliding=0 diff --git a/test/internal/e2e/object-controller/steps/steps.go b/test/internal/e2e/object-controller/steps/steps.go index b08b4baa6e..939c26ba07 100644 --- a/test/internal/e2e/object-controller/steps/steps.go +++ b/test/internal/e2e/object-controller/steps/steps.go @@ -39,7 +39,7 @@ func RegisterSteps(sc *godog.ScenarioContext) { sc.Step(`^(?i)ClusterObjectSet "([^"]+)" has observed phase "([^"]+)" with a non-empty digest$`, ClusterObjectSetHasObservedPhase) sc.Step(`^(?i)ClusterObjectSet "([^"]+)" is archived$`, ClusterObjectSetIsArchived) sc.Step(`^(?i)ClusterObjectSet "([^"]+)" is eventually deleted$`, ClusterObjectSetIsEventuallyDeleted) - sc.Step(`^(?i)ClusterObjectSet "([^"]+)" reports aggregate object counts: total=(\d+), present=(\d+), synced=(\d+), ready=(\d+)$`, ClusterObjectSetHasAggregateObjectCounts) + sc.Step(`^(?i)ClusterObjectSet "([^"]+)" reports aggregate object counts: total=(\d+), present=(\d+), synced=(\d+), ready=(\d+), superseded=(\d+), colliding=(\d+)$`, ClusterObjectSetHasAggregateObjectCounts) sc.Step(`^(?i)ClusterObjectSet "([^"]+)" contains annotation "([^"]+)" with value$`, ClusterObjectSetHasAnnotationWithValue) sc.Step(`^(?i)ClusterObjectSet "([^"]+)" has label "([^"]+)" with value "([^"]+)"$`, ClusterObjectSetHasLabelWithValue) sc.Step(`^(?i)ClusterObjectSet "([^"]+)" has group "([^"]+)"$`, ClusterObjectSetHasGroup) @@ -174,7 +174,7 @@ func ClusterObjectDeploymentReportsConditionWithoutMsg(ctx context.Context, name // ClusterObjectSetHasAggregateObjectCounts waits for the named ClusterObjectSet to report exact // aggregate object counts (summed across all phases). Polls with timeout. -func ClusterObjectSetHasAggregateObjectCounts(ctx context.Context, cosName string, total, present, synced, ready int64) error { +func ClusterObjectSetHasAggregateObjectCounts(ctx context.Context, cosName string, total, present, synced, ready, superseded, colliding int64) error { sc := shared.Scenario(ctx) cosName = shared.SubstituteScenarioVars(cosName, sc) shared.WaitFor(ctx, func() bool { @@ -189,7 +189,9 @@ func ClusterObjectSetHasAggregateObjectCounts(ctx context.Context, cosName strin return ptr.Deref(cos.Status.ObjectCounts.Total, -1) == total && ptr.Deref(cos.Status.ObjectCounts.Present, -1) == present && ptr.Deref(cos.Status.ObjectCounts.Synced, -1) == synced && - ptr.Deref(cos.Status.ObjectCounts.Ready, -1) == ready + ptr.Deref(cos.Status.ObjectCounts.Ready, -1) == ready && + ptr.Deref(cos.Status.ObjectCounts.Superseded, -1) == superseded && + ptr.Deref(cos.Status.ObjectCounts.Colliding, -1) == colliding }) return nil }