Skip to content

Commit 77e1a5d

Browse files
committed
feature to prevent updating existing configmap
1 parent cd5a6a0 commit 77e1a5d

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

chart/templates/configmap.yaml

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
1+
{{- $configMapName := printf "%s-config" (include "PolyNSI.fullname" .) }}
2+
{{- $existingConfigMap := "" }}
3+
{{- if .Values.config.checkExistence }}
4+
{{- $existingConfigMap = lookup "v1" "ConfigMap" .Release.Namespace $configMapName }}
5+
{{- end }}
6+
17
apiVersion: v1
28
kind: ConfigMap
39
metadata:
4-
name: {{ printf "%s-config" (include "PolyNSI.fullname" .) }}
10+
name: {{ $configMapName }}
511
# namespace: {{ .Release.Namespace }}
12+
{{- if and .Values.config.checkExistence $existingConfigMap }}
13+
# Preserve existing ConfigMap data
14+
{{- if $existingConfigMap.data }}
15+
data:
16+
{{- range $key, $value := $existingConfigMap.data }}
17+
{{ $key }}: {{ $value | quote }}
18+
{{- end }}
19+
{{- end }}
20+
{{- if $existingConfigMap.binaryData }}
21+
binaryData:
22+
{{- range $key, $value := $existingConfigMap.binaryData }}
23+
{{ $key }}: {{ $value }}
24+
{{- end }}
25+
{{- end }}
26+
{{- else }}
27+
# Create new ConfigMap data from values
628
{{- if .Values.config.filesGlob }}
729
binaryData:
830
{{- range $path, $_ := .Files.Glob .Values.config.filesGlob }}
9-
{{ $path | base | indent 2 }}: |-
31+
{{ $path | base }}: |-
1032
{{ $.Files.Get $path | b64enc | indent 4 }}
11-
{{ end }}
12-
{{ else if .Values.config.inline }}
33+
{{- end }}
34+
{{- else if .Values.config.inline }}
1335
data:
14-
{{.Values.config.inline | indent 2}}
15-
{{ end }}
36+
{{ .Values.config.inline | indent 2 }}
37+
{{- end }}
38+
{{- end }}

chart/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ truststore:
9898
key: truststore.jks
9999

100100
config:
101+
checkExistence: false # Set to true to not overwrite existing configmap.
101102
# either read config files from folder or use inline data, filesGlob takes precedence over inline.
102103
#filesGlob: "config/*"
103104
inline: |-

0 commit comments

Comments
 (0)