Skip to content

Commit 19cdf4e

Browse files
authored
Merge pull request #112 from GDATASoftwareAG/111-mismatch-between-globalimagepullsecrets-for-vaas-and-redis
accept only object based imagepullsecrets
2 parents 2424a8d + e5160be commit 19cdf4e

File tree

10 files changed

+105
-35
lines changed

10 files changed

+105
-35
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ jobs:
4949
- name: Set up chart-testing
5050
uses: helm/[email protected]
5151

52+
- name: Install helm unittest
53+
run: helm plugin install https://github.com/helm-unittest/helm-unittest.git
54+
5255
- name: Extract tag
5356
id: extract_tag
5457
run: |
@@ -61,6 +64,9 @@ jobs:
6164
- name: Run chart-testing (lint)
6265
run: ct lint --validate-maintainers=false --charts vaas-helm/charts/vaas
6366

67+
- name: Run helm unittest
68+
run: helm unittest --strict vaas-helm/charts/vaas
69+
6470
- name: Install Minikube
6571
uses: manusa/[email protected]
6672
with:

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ You need to substitute the username and password with the credentials we provide
4444
```yaml
4545
global:
4646
imagePullSecrets:
47-
- my-image-pull-secret
47+
- name: my-image-pull-secret
48+
- name: my-other-image-pull-secret
49+
...
4850
```
4951

5052

charts/vaas/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: vaas
3-
version: 3.0.3
3+
version: 3.1.0
44
description: Deployment of a Verdict-as-a-Service on-premise instance
55
maintainers:
66
- name: G DATA CyberDefense AG

charts/vaas/templates/gateway/_helpers.tpl

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,29 +25,27 @@ If release name contains chart name it will be used as a full name.
2525

2626
{{- define "gateway.imagePullSecrets" -}}
2727
{{- $ips := .Values.global.imagePullSecrets | default (list) -}}
28+
29+
{{- range $i, $e := $ips }}
30+
{{- if not (kindIs "map" $e) -}}
31+
{{- fail (printf "global.imagePullSecrets[%d] must be an object with 'name' (or 'secretName'), not %s" $i (kindOf $e)) -}}
32+
{{- end -}}
33+
{{- $n := (get $e "name") | default (get $e "secretName") -}}
34+
{{- if not $n -}}
35+
{{- fail (printf "global.imagePullSecrets[%d] must contain key 'name' or 'secretName'. Got keys: %v" $i (keys $e)) -}}
36+
{{- end -}}
37+
{{- end }}
38+
2839
{{- $hasIps := gt (len $ips) 0 -}}
2940
{{- $hasLocal := .Values.imagePullSecret -}}
3041
{{- $hasGlobalImagePullSecret := ((.Values.global).secret).imagePullSecret -}}
3142
{{- $hasGlobalDockerconfig := ((.Values.global).secret).dockerconfigjson -}}
3243

3344
{{- if or $hasIps $hasLocal $hasGlobalImagePullSecret $hasGlobalDockerconfig }}
3445
imagePullSecrets:
35-
{{- range $i, $entry := $ips }}
36-
{{- if kindIs "string" $entry }}
37-
- name: {{ $entry }}
38-
{{- else if kindIs "map" $entry }}
39-
{{- if hasKey $entry "name" }}
40-
- name: {{ get $entry "name" }}
41-
{{- else if hasKey $entry "secretName" }}
42-
- name: {{ get $entry "secretName" }}
43-
{{- else }}
44-
{{- fail (printf "global.imagePullSecrets[%d] must have key 'name' (or 'secretName'). Got keys: %v" $i (keys $entry)) }}
45-
{{- end }}
46-
{{- else }}
47-
{{- fail (printf "global.imagePullSecrets[%d] has unsupported kind %s (type %s)" $i (kindOf $entry) (typeOf $entry)) }}
48-
{{- end }}
46+
{{- range $i, $e := $ips }}
47+
- name: {{ (get $e "name") | default (get $e "secretName") }}
4948
{{- end }}
50-
5149
{{- if $hasLocal }}
5250
- name: {{ include "gateway.fullname" . }}-image-pull-secret
5351
{{- end }}
@@ -58,12 +56,11 @@ imagePullSecrets:
5856
- name: {{ include "gateway.fullname" . }}-global-dockerconfigjson
5957
{{- end }}
6058
{{- else -}}
61-
{{- fail "You have to set at least one imagePullSecret (global.imagePullSecrets, imagePullSecret, global.secret.imagePullSecret or global.secret.dockerconfigjson)" }}
59+
{{- fail "You have to set at least one imagePullSecret: use global.imagePullSecrets (objects with 'name'/'secretName') or set imagePullSecret/global.secret.*" }}
6260
{{- end -}}
6361
{{- end -}}
6462

6563

66-
6764
{{/*
6865
Create chart name and version as used by the chart label.
6966
*/}}

charts/vaas/templates/gdscan/_helpers.tpl

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,29 +44,27 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
4444

4545
{{- define "gdscan.imagePullSecrets" -}}
4646
{{- $ips := .Values.global.imagePullSecrets | default (list) -}}
47+
48+
{{- range $i, $e := $ips }}
49+
{{- if not (kindIs "map" $e) -}}
50+
{{- fail (printf "global.imagePullSecrets[%d] must be an object with 'name' (or 'secretName'), not %s" $i (kindOf $e)) -}}
51+
{{- end -}}
52+
{{- $n := (get $e "name") | default (get $e "secretName") -}}
53+
{{- if not $n -}}
54+
{{- fail (printf "global.imagePullSecrets[%d] must contain key 'name' or 'secretName'. Got keys: %v" $i (keys $e)) -}}
55+
{{- end -}}
56+
{{- end }}
57+
4758
{{- $hasIps := gt (len $ips) 0 -}}
4859
{{- $hasLocal := .Values.imagePullSecret -}}
4960
{{- $hasGlobalImagePullSecret := ((.Values.global).secret).imagePullSecret -}}
5061
{{- $hasGlobalDockerconfig := ((.Values.global).secret).dockerconfigjson -}}
5162

5263
{{- if or $hasIps $hasLocal $hasGlobalImagePullSecret $hasGlobalDockerconfig }}
5364
imagePullSecrets:
54-
{{- range $i, $entry := $ips }}
55-
{{- if kindIs "string" $entry }}
56-
- name: {{ $entry }}
57-
{{- else if kindIs "map" $entry }}
58-
{{- if hasKey $entry "name" }}
59-
- name: {{ get $entry "name" }}
60-
{{- else if hasKey $entry "secretName" }}
61-
- name: {{ get $entry "secretName" }}
62-
{{- else }}
63-
{{- fail (printf "global.imagePullSecrets[%d] must have key 'name' (or 'secretName'). Got keys: %v" $i (keys $entry)) }}
64-
{{- end }}
65-
{{- else }}
66-
{{- fail (printf "global.imagePullSecrets[%d] has unsupported kind %s (type %s)" $i (kindOf $entry) (typeOf $entry)) }}
67-
{{- end }}
65+
{{- range $i, $e := $ips }}
66+
- name: {{ (get $e "name") | default (get $e "secretName") }}
6867
{{- end }}
69-
7068
{{- if $hasLocal }}
7169
- name: {{ include "gdscan.fullname" . }}-image-pull-secret
7270
{{- end }}
@@ -77,7 +75,7 @@ imagePullSecrets:
7775
- name: {{ include "gdscan.fullname" . }}-global-dockerconfigjson
7876
{{- end }}
7977
{{- else -}}
80-
{{- fail "You have to set at least one imagePullSecret (global.imagePullSecrets, imagePullSecret, global.secret.imagePullSecret or global.secret.dockerconfigjson)" }}
78+
{{- fail "You have to set at least one imagePullSecret: use global.imagePullSecrets (objects with 'name'/'secretName') or set imagePullSecret/global.secret.*" }}
8179
{{- end -}}
8280
{{- end -}}
8381

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- $tests := .Values._tests | default dict -}}
2+
{{- if (get $tests "enableImagePullSecretsTest") }}
3+
apiVersion: v1
4+
kind: Pod
5+
metadata:
6+
name: imagepullsecrets-test
7+
spec:
8+
{{- $_ := include "gateway.imagePullSecrets" . -}}
9+
{{- include "gateway.imagePullSecrets" . | nindent 2 }}
10+
containers:
11+
- name: noop
12+
image: scratch
13+
{{- end }}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
suite: imagePullSecrets helper
2+
templates:
3+
- templates/imagepullsecrets-test.yaml
4+
5+
tests:
6+
- it: renders with object {name}
7+
values: [values/ok_object.yaml]
8+
asserts:
9+
- isKind: { of: Pod }
10+
- contains:
11+
path: spec.imagePullSecrets
12+
content: { name: ghcr-pull }
13+
14+
- it: renders with global.secret.* only
15+
values: [values/ok_global_secret.yaml]
16+
asserts:
17+
- isKind: { of: Pod }
18+
- contains:
19+
path: spec.imagePullSecrets
20+
content: { name: gateway-global-image-pull-secret }
21+
- contains:
22+
path: spec.imagePullSecrets
23+
content: { name: gateway-global-dockerconfigjson }
24+
25+
- it: fails on string entry
26+
values: [values/fail_string.yaml]
27+
asserts:
28+
- failedTemplate:
29+
errorPattern: "must be an object with 'name'"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_tests:
2+
enableImagePullSecretsTest: true
3+
global:
4+
imagePullSecrets:
5+
- my-secret
6+
redis:
7+
enabled: false
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
_tests:
2+
enableImagePullSecretsTest: true
3+
4+
global:
5+
imagePullSecrets: []
6+
secret:
7+
imagePullSecret: "e30K"
8+
dockerconfigjson: "e30K"
9+
10+
redis:
11+
enabled: false
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_tests:
2+
enableImagePullSecretsTest: true
3+
global:
4+
imagePullSecrets:
5+
- name: ghcr-pull
6+
redis:
7+
enabled: false

0 commit comments

Comments
 (0)