consolidate configmap into 1 class

This commit is contained in:
Stavros kois
2022-12-19 17:35:01 +02:00
parent f54faae277
commit 4fdf70e8d8
5 changed files with 53 additions and 42 deletions

View File

@@ -0,0 +1,26 @@
{{- define "ix.v1.common.class.configmap" -}}
{{- $configName := .configName -}}
{{- $data := .data -}}
{{- $type := .type -}}
{{- $root := .root -}}
---
apiVersion: {{ include "ix.v1.common.capabilities.configMap.apiVersion" $root }}
kind: ConfigMap
metadata:
name: {{ $configName }}
{{- $labels := (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)) -}}
{{- 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 }}
{{- end -}}
{{- end -}}

View File

@@ -1,38 +0,0 @@
{{/* A placeholder is added, just to avoid having an empty configmap */}}
{{- define "ix.v1.common.class.portal" -}}
{{- $root := .root -}}
---
apiVersion: {{ include "ix.v1.common.capabilities.configMap.apiVersion" . }}
kind: ConfigMap
metadata:
name: portal
{{- $labels := (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)) -}}
{{- with (include "ix.v1.common.util.annotations.render" (dict "root" $root "annotations" $annotations) | trim) }}
annotations:
{{- . | nindent 4 }}
{{- end }}
data:
portal: placeholder
{{- range $svcName, $svc := $root.Values.service }}
{{- if $svc.enabled -}}
{{- $svcValues := $svc -}}
{{- range $portName, $port := $svc.ports }}
{{- $portalProtocol := include "ix.v1.common.portal.protocol" (dict "svcType" $svc.type "svcName" $svcName "portName" $portName "port" $port "root" $root) | trim }}
{{- $portalHost := include "ix.v1.common.portal.host" (dict "svcType" $svc.type "svcName" $svcName "portName" $portName "port" $port "root" $root) | trim }}
{{- $portalPort := include "ix.v1.common.portal.port" (dict "svcType" $svc.type "svcName" $svcName "portName" $portName "port" $port "root" $root) | trim }}
{{- $portalPath := include "ix.v1.common.portal.path" (dict "svcType" $svc.type "svcName" $svcName "portName" $portName "port" $port "root" $root) | trim }}
{{ printf "protocol-%v-%v" $svcName $portName }}: {{ $portalProtocol | quote }}
{{ printf "host-%v-%v" $svcName $portName }}: {{ $portalHost | quote }}
{{ printf "path-%v-%v" $svcName $portName }}: {{ $portalPath | quote }}
{{ printf "port-%v-%v" $svcName $portName }}: {{ $portalPort | quote }}
{{ printf "url-%v-%v" $svcName $portName }}: {{ printf "%v://%v:%v%v" $portalProtocol $portalHost $portalPort $portalPath | quote }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -3,8 +3,8 @@
{{- $data := .data -}}
{{- $type := .type -}}
{{- $root := .root -}}
{{- $typeClass := "" -}}
{{- $typeClass := "" -}}
{{- if eq $type "certificate" -}}
{{- $typeClass = (include "ix.v1.common.capabilities.secret.certificate.type" $root) -}}
{{- else if eq $type "pullSecret" -}}
@@ -33,7 +33,7 @@ data:
.dockerconfigjson: {{ $data | toJson | b64enc }}
{{- else if eq $type "certificate" -}}
{{- range $k, $v := $data }}
{{ $k }}: {{ $v | toString | b64enc }}
{{- $k | nindent 2 }}: {{ $v | toString | b64enc }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -34,7 +34,7 @@
{{- $_ := set $certData $tlsCrtKey (include "ix.v1.common.certificate.get" (dict "root" $root "cert" $cert "key" "certificate")) -}}
{{- $_ := set $certData $tlsPrivateKey (include "ix.v1.common.certificate.get" (dict "root" $root "cert" $cert "key" "privatekey")) -}}
{{/* Create the secret */}}
{{/* Create the Secret */}}
{{- include "ix.v1.common.class.secret" (dict "root" $root "secretName" $secretName "data" $certData "type" "certificate") -}}
{{- end -}}
{{- end -}}

View File

@@ -1,7 +1,30 @@
{{- define "ix.v1.common.spawner.portal" -}}
{{- $data := dict -}}
{{- $root := . -}}
{{- if .Values.portal -}}
{{- if .Values.portal.enabled -}}
{{- include "ix.v1.common.class.portal" (dict "root" $) -}}
{{- range $svcName, $svc := $root.Values.service -}}
{{- if $svc.enabled -}}
{{- $svcValues := $svc -}}
{{- range $portName, $port := $svc.ports -}}
{{- $portalProtocol := include "ix.v1.common.portal.protocol" (dict "svcType" $svc.type "svcName" $svcName "portName" $portName "port" $port "root" $root) | trim -}}
{{- $portalHost := include "ix.v1.common.portal.host" (dict "svcType" $svc.type "svcName" $svcName "portName" $portName "port" $port "root" $root) | trim -}}
{{- $portalPort := include "ix.v1.common.portal.port" (dict "svcType" $svc.type "svcName" $svcName "portName" $portName "port" $port "root" $root) | trim -}}
{{- $portalPath := include "ix.v1.common.portal.path" (dict "svcType" $svc.type "svcName" $svcName "portName" $portName "port" $port "root" $root) | trim -}}
{{- $_ := set $data (printf "protocol-%v-%v" $svcName $portName) ($portalProtocol | quote) -}}
{{- $_ := set $data (printf "host-%v-%v" $svcName $portName) ($portalHost | quote) -}}
{{- $_ := set $data (printf "path-%v-%v" $svcName $portName) ($portalPath | quote) -}}
{{- $_ := set $data (printf "port-%v-%v" $svcName $portName) ($portalPort | quote) -}}
{{- $_ := set $data (printf "url-%v-%v" $svcName $portName) (printf "%v://%v:%v%v" $portalProtocol $portalHost $portalPort $portalPath | quote) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $data -}}
{{/* Create the ConfigMap */}}
{{- include "ix.v1.common.class.configmap" (dict "root" $root "configName" "portal" "type" "portal" "data" $data) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}