Skip to content

Commit

Permalink
driver will now check if secretObjects is an empty list before perfor…
Browse files Browse the repository at this point in the history
…ming syncAll operations
  • Loading branch information
manedurphy committed Aug 21, 2021
1 parent 5ba6d82 commit f552f0f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
12 changes: 10 additions & 2 deletions controllers/secretproviderclasspodstatus_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ func (r *SecretProviderClassPodStatusReconciler) Patcher(ctx context.Context) er
if err != nil {
klog.ErrorS(err, "failed to get mounted files", "spc", klog.KObj(spc), "pod", klog.KObj(pod), "spcps", klog.KObj(&spcPodStatus))
} else {
spc.Spec.SecretObjects = spcutil.BuildSecretObjects(files, secretutil.GetSecretType(strings.TrimSpace(spc.Spec.SyncOptions.Type)))
if len(spc.Spec.SecretObjects) == 0 {
spc.Spec.SecretObjects = spcutil.BuildSecretObjects(files, secretutil.GetSecretType(strings.TrimSpace(spc.Spec.SyncOptions.Type)))
} else {
spc.Spec.SecretObjects = append(spc.Spec.SecretObjects, spcutil.BuildSecretObjects(files, secretutil.GetSecretType(strings.TrimSpace(spc.Spec.SyncOptions.Type)))...)
}
}
}

Expand Down Expand Up @@ -297,7 +301,11 @@ func (r *SecretProviderClassPodStatusReconciler) Reconcile(ctx context.Context,
files, err := fileutil.GetMountedFiles(spcPodStatus.Status.TargetPath)

if spc.Spec.SyncOptions.SyncAll {
spc.Spec.SecretObjects = spcutil.BuildSecretObjects(files, secretutil.GetSecretType(strings.TrimSpace(spc.Spec.SyncOptions.Type)))
if len(spc.Spec.SecretObjects) == 0 {
spc.Spec.SecretObjects = spcutil.BuildSecretObjects(files, secretutil.GetSecretType(strings.TrimSpace(spc.Spec.SyncOptions.Type)))
} else {
spc.Spec.SecretObjects = append(spc.Spec.SecretObjects, spcutil.BuildSecretObjects(files, secretutil.GetSecretType(strings.TrimSpace(spc.Spec.SyncOptions.Type)))...)
}
}

for _, secretObj := range spc.Spec.SecretObjects {
Expand Down
6 changes: 5 additions & 1 deletion pkg/rotation/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,11 @@ func (r *Reconciler) reconcile(ctx context.Context, spcps *v1alpha1.SecretProvid
files, err := fileutil.GetMountedFiles(spcps.Status.TargetPath)

if spc.Spec.SyncOptions.SyncAll {
spc.Spec.SecretObjects = spcutil.BuildSecretObjects(files, secretutil.GetSecretType(strings.TrimSpace(spc.Spec.SyncOptions.Type)))
if len(spc.Spec.SecretObjects) == 0 {
spc.Spec.SecretObjects = spcutil.BuildSecretObjects(files, secretutil.GetSecretType(strings.TrimSpace(spc.Spec.SyncOptions.Type)))
} else {
spc.Spec.SecretObjects = append(spc.Spec.SecretObjects, spcutil.BuildSecretObjects(files, secretutil.GetSecretType(strings.TrimSpace(spc.Spec.SyncOptions.Type)))...)
}
}

for _, secretObj := range spc.Spec.SecretObjects {
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/secretutil/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type basicAuthCreds struct {
// getCredentials parses the mounted content and returns the required
// key-value pairs for a kubernetes.io/basic-auth K8s secret
func getCredentials(data []byte) basicAuthCreds {
credentials := strings.Split(string(data), ";")
credentials := strings.Split(string(data), ",")
return basicAuthCreds{
Username: credentials[0],
Password: credentials[1],
Expand Down
8 changes: 5 additions & 3 deletions pkg/util/spcutil/secret_object_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func createDockerConfigJsonSecretDataObject(key string) *v1alpha1.SecretObject {
Type: string(corev1.SecretTypeDockerConfigJson),
Data: []*v1alpha1.SecretObjectData{
{
ObjectName: setKey(key),
ObjectName: key,
Key: dockerConfigJsonKey,
},
},
Expand Down Expand Up @@ -135,7 +135,8 @@ func createSSHSecretDataObject(key string) *v1alpha1.SecretObject {
}
}

func setKey(key string) string {
// setSecretName sets the name of a secret to the value of "objectName" separated by "-"
func setSecretName(key string) string {
nested := strings.Split(key, "/")

if len(nested) > 0 {
Expand All @@ -145,7 +146,8 @@ func setKey(key string) string {
return key
}

func setSecretName(key string) string {
// setKey sets the key of a secret to the name of the mounted file
func setKey(key string) string {
nested := strings.Split(key, "/")

if len(nested) > 0 {
Expand Down

0 comments on commit f552f0f

Please sign in to comment.