fix(addon): remove internal annotation from v1alpha1 after conversion (#1321)

When converting ManagedClusterAddOn from v1beta1 to v1alpha1, the
internal annotation 'addon.open-cluster-management.io/v1alpha1-install-namespace'
should be removed after being converted to Spec.InstallNamespace field.

This annotation is only used internally for v1beta1 storage to preserve
the InstallNamespace field which was removed in v1beta1. It should not
appear in v1alpha1 API responses.

Fixes: ACM-28133

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Qing Hao <qhao@redhat.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Qing Hao
2026-01-09 09:34:23 +08:00
committed by GitHub
parent ad89f05351
commit c6aa931619
2 changed files with 42 additions and 3 deletions

View File

@@ -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

View File

@@ -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 {