Skip to content

Commit

Permalink
refactor: last commit before refactoring pod.go
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Csati <[email protected]>
  • Loading branch information
csatib02 committed Mar 26, 2024
1 parent c4683c5 commit fc8d4b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/webhook/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand All @@ -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) {
Expand All @@ -163,6 +166,7 @@ func (mw *MutatingWebhook) lookForEnvFrom(envFrom []corev1.EnvFromSource, ns str
}
}
}

return envVars, nil
}

Expand All @@ -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{
Expand All @@ -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 {
Expand All @@ -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{
Expand All @@ -201,6 +208,7 @@ func (mw *MutatingWebhook) lookForValueFrom(env corev1.EnvVar, ns string) (*core
return &fromSecret, nil
}
}

return nil, nil
}

Expand Down

0 comments on commit fc8d4b1

Please sign in to comment.