Unverified Commit b1732a5f authored by Julien Mancuso's avatar Julien Mancuso Committed by GitHub
Browse files

fix: remove duplicates from imagePullSecrets (#3923)


Signed-off-by: default avatarJulien Mancuso <jmancuso@nvidia.com>
parent 927dcbfc
...@@ -87,12 +87,12 @@ spec: ...@@ -87,12 +87,12 @@ spec:
{{- if .Values.natsAddr }} {{- if .Values.natsAddr }}
- --natsAddr={{ .Values.natsAddr }} - --natsAddr={{ .Values.natsAddr }}
{{- else }} {{- else }}
- --natsAddr=nats://{{ .Release.Name }}-nats.{{ .Release.Namespace }}:4222 - --natsAddr=nats://{{ .Release.Name }}-nats.{{ .Release.Namespace }}.svc.cluster.local:4222
{{- end }} {{- end }}
{{- if .Values.etcdAddr }} {{- if .Values.etcdAddr }}
- --etcdAddr={{ .Values.etcdAddr }} - --etcdAddr={{ .Values.etcdAddr }}
{{- else }} {{- else }}
- --etcdAddr={{ .Release.Name }}-etcd.{{ .Release.Namespace }}:2379 - --etcdAddr={{ .Release.Name }}-etcd.{{ .Release.Namespace }}.svc.cluster.local:2379
{{- end }} {{- end }}
{{- if and .Values.dynamo.istio.enabled .Values.dynamo.istio.gateway }} {{- if and .Values.dynamo.istio.enabled .Values.dynamo.istio.gateway }}
- --istio-virtual-service-gateway={{ .Values.dynamo.istio.gateway }} - --istio-virtual-service-gateway={{ .Values.dynamo.istio.gateway }}
......
...@@ -101,9 +101,11 @@ func CanonicalizePodSpec(podSpec *corev1.PodSpec) *corev1.PodSpec { ...@@ -101,9 +101,11 @@ func CanonicalizePodSpec(podSpec *corev1.PodSpec) *corev1.PodSpec {
// Sort image pull secrets // Sort image pull secrets
if len(podSpec.ImagePullSecrets) > 1 { if len(podSpec.ImagePullSecrets) > 1 {
sort.Slice(podSpec.ImagePullSecrets, func(i, j int) bool { uniqueSecrets := ensureUniqueImagePullSecrets(podSpec.ImagePullSecrets)
return podSpec.ImagePullSecrets[i].Name < podSpec.ImagePullSecrets[j].Name sort.Slice(uniqueSecrets, func(i, j int) bool {
return uniqueSecrets[i].Name < uniqueSecrets[j].Name
}) })
podSpec.ImagePullSecrets = uniqueSecrets
} }
// Sort volumes and their nested items // Sort volumes and their nested items
...@@ -275,3 +277,18 @@ func CanonicalizePodSpec(podSpec *corev1.PodSpec) *corev1.PodSpec { ...@@ -275,3 +277,18 @@ func CanonicalizePodSpec(podSpec *corev1.PodSpec) *corev1.PodSpec {
return podSpec return podSpec
} }
func ensureUniqueImagePullSecrets(secrets []corev1.LocalObjectReference) []corev1.LocalObjectReference {
if len(secrets) == 0 {
return nil
}
uniqueSecrets := make(map[string]corev1.LocalObjectReference)
for _, secret := range secrets {
uniqueSecrets[secret.Name] = secret
}
uniqueSecretsList := make([]corev1.LocalObjectReference, 0, len(uniqueSecrets))
for secretName := range uniqueSecrets {
uniqueSecretsList = append(uniqueSecretsList, corev1.LocalObjectReference{Name: secretName})
}
return uniqueSecretsList
}
...@@ -208,6 +208,7 @@ func TestCanonicalizePodSpec(t *testing.T) { ...@@ -208,6 +208,7 @@ func TestCanonicalizePodSpec(t *testing.T) {
{Name: "registry-z"}, {Name: "registry-z"},
{Name: "registry-a"}, {Name: "registry-a"},
{Name: "registry-b"}, {Name: "registry-b"},
{Name: "registry-a"},
}, },
}, },
expected: &corev1.PodSpec{ expected: &corev1.PodSpec{
...@@ -218,6 +219,15 @@ func TestCanonicalizePodSpec(t *testing.T) { ...@@ -218,6 +219,15 @@ func TestCanonicalizePodSpec(t *testing.T) {
}, },
}, },
}, },
{
name: "sorts nil image pull secrets",
input: &corev1.PodSpec{
ImagePullSecrets: nil,
},
expected: &corev1.PodSpec{
ImagePullSecrets: nil,
},
},
{ {
name: "sorts volumes by name", name: "sorts volumes by name",
input: &corev1.PodSpec{ input: &corev1.PodSpec{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment