Skip to content

Commit

Permalink
tests for global.image.pullSecretNames
Browse files Browse the repository at this point in the history
Signed-off-by: Caleb Lloyd <[email protected]>
  • Loading branch information
Caleb Lloyd committed Nov 1, 2023
1 parent 2324054 commit 598ec56
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
2 changes: 1 addition & 1 deletion helm/charts/nats/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ keywords:
- nats
- messaging
- cncf
version: 1.1.3
version: 1.1.4
home: http://github.com/nats-io/k8s
maintainers:
- email: [email protected]
Expand Down
11 changes: 7 additions & 4 deletions helm/charts/nats/files/nats-box/deployment/pod-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ metadata:
labels:
{{- include "natsBox.labels" $ | nindent 4 }}
spec:
{{- with .Values.global.image.pullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 4 }}
{{- end }}
containers:
{{- with .Values.natsBox.container }}
- {{ include "nats.loadMergePatch" (merge (dict "file" "nats-box/deployment/container.yaml" "ctx" $) .) | nindent 4 }}
{{- end }}

# service discovery uses DNS; don't need service env vars
enableServiceLinks: false

{{- with .Values.global.image.pullSecretNames }}
imagePullSecrets:
{{- range . }}
- name: {{ . | quote }}
{{- end }}
{{- end }}

{{- with .Values.natsBox.serviceAccount }}
{{- if .enabled }}
Expand Down
11 changes: 7 additions & 4 deletions helm/charts/nats/files/stateful-set/pod-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ metadata:
checksum/config: {{ sha256sum $configMap }}
{{- end }}
spec:
{{- with .Values.global.image.pullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 4 }}
{{- end }}
containers:
# nats
{{- $nats := dict }}
Expand All @@ -32,6 +28,13 @@ spec:

# service discovery uses DNS; don't need service env vars
enableServiceLinks: false

{{- with .Values.global.image.pullSecretNames }}
imagePullSecrets:
{{- range . }}
- name: {{ . | quote }}
{{- end }}
{{- end }}

{{- with .Values.serviceAccount }}
{{- if .enabled }}
Expand Down
7 changes: 5 additions & 2 deletions helm/charts/nats/test/defaults_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package test

import (
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
policyv1 "k8s.io/api/policy/v1"
"sync"
"testing"

monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
policyv1 "k8s.io/api/policy/v1"

"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -312,6 +313,7 @@ exec sh -ec "$0"
},
},
EnableServiceLinks: &falseBool,
ImagePullSecrets: make([]corev1.LocalObjectReference, 0),
Volumes: []corev1.Volume{
{
Name: "contexts",
Expand Down Expand Up @@ -560,6 +562,7 @@ exec sh -ec "$0"
},
},
EnableServiceLinks: &falseBool,
ImagePullSecrets: make([]corev1.LocalObjectReference, 0),
ShareProcessNamespace: &trueBool,
Volumes: []corev1.Volume{
{
Expand Down
13 changes: 13 additions & 0 deletions helm/charts/nats/test/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func TestResourceOptions(t *testing.T) {
global:
image:
pullPolicy: Always
pullSecretNames:
- testPullSecret
registry: docker.io
labels:
global: global
Expand Down Expand Up @@ -133,6 +135,11 @@ natsBox:
expected.StatefulSet.Value.ObjectMeta.Labels["global"] = "global"
expected.StatefulSet.Value.ObjectMeta.Namespace = "foo"
expected.StatefulSet.Value.Spec.Template.ObjectMeta.Labels["global"] = "global"
expected.StatefulSet.Value.Spec.Template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{
{
Name: "testPullSecret",
},
}

dd := ddg.Get(t)
ctr := expected.StatefulSet.Value.Spec.Template.Spec.Containers
Expand Down Expand Up @@ -192,6 +199,12 @@ natsBox:
expected.NatsBoxDeployment.Value.ObjectMeta.Labels["global"] = "global"
expected.NatsBoxDeployment.Value.ObjectMeta.Namespace = "foo"
expected.NatsBoxDeployment.Value.Spec.Template.ObjectMeta.Labels["global"] = "global"
expected.NatsBoxDeployment.Value.Spec.Template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{
{
Name: "testPullSecret",
},
}

nbCtr := expected.NatsBoxDeployment.Value.Spec.Template.Spec.Containers[0]
// nats-box
nbCtr.Env = env
Expand Down
5 changes: 3 additions & 2 deletions helm/charts/nats/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ global:
# global image pull policy to use for all container images in the chart
# can be overridden by individual image pullPolicy
pullPolicy:
# global image pull secrets to use for all pod templates in the chart
# global list of secret names to use as image pull secrets for all pod specs in the chart
# secrets must exist in the same namespace
# https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
pullSecrets: []
pullSecretNames: []
# global registry to use for all container images in the chart
# can be overridden by individual image registry
registry:
Expand Down

0 comments on commit 598ec56

Please sign in to comment.