From 0145ee010f57c7541fe20ac3a1d6735d43e5964a Mon Sep 17 00:00:00 2001 From: liranmauda Date: Thu, 12 May 2022 16:46:39 +0300 Subject: [PATCH] when there is no secretRef.Namespace adding it from the backingstore or namespacestore when there is no secretRef.Namespace adding it from the backingstore or namespacestore Signed-off-by: liranmauda --- pkg/backingstore/reconciler.go | 4 ---- pkg/util/util.go | 31 +++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/pkg/backingstore/reconciler.go b/pkg/backingstore/reconciler.go index 798a2fab6a..36138b030d 100644 --- a/pkg/backingstore/reconciler.go +++ b/pkg/backingstore/reconciler.go @@ -267,10 +267,6 @@ func (r *Reconciler) LoadBackingStoreSecret() error { r.Secret.Name = secretRef.Name r.Secret.Namespace = secretRef.Namespace - if r.Secret.Namespace == "" { - r.Secret.Namespace = r.BackingStore.Namespace - } - if r.Secret.Name == "" { if r.BackingStore.Spec.Type != nbv1.StoreTypePVPool { return util.NewPersistentError("EmptySecretName", diff --git a/pkg/util/util.go b/pkg/util/util.go index fe441d40d4..51fd59b3f3 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -1643,22 +1643,28 @@ func GetAvailabeKubeCli() string { // GetBackingStoreSecret returns the secret reference of the backing store if it is relevant to the type func GetBackingStoreSecret(bs *nbv1.BackingStore) (*corev1.SecretReference, error) { + var secretRef corev1.SecretReference switch bs.Spec.Type { case nbv1.StoreTypeAWSS3: - return &bs.Spec.AWSS3.Secret, nil + secretRef = bs.Spec.AWSS3.Secret case nbv1.StoreTypeS3Compatible: - return &bs.Spec.S3Compatible.Secret, nil + secretRef = bs.Spec.S3Compatible.Secret case nbv1.StoreTypeIBMCos: - return &bs.Spec.IBMCos.Secret, nil + secretRef = bs.Spec.IBMCos.Secret case nbv1.StoreTypeAzureBlob: - return &bs.Spec.AzureBlob.Secret, nil + secretRef = bs.Spec.AzureBlob.Secret case nbv1.StoreTypeGoogleCloudStorage: - return &bs.Spec.GoogleCloudStorage.Secret, nil + secretRef = bs.Spec.GoogleCloudStorage.Secret case nbv1.StoreTypePVPool: - return &bs.Spec.PVPool.Secret, nil + secretRef = bs.Spec.PVPool.Secret default: return nil, fmt.Errorf("failed to get secret reference from backingstore %q", bs.Name) } + + if secretRef.Namespace == "" { + secretRef.Namespace = bs.Namespace + } + return &secretRef, nil } // SetBackingStoreSecretRef setting a backingstore secret reference to the provided one @@ -1709,20 +1715,25 @@ func GetBackingStoreTargetBucket(bs *nbv1.BackingStore) (string, error) { // GetNamespaceStoreSecret returns the secret reference of the namespace store if it is relevant to the type func GetNamespaceStoreSecret(ns *nbv1.NamespaceStore) (*corev1.SecretReference, error) { + var secretRef corev1.SecretReference switch ns.Spec.Type { case nbv1.NSStoreTypeAWSS3: - return &ns.Spec.AWSS3.Secret, nil + secretRef = ns.Spec.AWSS3.Secret case nbv1.NSStoreTypeS3Compatible: - return &ns.Spec.S3Compatible.Secret, nil + secretRef = ns.Spec.S3Compatible.Secret case nbv1.NSStoreTypeIBMCos: - return &ns.Spec.IBMCos.Secret, nil + secretRef = ns.Spec.IBMCos.Secret case nbv1.NSStoreTypeAzureBlob: - return &ns.Spec.AzureBlob.Secret, nil + secretRef = ns.Spec.AzureBlob.Secret case nbv1.NSStoreTypeNSFS: return nil, nil default: return nil, fmt.Errorf("failed to get namespacestore %q secret", ns.Name) } + if secretRef.Namespace == "" { + secretRef.Namespace = ns.Namespace + } + return &secretRef, nil } // SetNamespaceStoreSecretRef setting a namespacestore secret reference to the provided one