From ad1bef9153533ed86fb2c9948fbc6b18109f2272 Mon Sep 17 00:00:00 2001 From: Jian Qiu Date: Tue, 4 Apr 2023 15:13:36 +0800 Subject: [PATCH] Read namespce from status at first to build config (#308) Signed-off-by: Jian Qiu --- pkg/spoke/addon/configuration.go | 7 +++++-- pkg/spoke/addon/configuration_test.go | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) 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{