Skip to content

Commit

Permalink
tests for global.image.pullSecretNames (#815)
Browse files Browse the repository at this point in the history
* tests for global.image.pullSecretNames

Signed-off-by: Caleb Lloyd <[email protected]>

* update chart testing action

Signed-off-by: Caleb Lloyd <[email protected]>

* fix tests

Signed-off-by: Caleb Lloyd <[email protected]>

---------

Signed-off-by: Caleb Lloyd <[email protected]>
  • Loading branch information
caleblloyd authored Nov 2, 2023
1 parent 2324054 commit b85689c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
python-version: 3.9

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.4.0
uses: helm/chart-testing-action@v2.6.0

- name: Run chart-testing (lint)
run: |-
Expand Down
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
5 changes: 3 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
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 b85689c

Please sign in to comment.