From fc8d4b11a192b2e4ba8016bd466afee613724880 Mon Sep 17 00:00:00 2001 From: Bence Csati Date: Tue, 26 Mar 2024 18:28:31 +0100 Subject: [PATCH] refactor: last commit before refactoring pod.go Signed-off-by: Bence Csati --- pkg/webhook/pod.go | 7 +++++++ pkg/webhook/webhook.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/pkg/webhook/pod.go b/pkg/webhook/pod.go index e632675..5ad5ebf 100644 --- a/pkg/webhook/pod.go +++ b/pkg/webhook/pod.go @@ -67,6 +67,13 @@ func (mw *MutatingWebhook) MutatePod(ctx context.Context, pod *corev1.Pod, webho if err != nil { return errors.Wrap(err, "failed to mutate secret") } + case bao.Config: + currentlyUsedProvider = bao.ProviderName + + // err := mw.mutatePodForBao(ctx, pod, webhookConfig, secretInitConfig, providerConfig, dryRun) + // if err != nil { + // return errors.Wrap(err, "failed to mutate secret") + // } default: return errors.Errorf("unknown provider config type: %T", config) diff --git a/pkg/webhook/webhook.go b/pkg/webhook/webhook.go index 8b1eba5..7371b1a 100644 --- a/pkg/webhook/webhook.go +++ b/pkg/webhook/webhook.go @@ -132,6 +132,7 @@ func (mw *MutatingWebhook) lookForEnvFrom(envFrom []corev1.EnvFromSource, ns str return envVars, err } + for key, value := range data { if hasProviderPrefix(currentlyUsedProvider, value, true) { envFromCM := corev1.EnvVar{ @@ -142,6 +143,7 @@ func (mw *MutatingWebhook) lookForEnvFrom(envFrom []corev1.EnvFromSource, ns str } } } + if ef.SecretRef != nil { data, err := mw.getDataFromSecret(ef.SecretRef.Name, ns) if err != nil { @@ -151,6 +153,7 @@ func (mw *MutatingWebhook) lookForEnvFrom(envFrom []corev1.EnvFromSource, ns str return envVars, err } + for name, v := range data { value := string(v) if hasProviderPrefix(currentlyUsedProvider, value, true) { @@ -163,6 +166,7 @@ func (mw *MutatingWebhook) lookForEnvFrom(envFrom []corev1.EnvFromSource, ns str } } } + return envVars, nil } @@ -175,6 +179,7 @@ func (mw *MutatingWebhook) lookForValueFrom(env corev1.EnvVar, ns string) (*core } return nil, err } + value := data[env.ValueFrom.ConfigMapKeyRef.Key] if hasProviderPrefix(currentlyUsedProvider, value, true) { fromCM := corev1.EnvVar{ @@ -184,6 +189,7 @@ func (mw *MutatingWebhook) lookForValueFrom(env corev1.EnvVar, ns string) (*core return &fromCM, nil } } + if env.ValueFrom.SecretKeyRef != nil { data, err := mw.getDataFromSecret(env.ValueFrom.SecretKeyRef.Name, ns) if err != nil { @@ -192,6 +198,7 @@ func (mw *MutatingWebhook) lookForValueFrom(env corev1.EnvVar, ns string) (*core } return nil, err } + value := string(data[env.ValueFrom.SecretKeyRef.Key]) if hasProviderPrefix(currentlyUsedProvider, value, true) { fromSecret := corev1.EnvVar{ @@ -201,6 +208,7 @@ func (mw *MutatingWebhook) lookForValueFrom(env corev1.EnvVar, ns string) (*core return &fromSecret, nil } } + return nil, nil }