From 4fdf70e8d876d0cd697c305a743426c169a4893e Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Mon, 19 Dec 2022 17:35:01 +0200 Subject: [PATCH] consolidate configmap into 1 class --- .../1.0.0/templates/class/_configmap.tpl | 26 +++++++++++++ .../common/1.0.0/templates/class/_portal.tpl | 38 ------------------- .../common/1.0.0/templates/class/_secret.tpl | 4 +- .../templates/lib/certificate/_certSecret.tpl | 2 +- .../1.0.0/templates/spawner/_portal.tpl | 25 +++++++++++- 5 files changed, 53 insertions(+), 42 deletions(-) create mode 100644 library/common/1.0.0/templates/class/_configmap.tpl delete mode 100644 library/common/1.0.0/templates/class/_portal.tpl diff --git a/library/common/1.0.0/templates/class/_configmap.tpl b/library/common/1.0.0/templates/class/_configmap.tpl new file mode 100644 index 0000000000..0b13541f68 --- /dev/null +++ b/library/common/1.0.0/templates/class/_configmap.tpl @@ -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 -}} diff --git a/library/common/1.0.0/templates/class/_portal.tpl b/library/common/1.0.0/templates/class/_portal.tpl deleted file mode 100644 index 3e4b6b437b..0000000000 --- a/library/common/1.0.0/templates/class/_portal.tpl +++ /dev/null @@ -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 -}} diff --git a/library/common/1.0.0/templates/class/_secret.tpl b/library/common/1.0.0/templates/class/_secret.tpl index eb348ebf58..3714389a30 100644 --- a/library/common/1.0.0/templates/class/_secret.tpl +++ b/library/common/1.0.0/templates/class/_secret.tpl @@ -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 -}} diff --git a/library/common/1.0.0/templates/lib/certificate/_certSecret.tpl b/library/common/1.0.0/templates/lib/certificate/_certSecret.tpl index 371c1366c0..64bbf9cadf 100644 --- a/library/common/1.0.0/templates/lib/certificate/_certSecret.tpl +++ b/library/common/1.0.0/templates/lib/certificate/_certSecret.tpl @@ -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 -}} diff --git a/library/common/1.0.0/templates/spawner/_portal.tpl b/library/common/1.0.0/templates/spawner/_portal.tpl index 63f85d3669..5ceeb2aea5 100644 --- a/library/common/1.0.0/templates/spawner/_portal.tpl +++ b/library/common/1.0.0/templates/spawner/_portal.tpl @@ -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 -}}