mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-22 15:38:06 +00:00
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package onepassword
|
|
|
|
import corev1 "k8s.io/api/core/v1"
|
|
|
|
func AreContainersUsingSecrets(containers []corev1.Container, secrets map[string]*corev1.Secret) bool {
|
|
for i := 0; i < len(containers); i++ {
|
|
envVariables := containers[i].Env
|
|
for j := 0; j < len(envVariables); j++ {
|
|
if envVariables[j].ValueFrom != nil && envVariables[j].ValueFrom.SecretKeyRef != nil {
|
|
_, ok := secrets[envVariables[j].ValueFrom.SecretKeyRef.Name]
|
|
if ok {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func AppendUpdatedContainerSecrets(containers []corev1.Container, secrets map[string]*corev1.Secret, updatedDeploymentSecrets map[string]*corev1.Secret) map[string]*corev1.Secret {
|
|
for i := 0; i < len(containers); i++ {
|
|
envVariables := containers[i].Env
|
|
for j := 0; j < len(envVariables); j++ {
|
|
if envVariables[j].ValueFrom != nil && envVariables[j].ValueFrom.SecretKeyRef != nil {
|
|
secret, ok := secrets[envVariables[j].ValueFrom.SecretKeyRef.Name]
|
|
if ok {
|
|
updatedDeploymentSecrets[secret.Name] = secret
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return updatedDeploymentSecrets
|
|
}
|