Skip to content

Commit

Permalink
Fix issue where MCE override annotation not removed (stolostron#1025)
Browse files Browse the repository at this point in the history
When the MCH image repository override annotation is set and then removed
the annotation remained on MCE. This fix makes sure the override is unset.

Signed-off-by: Jakob Gray <[email protected]>
  • Loading branch information
JakobGray authored Apr 28, 2023
1 parent 04833cd commit 453d629
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/multiclusterengine/multiclusterengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ func RenderMultiClusterEngine(existingMCE *mcev1.MultiClusterEngine, m *operator
newAnnotations[key] = val
}
copy.SetAnnotations(newAnnotations)
} else {
RemoveSupportedAnnotations(copy)
}

if m.Spec.AvailabilityConfig == operatorsv1.HABasic {
Expand Down Expand Up @@ -159,6 +161,18 @@ func GetSupportedAnnotations(m *operatorsv1.MultiClusterHub) map[string]string {
return mceAnnotations
}

// RemoveSupportedAnnotations removes annotations relevant to MCE from MCE. If the annotation is
// already present then sets value to empty rather than removing the key
func RemoveSupportedAnnotations(mce *mcev1.MultiClusterEngine) map[string]string {
mceAnnotations := mce.GetAnnotations()
if mceAnnotations != nil {
if _, ok := mceAnnotations["imageRepository"]; ok {
mceAnnotations["imageRepository"] = ""
}
}
return mceAnnotations
}

func Namespace() *corev1.Namespace {
namespace := OperandNameSpace()
return &corev1.Namespace{
Expand Down
9 changes: 9 additions & 0 deletions pkg/multiclusterengine/multiclusterengine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,15 @@ func TestRenderMultiClusterEngine(t *testing.T) {
g.Expect(got.Annotations["imageRepository"]).To(gomega.Equal(mch.Annotations["mch-imageRepository"]), "Override annotations should be updated")
})

// Annotation on MCE but not MCH
existingMCE.Annotations["imageRepository"] = "quay.io"
mch.SetAnnotations(map[string]string{})
got = RenderMultiClusterEngine(existingMCE, mch)
t.Run("Remove override annotation", func(t *testing.T) {
g.Expect(got.Annotations["random"]).To(gomega.Equal(existingMCE.Annotations["random"]), "Unrelated annotations should not be erased")
g.Expect(got.Annotations["imageRepository"]).To(gomega.Equal(""), "Override annotation should be be emptied")
})

}

func Test_filterPackageManifests(t *testing.T) {
Expand Down

0 comments on commit 453d629

Please sign in to comment.