Skip to content

Commit

Permalink
when there is no secretRef.Namespace adding it from the backingstore …
Browse files Browse the repository at this point in the history
…or namespacestore

when there is no secretRef.Namespace adding it from the backingstore or namespacestore

Signed-off-by: liranmauda <liran.mauda@gmail.com>
  • Loading branch information
liranmauda committed May 12, 2022
1 parent cdb9f8f commit 0145ee0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
4 changes: 0 additions & 4 deletions pkg/backingstore/reconciler.go
Expand Up @@ -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",
Expand Down
31 changes: 21 additions & 10 deletions pkg/util/util.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0145ee0

Please sign in to comment.