Skip to content

Commit 121e7e9

Browse files
authored
Move extraEnvVars and add tests (#2233)
Signed-off-by: Alexander Lindeskär <lindeskar@users.noreply.github.com>
1 parent e0b7bc1 commit 121e7e9

File tree

2 files changed

+112
-12
lines changed

2 files changed

+112
-12
lines changed

templates/exporter/exporter-dpl.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,12 @@ spec:
9494
name: {{ .Values.existingSecretAdminPassword }}
9595
key: {{ .Values.existingSecretAdminPasswordKey }}
9696
{{- end }}
97+
{{- with .Values.exporter.extraEnvVars }}
98+
{{- toYaml . | nindent 8 }}
99+
{{- end }}
97100
{{- if .Values.exporter.resources }}
98101
resources:
99102
{{ toYaml .Values.exporter.resources | indent 10 }}
100-
{{- end }}
101-
{{- with .Values.exporter.extraEnvVars }}
102-
env:
103-
{{- toYaml . | nindent 10 }}
104103
{{- end }}
105104
{{- if not (empty .Values.containerSecurityContext) }}
106105
securityContext: {{ .Values.containerSecurityContext | toYaml | nindent 10 }}

test/unittest/exporter/exporter_deployment_test.yaml

Lines changed: 109 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ tests:
9898
- contains:
9999
path: spec.template.spec.topologySpreadConstraints
100100
content:
101-
labelSelector:
102-
matchLabels:
103-
app: harbor
104-
component: exporter
105-
release: RELEASE-NAME
106-
maxSkew: 1
107-
topologyKey: topology.kubernetes.io/zone
108-
whenUnsatisfiable: ScheduleAnyway
101+
labelSelector:
102+
matchLabels:
103+
app: harbor
104+
component: exporter
105+
release: RELEASE-NAME
106+
maxSkew: 1
107+
topologyKey: topology.kubernetes.io/zone
108+
whenUnsatisfiable: ScheduleAnyway
109109

110110
- it: ContainerImage
111111
set:
@@ -311,3 +311,104 @@ tests:
311311
- equal:
312312
path: spec.template.spec.priorityClassName
313313
value: test-priority
314+
315+
- it: ExtraEnvVars
316+
set:
317+
metrics:
318+
enabled: true
319+
exporter:
320+
extraEnvVars:
321+
- name: EXAMPLE_ENV_VAR
322+
valueFrom:
323+
secretKeyRef:
324+
name: example-secret
325+
key: example-key
326+
template: templates/exporter/exporter-dpl.yaml
327+
asserts:
328+
- lengthEqual:
329+
path: spec.template.spec.containers[0].env
330+
count: 1
331+
- equal:
332+
path: spec.template.spec.containers[0].env[0].name
333+
value: EXAMPLE_ENV_VAR
334+
- equal:
335+
path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.name
336+
value: example-secret
337+
- equal:
338+
path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.key
339+
value: example-key
340+
341+
- it: ExtraEnvVarsExistingSecretAdminPassword
342+
set:
343+
metrics:
344+
enabled: true
345+
exporter:
346+
extraEnvVars:
347+
- name: EXAMPLE_ENV_VAR
348+
valueFrom:
349+
secretKeyRef:
350+
name: example-secret
351+
key: example-key
352+
existingSecretAdminPassword: HARBOR_ADMIN_PASSWORD
353+
template: templates/exporter/exporter-dpl.yaml
354+
asserts:
355+
- lengthEqual:
356+
path: spec.template.spec.containers[0].env
357+
count: 2
358+
- equal:
359+
path: spec.template.spec.containers[0].env[0].name
360+
value: HARBOR_ADMIN_PASSWORD
361+
- equal:
362+
path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.name
363+
value: HARBOR_ADMIN_PASSWORD
364+
- equal:
365+
path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.key
366+
value: HARBOR_ADMIN_PASSWORD
367+
- equal:
368+
path: spec.template.spec.containers[0].env[1].name
369+
value: EXAMPLE_ENV_VAR
370+
- equal:
371+
path: spec.template.spec.containers[0].env[1].valueFrom.secretKeyRef.name
372+
value: example-secret
373+
- equal:
374+
path: spec.template.spec.containers[0].env[1].valueFrom.secretKeyRef.key
375+
value: example-key
376+
377+
- it: ExtraEnvVarsExtDatabase
378+
set:
379+
metrics:
380+
enabled: true
381+
exporter:
382+
extraEnvVars:
383+
- name: EXAMPLE_ENV_VAR
384+
valueFrom:
385+
secretKeyRef:
386+
name: example-secret
387+
key: example-key
388+
database:
389+
type: external
390+
external:
391+
existingSecret: database-creds
392+
template: templates/exporter/exporter-dpl.yaml
393+
asserts:
394+
- lengthEqual:
395+
path: spec.template.spec.containers[0].env
396+
count: 2
397+
- equal:
398+
path: spec.template.spec.containers[0].env[0].name
399+
value: HARBOR_DATABASE_PASSWORD
400+
- equal:
401+
path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.name
402+
value: database-creds
403+
- equal:
404+
path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.key
405+
value: password
406+
- equal:
407+
path: spec.template.spec.containers[0].env[1].name
408+
value: EXAMPLE_ENV_VAR
409+
- equal:
410+
path: spec.template.spec.containers[0].env[1].valueFrom.secretKeyRef.name
411+
value: example-secret
412+
- equal:
413+
path: spec.template.spec.containers[0].env[1].valueFrom.secretKeyRef.key
414+
value: example-key

0 commit comments

Comments
 (0)