Skip to content

Commit

Permalink
fix: don't create a configmap if there isn't any items
Browse files Browse the repository at this point in the history
  • Loading branch information
henrywhitaker3 committed Mar 25, 2024
1 parent 6948efc commit fd84f62
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.3.5
version: 1.3.6
# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
Expand Down
2 changes: 2 additions & 0 deletions chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.config }}
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -6,3 +7,4 @@ metadata:
{{- include "generic.labels" . | nindent 4 }}
data:
{{- .Values.config | toYaml | nindent 2 }}
{{- end }}
4 changes: 4 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,17 @@ spec:
env:
{{ .Values.env | toYaml | nindent 12 }}
{{- end }}
{{- if or (.Values.secrets.enabled) (.Values.config) }}
envFrom:
{{- if .Values.config }}
- configMapRef:
name: {{ include "generic.fullname" . }}
{{- end }}
{{- if .Values.secrets.enabled }}
- secretRef:
name: {{ include "generic.fullname" . }}
{{- end }}
{{- end }}
{{- if gt (len .Values.extraContainers) 0 }}
{{ .Values.extraContainers | toYaml | nindent 8 }}
{{- end }}
Expand Down
21 changes: 21 additions & 0 deletions chart/tests/configmap_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
suite: configmap test

templates:
- configmap.yaml

tests:
- it: does not create a cm when no items in map
asserts:
- hasDocuments:
count: 0

- it: creates a cm when items in map
set:
config:
BONGO: bingo
asserts:
- hasDocuments:
count: 1
- equal:
path: .data.BONGO
value: bingo
16 changes: 11 additions & 5 deletions chart/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,24 @@ tests:
path: .spec.template.spec.containers[0].resources.limits.cpu
value: 100m

- it: adds the configmap to the envFrom
- it: adds the configmap to the envFrom when created
set:
fullnameOverride: bongo
config:
BONGO: bingo
asserts:
- contains:
path: .spec.template.spec.containers[0].envFrom
content:
configMapRef:
name: bongo

- it: does not add the configmap to the envFrom when not set
set:
fullnameOverride: bongo
asserts:
- notExists:
path: .spec.template.spec.containers[0].envFrom

- it: adds the secret to the envFrom when secrets.enabled == true
set:
Expand All @@ -182,11 +191,8 @@ tests:
secrets.enabled: false
fullnameOverride: bongo
asserts:
- notContains:
- notExists:
path: .spec.template.spec.containers[0].envFrom
content:
secretRef:
name: bongo

- it: creates one container by default
asserts:
Expand Down

0 comments on commit fd84f62

Please sign in to comment.