Skip to content

Commit 5bbbf3e

Browse files
(fix):ClusterExtensionRevision had inconsistent owner labeling and confusing code.
1 parent 6ef62de commit 5bbbf3e

5 files changed

Lines changed: 25 additions & 27 deletions

File tree

internal/operator-controller/applier/boxcutter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (r *SimpleRevisionGenerator) buildClusterExtensionRevision(
183183
ObjectMeta: metav1.ObjectMeta{
184184
Annotations: annotations,
185185
Labels: map[string]string{
186-
controllers.ClusterExtensionRevisionOwnerLabel: ext.Name,
186+
labels.OwnerNameKey: ext.Name,
187187
},
188188
},
189189
Spec: ocv1.ClusterExtensionRevisionSpec{

internal/operator-controller/applier/boxcutter_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func Test_SimpleRevisionGenerator_GenerateRevisionFromHelmRelease(t *testing.T)
8686
"olm.operatorframework.io/package-name": "my-package",
8787
},
8888
Labels: map[string]string{
89-
"olm.operatorframework.io/owner": "test-123",
89+
"olm.operatorframework.io/owner-name": "test-123",
9090
},
9191
},
9292
Spec: ocv1.ClusterExtensionRevisionSpec{
@@ -178,9 +178,9 @@ func Test_SimpleRevisionGenerator_GenerateRevision(t *testing.T) {
178178
rev, err := b.GenerateRevision(t.Context(), fstest.MapFS{}, ext, map[string]string{}, map[string]string{})
179179
require.NoError(t, err)
180180

181-
t.Log("by checking the olm.operatorframework.io/owner label is set to the name of the ClusterExtension")
181+
t.Log("by checking the owner label is set correctly (owner-name)")
182182
require.Equal(t, map[string]string{
183-
controllers.ClusterExtensionRevisionOwnerLabel: "test-extension",
183+
labels.OwnerNameKey: "test-extension",
184184
}, rev.Labels)
185185
t.Log("by checking the revision number is 0")
186186
require.Equal(t, int64(0), rev.Spec.Revision)
@@ -288,13 +288,13 @@ func Test_SimpleRevisionGenerator_AppliesObjectLabelsAndRevisionAnnotations(t *t
288288
ManifestProvider: r,
289289
}
290290

291-
revAnnotations := map[string]string{
291+
revisionAnnotations := map[string]string{
292292
"other": "value",
293293
}
294294

295295
rev, err := b.GenerateRevision(t.Context(), fstest.MapFS{}, &ocv1.ClusterExtension{}, map[string]string{
296296
"some": "value",
297-
}, revAnnotations)
297+
}, revisionAnnotations)
298298
require.NoError(t, err)
299299
t.Log("by checking the rendered objects contain the given object labels")
300300
for _, phase := range rev.Spec.Phases {
@@ -305,8 +305,8 @@ func Test_SimpleRevisionGenerator_AppliesObjectLabelsAndRevisionAnnotations(t *t
305305
}, revObj.Object.GetLabels())
306306
}
307307
}
308-
t.Log("by checking the generated revision contain the given annotations")
309-
require.Equal(t, revAnnotations, rev.Annotations)
308+
t.Log("by checking the generated revision contains the given annotations")
309+
require.Equal(t, revisionAnnotations, rev.Annotations)
310310
}
311311

