add configmap

This commit is contained in:
Stavros kois
2022-12-20 00:58:52 +02:00
parent bcc395dbc6
commit 992c41c3c4
2 changed files with 63 additions and 4 deletions

View File

@@ -2,6 +2,8 @@
{{- $configName := .configName -}}
{{- $data := .data -}}
{{- $type := .type -}}
{{- $configLabels := .labels -}}
{{- $configAnnotations := .annotations -}}
{{- $root := .root -}}
---
@@ -9,18 +11,24 @@ apiVersion: {{ include "ix.v1.common.capabilities.configMap.apiVersion" $root }}
kind: ConfigMap
metadata:
name: {{ $configName }}
{{- $labels := (default dict (include "ix.v1.common.labels" $root | fromYaml)) -}}
{{- $labels := (mustMerge ($configLabels | default dict) (include "ix.v1.common.labels" $root | fromYaml)) -}}
{{- with (include "ix.v1.common.util.labels.render" (dict "root" $root "labels" $labels) | trim) }}
labels:
{{- . | nindent 4 }}
{{- end -}}
{{- $annotations := (default dict (include "ix.v1.common.annotations" $root | fromYaml)) -}}
{{- $annotations := (mustMerge ($configAnnotations | default dict) (include "ix.v1.common.annotations" $root | fromYaml)) -}}
{{- with (include "ix.v1.common.util.annotations.render" (dict "root" $root "annotations" $annotations) | trim) }}
annotations:
{{- . | nindent 4 }}
{{- end }}
data:
{{- range $k, $v := $data }}
{{- $k | nindent 2 }}: {{ $v }}
{{- if eq $type "key_value" -}}
{{- range $k, $v := $data }}
{{- $k | nindent 2 }}: {{ $v }}
{{- end -}}
{{- else if eq $type "scalar" -}}
{{- $data | nindent 2 }}
{{- else -}}
{{- fail (printf "Invalid type (%s) for configmap. Valid types are scalar and key_value" $type) -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,51 @@
{{- define "ix.v1.common.spawner.configmap" -}}
{{- $root := . -}}
{{- range $name, $config := .Values.configmap -}}
{{- $configMapName := include "ix.v1.common.names.fullname" $root -}}
{{- $data := dict -}}
{{- if $config.enabled -}}
{{- if not $config.content -}}
{{- fail (printf "Configmap (%s) has empty <content>. Please disable or add contents." $name) -}}
{{- end -}}
{{- if eq (kindOf $config.content) "string" -}}
{{- fail (printf "Configmap (%s) contents are string. Must be in key/value format. Value can be scalar too." $name) -}}
{{- end -}}
{{- if and (hasKey $config "nameOverride") $config.nameOverride -}}
{{- $configMapName = printf "%v-%v" $configMapName $config.nameOverride -}}
{{- else -}}
{{- $configMapName = printf "%v-%v" $configMapName $name -}}
{{- end -}}
{{- $parseAsEnv := false -}}
{{- if hasKey $config "parseAsEnv" -}}
{{- $parseAsEnv = $config.parseAsEnv -}}
{{- end -}}
{{- if $parseAsEnv -}}
{{- $dupeCheck := dict -}}
{{- range $k, $v := $config.content -}}
{{- $value := tpl $v $root -}} {{/* Exapand templates before sending them to the configmap */}}
{{- $_ := set $data $k $value -}}
{{- $_ := set $dupeCheck $k $value -}}
{{- end -}}
{{- include "ix.v1.common.util.storeEnvsForCheck" (dict "root" $root "source" (printf "configmap-%s" $name) "data" $dupeCheck) -}}
{{/* Create ConfigMap */}}
{{- include "ix.v1.common.class.configmap" (dict "root" $root "configName" $configMapName "type" "key_value" "data" $data "labels" $config.labels "annotations" $config.annotations) -}}
{{- else -}}
{{- range $key, $value := $config.content -}}
{{- if not $value -}}
{{- fail (printf "Configmap (%s) has key (%s), without content." $name $key) -}}
{{- end -}}
{{- end -}}
{{- include "ix.v1.common.class.configmap" (dict "root" $root "configName" $configMapName "type" "scalar" "data" (tpl (toYaml $config.content) $root) "labels" $config.labels "annotations" $config.annotations) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}