diff --git a/pkg/addon/webhook/v1beta1/managedclusteraddon_conversion.go b/pkg/addon/webhook/v1beta1/managedclusteraddon_conversion.go index b5c1553fd..11d4cb577 100644 --- a/pkg/addon/webhook/v1beta1/managedclusteraddon_conversion.go +++ b/pkg/addon/webhook/v1beta1/managedclusteraddon_conversion.go @@ -48,6 +48,9 @@ func (src *ManagedClusterAddOn) ConvertTo(dstRaw conversion.Hub) error { // This field was removed in v1beta1, so we store it in annotation if installNs, ok := src.Annotations[InstallNamespaceAnnotation]; ok { v1alpha1Obj.Spec.InstallNamespace = installNs + // Remove the internal annotation from v1alpha1 object + // This annotation is only used for v1beta1 storage, not for v1alpha1 API + delete(v1alpha1Obj.Annotations, InstallNamespaceAnnotation) } // Manually populate deprecated ConfigReferent field in ConfigReferences diff --git a/pkg/addon/webhook/v1beta1/managedclusteraddon_conversion_test.go b/pkg/addon/webhook/v1beta1/managedclusteraddon_conversion_test.go index c0faa87a9..2a8a6efaa 100644 --- a/pkg/addon/webhook/v1beta1/managedclusteraddon_conversion_test.go +++ b/pkg/addon/webhook/v1beta1/managedclusteraddon_conversion_test.go @@ -106,9 +106,8 @@ func TestManagedClusterAddOnConvertTo(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "test-addon", Namespace: "cluster1", - Annotations: map[string]string{ - "addon.open-cluster-management.io/v1alpha1-install-namespace": "test-namespace", - }, + // The internal annotation should be removed after conversion to v1alpha1 + Annotations: map[string]string{}, }, Spec: addonv1alpha1.ManagedClusterAddOnSpec{ InstallNamespace: "test-namespace", @@ -178,6 +177,43 @@ func TestManagedClusterAddOnConvertTo(t *testing.T) { }, }, }, + { + name: "conversion removes internal annotation but preserves user annotations", + src: &ManagedClusterAddOn{ + ManagedClusterAddOn: addonv1beta1.ManagedClusterAddOn{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-addon", + Namespace: "cluster1", + Annotations: map[string]string{ + "addon.open-cluster-management.io/v1alpha1-install-namespace": "test-namespace", + "abc.def": "hahaha", + "user.annotation": "should-be-preserved", + }, + }, + Spec: addonv1beta1.ManagedClusterAddOnSpec{}, + }, + }, + expected: &internalv1alpha1.ManagedClusterAddOn{ + ManagedClusterAddOn: addonv1alpha1.ManagedClusterAddOn{ + TypeMeta: metav1.TypeMeta{ + Kind: "ManagedClusterAddOn", + APIVersion: "addon.open-cluster-management.io/v1alpha1", + }, + ObjectMeta: metav1.ObjectMeta{ + Name: "test-addon", + Namespace: "cluster1", + // Internal annotation removed, user annotations preserved + Annotations: map[string]string{ + "abc.def": "hahaha", + "user.annotation": "should-be-preserved", + }, + }, + Spec: addonv1alpha1.ManagedClusterAddOnSpec{ + InstallNamespace: "test-namespace", + }, + }, + }, + }, } for _, tc := range cases {