312312
func Test_SimpleRevisionGenerator_Failure(t *testing.T) {
@@ -344,7 +344,7 @@ func TestBoxcutter_Apply(t *testing.T) {
344344
Name: "test-ext-1",
345345
UID: "rev-uid-1",
346346
Labels: map[string]string{
347-
controllers.ClusterExtensionRevisionOwnerLabel: ext.Name,
347+
labels.OwnerNameKey: ext.Name,
348348
},
349349
},
350350
Spec: ocv1.ClusterExtensionRevisionSpec{
@@ -400,10 +400,10 @@ func TestBoxcutter_Apply(t *testing.T) {
400400
makeRevisionFunc: func(ctx context.Context, bundleFS fs.FS, ext *ocv1.ClusterExtension, objectLabels, revisionAnnotations map[string]string) (*ocv1.ClusterExtensionRevision, error) {
401401
return &ocv1.ClusterExtensionRevision{
402402
ObjectMeta: metav1.ObjectMeta{
403-
Annotations: revisionAnnotations,
404403
Labels: map[string]string{
405-
controllers.ClusterExtensionRevisionOwnerLabel: ext.Name,
404+
labels.OwnerNameKey: ext.Name,
406405
},
406+
Annotations: revisionAnnotations,
407407
},
408408
Spec: ocv1.ClusterExtensionRevisionSpec{
409409
Phases: []ocv1.ClusterExtensionRevisionPhase{
@@ -787,15 +787,15 @@ func TestBoxcutter_Apply(t *testing.T) {
787787
},
788788
},
789789
{
790-
name: "annotation-only update (same phases, different annotations)",
790+
name: "annotation update (same phases, different metadata)",
791791
mockBuilder: &mockBundleRevisionBuilder{
792792
makeRevisionFunc: func(ctx context.Context, bundleFS fs.FS, ext *ocv1.ClusterExtension, objectLabels, revisionAnnotations map[string]string) (*ocv1.ClusterExtensionRevision, error) {
793793
return &ocv1.ClusterExtensionRevision{
794794
ObjectMeta: metav1.ObjectMeta{
795-
Annotations: revisionAnnotations,
796795
Labels: map[string]string{
797-
controllers.ClusterExtensionRevisionOwnerLabel: ext.Name,
796+
labels.OwnerNameKey: ext.Name,
798797
},
798+
Annotations: revisionAnnotations,
799799
},
800800
Spec: ocv1.ClusterExtensionRevisionSpec{
801801
Phases: []ocv1.ClusterExtensionRevisionPhase{
@@ -830,7 +830,7 @@ func TestBoxcutter_Apply(t *testing.T) {
830830
labels.PackageNameKey: "test-package",
831831
},
832832
Labels: map[string]string{
833-
controllers.ClusterExtensionRevisionOwnerLabel: ext.Name,
833+
labels.OwnerNameKey: ext.Name,
834834
},
835835
},
836836
Spec: ocv1.ClusterExtensionRevisionSpec{
@@ -870,7 +870,7 @@ func TestBoxcutter_Apply(t *testing.T) {
870870
assert.Equal(t, "1.0.1", rev.Annotations[labels.BundleVersionKey])
871871
assert.Equal(t, "test-package", rev.Annotations[labels.PackageNameKey])
872872
// Verify owner label is still present
873-
assert.Equal(t, ext.Name, rev.Labels[controllers.ClusterExtensionRevisionOwnerLabel])
873+
assert.Equal(t, ext.Name, rev.Labels[labels.OwnerNameKey])
874874
},
875875
},
876876
}
@@ -896,8 +896,8 @@ func TestBoxcutter_Apply(t *testing.T) {
896896

897897
// Execute
898898
revisionAnnotations := map[string]string{}
899-
if tc.name == "annotation-only update (same phases, different annotations)" {
900-
// For annotation-only update test, pass NEW annotations
899+
if tc.name == "annotation update (same phases, different metadata)" {
900+
// For annotation update test, pass NEW metadata in annotations
901901
revisionAnnotations = map[string]string{
902902
labels.BundleVersionKey: "1.0.1",
903903
labels.PackageNameKey: "test-package",
@@ -1045,7 +1045,7 @@ func TestBoxcutterStorageMigrator(t *testing.T) {
10451045

10461046
// mockBundleRevisionBuilder is a mock implementation of the ClusterExtensionRevisionGenerator for testing.
10471047
type mockBundleRevisionBuilder struct {
1048-
makeRevisionFunc func(ctx context.Context, bundleFS fs.FS, ext *ocv1.ClusterExtension, objectLabels, revisionAnnotation map[string]string) (*ocv1.ClusterExtensionRevision, error)
1048+
makeRevisionFunc func(ctx context.Context, bundleFS fs.FS, ext *ocv1.ClusterExtension, objectLabels, revisionAnnotations map[string]string) (*ocv1.ClusterExtensionRevision, error)
10491049
}
10501050

10511051
func (m *mockBundleRevisionBuilder) GenerateRevision(ctx context.Context, bundleFS fs.FS, ext *ocv1.ClusterExtension, objectLabels, revisionAnnotations map[string]string) (*ocv1.ClusterExtensionRevision, error) {
@@ -1061,7 +1061,7 @@ func (m *mockBundleRevisionBuilder) GenerateRevisionFromHelmRelease(
10611061
ObjectMeta: metav1.ObjectMeta{
10621062
Name: "test-revision",
10631063
Labels: map[string]string{
1064-
controllers.ClusterExtensionRevisionOwnerLabel: ext.Name,
1064+
labels.OwnerNameKey: ext.Name,
10651065
},
10661066
},
10671067
Spec: ocv1.ClusterExtensionRevisionSpec{},

internal/operator-controller/applier/helm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (h *Helm) runPreAuthorizationChecks(ctx context.Context, ext *ocv1.ClusterE
102102
return nil
103103
}
104104

105-
func (h *Helm) Apply(ctx context.Context, contentFS fs.FS, ext *ocv1.ClusterExtension, objectLabels map[string]string, storageLabels map[string]string) (bool, string, error) {
105+
func (h *Helm) Apply(ctx context.Context, contentFS fs.FS, ext *ocv1.ClusterExtension, objectLabels, storageLabels map[string]string) (bool, string, error) {
106106
chrt, err := h.buildHelmChart(contentFS, ext)
107107
if err != nil {
108108
return false, "", err

internal/operator-controller/controllers/clusterextension_controller.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1.Cl
280280
return ctrl.Result{}, err
281281
}
282282

283-
storeLbls := map[string]string{
283+
revisionAnnotations := map[string]string{
284284
labels.BundleNameKey: resolvedRevisionMetadata.Name,
285285
labels.PackageNameKey: resolvedRevisionMetadata.Package,
286286
labels.BundleVersionKey: resolvedRevisionMetadata.Version,
@@ -297,7 +297,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1.Cl
297297
// to ensure exponential backoff can occur:
298298
// - Permission errors (it is not possible to watch changes to permissions.
299299
// The only way to eventually recover from permission errors is to keep retrying).
300-
rolloutSucceeded, rolloutStatus, err := r.Applier.Apply(ctx, imageFS, ext, objLbls, storeLbls)
300+
rolloutSucceeded, rolloutStatus, err := r.Applier.Apply(ctx, imageFS, ext, objLbls, revisionAnnotations)
301301

302302
// Set installed status
303303
if rolloutSucceeded {
@@ -549,9 +549,7 @@ func (d *BoxcutterRevisionStatesGetter) GetRevisionStates(ctx context.Context, e
549549
continue
550550
}
551551

552-
// TODO: the setting of these annotations (happens in boxcutter applier when we pass in "revisionAnnotations")
553-
// is fairly decoupled from this code where we get the annotations back out. We may want to co-locate
554-
// the set/get logic a bit better to make it more maintainable and less likely to get out of sync.
552+
// Read bundle metadata from annotations (informational, not queried)
555553
rm := &RevisionMetadata{
556554
Package: rev.Annotations[labels.PackageNameKey],
557555
Image: rev.Annotations[labels.BundleReferenceKey],

internal/operator-controller/controllers/clusterextensionrevision_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
)
3737

3838
const (
39-
ClusterExtensionRevisionOwnerLabel = "olm.operatorframework.io/owner"
39+
ClusterExtensionRevisionOwnerLabel = "olm.operatorframework.io/owner-name"
4040
clusterExtensionRevisionTeardownFinalizer = "olm.operatorframework.io/teardown"
4141
)
4242

0 commit comments

Comments
 (0)