Read namespce from status at first to build config (#308)

Signed-off-by: Jian Qiu <jqiu@redhat.com>
This commit is contained in:
Jian Qiu
2023-04-04 15:13:36 +08:00
committed by GitHub
parent 261bb16b70
commit ad1bef9153
2 changed files with 26 additions and 2 deletions

View File

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

View File

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