Skip to content

Commit 8eb6722

Browse files
pedjakclaude
andcommitted
Add bundle-version and package-name annotations to CER phase objects
When upgrading between bundle versions that produce identical Kubernetes manifests, the installed version status was not updated because CER phases were identical across versions, causing in-place patches instead of new revision creation. Propagate bundle-version and package-name annotations onto each rendered object within CER phases so that different bundle versions always produce distinct phases, triggering new revision creation via phase immutability. As a side benefit, every applied bundle resource now carries two annotations that immediately tell an observer which package and version it belongs to. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0db26d7 commit 8eb6722

4 files changed

Lines changed: 68 additions & 0 deletions

File tree

internal/operator-controller/applier/boxcutter.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ func (r *SimpleRevisionGenerator) GenerateRevisionFromHelmRelease(
7575
_ = cache.ApplyStripAnnotationsTransform(&obj)
7676
sanitizedUnstructured(ctx, &obj)
7777

78+
obj.SetAnnotations(mergeLabelMaps(obj.GetAnnotations(), map[string]string{
79+
labels.BundleVersionKey: helmRelease.Labels[labels.BundleVersionKey],
80+
labels.PackageNameKey: helmRelease.Labels[labels.PackageNameKey],
81+
}))
82+
7883
objs = append(objs, *ocv1ac.ClusterExtensionRevisionObject().
7984
WithObject(obj))
8085
}
@@ -146,6 +151,11 @@ func (r *SimpleRevisionGenerator) GenerateRevision(
146151
}
147152
sanitizedUnstructured(ctx, &unstr)
148153

154+
unstr.SetAnnotations(mergeLabelMaps(unstr.GetAnnotations(), map[string]string{
155+
labels.BundleVersionKey: revisionAnnotations[labels.BundleVersionKey],
156+
labels.PackageNameKey: revisionAnnotations[labels.PackageNameKey],
157+
}))
158+
149159
objs = append(objs, *ocv1ac.ClusterExtensionRevisionObject().
150160
WithObject(unstr))
151161
}

internal/operator-controller/applier/boxcutter_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ func Test_SimpleRevisionGenerator_GenerateRevisionFromHelmRelease(t *testing.T)
128128
"labels": map[string]interface{}{
129129
"my-label": "my-value",
130130
},
131+
"annotations": map[string]interface{}{
132+
"olm.operatorframework.io/bundle-version": "1.2.0",
133+
"olm.operatorframework.io/package-name": "my-package",
134+
},
131135
},
132136
},
133137
}),
@@ -140,6 +144,10 @@ func Test_SimpleRevisionGenerator_GenerateRevisionFromHelmRelease(t *testing.T)
140144
"labels": map[string]interface{}{
141145
"my-label": "my-value",
142146
},
147+
"annotations": map[string]interface{}{
148+
"olm.operatorframework.io/bundle-version": "1.2.0",
149+
"olm.operatorframework.io/package-name": "my-package",
150+
},
143151
},
144152
},
145153
}),
@@ -223,6 +231,10 @@ func Test_SimpleRevisionGenerator_GenerateRevision(t *testing.T) {
223231
"kind": "Service",
224232
"metadata": map[string]interface{}{
225233
"name": "test-service",
234+
"annotations": map[string]interface{}{
235+
"olm.operatorframework.io/bundle-version": "",
236+
"olm.operatorframework.io/package-name": "",
237+
},
226238
},
227239
"spec": map[string]interface{}{},
228240
},
@@ -244,6 +256,8 @@ func Test_SimpleRevisionGenerator_GenerateRevision(t *testing.T) {
244256
},
245257
"annotations": map[string]interface{}{
246258
"my-annotation": "my-annotation-value",
259+
"olm.operatorframework.io/bundle-version": "",
260+
"olm.operatorframework.io/package-name": "",
247261
},
248262
},
249263
"spec": map[string]interface{}{

test/e2e/features/update.feature

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,36 @@ Feature: Update ClusterExtension
180180
When ClusterCatalog "test" image version "v2" is also tagged as "latest"
181181
Then bundle "test-operator.1.3.0" is installed in version "1.3.0"
182182

183+
@BoxcutterRuntime
184+
Scenario: Update to a version with identical bundle content creates a new revision
185+
Given ClusterExtension is applied
186+
"""
187+
apiVersion: olm.operatorframework.io/v1
188+
kind: ClusterExtension
189+
metadata:
190+
name: ${NAME}
191+
spec:
192+
namespace: ${TEST_NAMESPACE}
193+
serviceAccount:
194+
name: olm-sa
195+
source:
196+
sourceType: Catalog
197+
catalog:
198+
packageName: test
199+
selector:
200+
matchLabels:
201+
"olm.operatorframework.io/metadata.name": test-catalog
202+
version: 1.0.0
203+
upgradeConstraintPolicy: SelfCertified
204+
"""
205+
And ClusterExtension is rolled out
206+
And ClusterExtension is available
207+
And bundle "test-operator.1.0.0" is installed in version "1.0.0"
208+
When ClusterExtension is updated to version "1.0.4"
209+
Then ClusterExtension is rolled out
210+
And ClusterExtension is available
211+
And bundle "test-operator.1.0.4" is installed in version "1.0.4"
212+
183213
@BoxcutterRuntime
184214
Scenario: Each update creates a new revision and resources not present in the new revision are removed from the cluster
185215
Given ClusterExtension is applied

testdata/images/catalogs/test-catalog/v1/configs/catalog.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ entries:
1717
- name: test-operator.1.0.0
1818
- name: test-operator.1.0.1
1919
replaces: test-operator.1.0.0
20+
- name: test-operator.1.0.4
2021
- name: test-operator.1.2.0
2122
replaces: test-operator.1.0.1
2223
---
@@ -40,6 +41,19 @@ properties:
4041
packageName: test
4142
version: 1.0.1
4243
---
44+
# Bundle with identical rendered content as v1.0.0 (same image).
45+
# Used to test that upgrading between versions with identical manifests
46+
# correctly updates the installed version status (OCPBUGS-78311).
47+
schema: olm.bundle
48+
name: test-operator.1.0.4
49+
package: test
50+
image: docker-registry.operator-controller-e2e.svc.cluster.local:5000/bundles/registry-v1/test-operator:v1.0.0
51+
properties:
52+
- type: olm.package
53+
value:
54+
packageName: test
55+
version: 1.0.4
56+
---
4357
# Bundle with a wrong image ref causing image pull failure
4458
schema: olm.bundle
4559
name: test-operator.1.0.2

0 commit comments

Comments
 (0)