diff --git a/pkg/spoke/addon/configuration.go b/pkg/spoke/addon/configuration.go index da8405403..4da79b573 100644 --- a/pkg/spoke/addon/configuration.go +++ b/pkg/spoke/addon/configuration.go @@ -59,10 +59,13 @@ func (c *registrationConfig) x509Subject(clusterName, agentName string) *pkix.Na } // getAddOnInstallationNamespace returns addon installation namespace from addon spec. -// If the installation namespace is not specified on addon spec, the addon default +// It first checks the installation namespace in status then addon spec, the addon default // installation namespace open-cluster-management-agent-addon will be returned. func getAddOnInstallationNamespace(addOn *addonv1alpha1.ManagedClusterAddOn) string { - installationNamespace := addOn.Spec.InstallNamespace + installationNamespace := addOn.Status.Namespace + if installationNamespace == "" { + installationNamespace = addOn.Spec.InstallNamespace + } if installationNamespace == "" { installationNamespace = defaultAddOnInstallationNamespace } diff --git a/pkg/spoke/addon/configuration_test.go b/pkg/spoke/addon/configuration_test.go index f445e1e8d..f57705598 100644 --- a/pkg/spoke/addon/configuration_test.go +++ b/pkg/spoke/addon/configuration_test.go @@ -52,6 +52,27 @@ func TestGetRegistrationConfigs(t *testing.T) { newRegistrationConfig(addOnName, addOnNamespace, "kubernetes.io/kube-apiserver-client", "", nil, false), }, }, + { + name: "namespace in status", + addon: &addonv1alpha1.ManagedClusterAddOn{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: testinghelpers.TestManagedClusterName, + Name: addOnName, + }, + Spec: addonv1alpha1.ManagedClusterAddOnSpec{}, + Status: addonv1alpha1.ManagedClusterAddOnStatus{ + Registrations: []addonv1alpha1.RegistrationConfig{ + { + SignerName: "kubernetes.io/kube-apiserver-client", + }, + }, + Namespace: addOnNamespace, + }, + }, + configs: []registrationConfig{ + newRegistrationConfig(addOnName, addOnNamespace, "kubernetes.io/kube-apiserver-client", "", nil, false), + }, + }, { name: "with default signer hosted mode", addon: &addonv1alpha1.ManagedClusterAddOn{