From 59a581ed2618b5ac762629decf794a55fb167bf0 Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Wed, 7 Dec 2022 18:00:40 +0200 Subject: [PATCH] initial portal work --- .../common/1.0.0/templates/class/_portal.tpl | 38 +++++++++++++++++++ .../1.0.0/templates/lib/portal/_host.tpl | 25 ++++++++++++ .../1.0.0/templates/lib/portal/_path.tpl | 25 ++++++++++++ .../1.0.0/templates/lib/portal/_port.tpl | 33 ++++++++++++++++ .../1.0.0/templates/lib/portal/_protocol.tpl | 31 +++++++++++++++ .../common/1.0.0/templates/loader/_apply.tpl | 2 + .../1.0.0/templates/spawner/_portal.tpl | 7 ++++ library/common/1.0.0/values.yaml | 10 +++++ 8 files changed, 171 insertions(+) create mode 100644 library/common/1.0.0/templates/class/_portal.tpl create mode 100644 library/common/1.0.0/templates/lib/portal/_host.tpl create mode 100644 library/common/1.0.0/templates/lib/portal/_path.tpl create mode 100644 library/common/1.0.0/templates/lib/portal/_port.tpl create mode 100644 library/common/1.0.0/templates/lib/portal/_protocol.tpl create mode 100644 library/common/1.0.0/templates/spawner/_portal.tpl diff --git a/library/common/1.0.0/templates/class/_portal.tpl b/library/common/1.0.0/templates/class/_portal.tpl new file mode 100644 index 0000000000..d89ae66ea6 --- /dev/null +++ b/library/common/1.0.0/templates/class/_portal.tpl @@ -0,0 +1,38 @@ +{{- 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: + {{- range $svcName, $svc := $root.Values.service }} + {{- if $svc.enabled -}} + {{- $svcValues := $svc -}} + {{- range $portName, $port := $svc.ports }} + {{- if (mustHas $port.protocol (list "HTTP" "HTTPS")) -}} + {{- $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 }} + {{ printf "host-%v-%v" $svcName $portName }}: {{ $portalHost }} + {{ printf "path-%v-%v" $svcName $portName }}: {{ $portalPath }} + {{ printf "port-%v-%v" $svcName $portName }}: {{ $portalPort }} + {{ printf "url-%v-%v" $svcName $portName }}: {{ printf "%v://%v:%v%v" $portalProtocol $portalHost $portalPort $portalPath }} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/portal/_host.tpl b/library/common/1.0.0/templates/lib/portal/_host.tpl new file mode 100644 index 0000000000..41e69e7994 --- /dev/null +++ b/library/common/1.0.0/templates/lib/portal/_host.tpl @@ -0,0 +1,25 @@ +{{- define "ix.v1.common.portal.host" -}} + {{- $svcType := .svcType -}} + {{- $svcName := .svcName -}} + {{- $portName := .portName -}} + {{- $port := .port -}} + {{- $root := .root -}} + + {{- $portalHost := "$node_ip" -}} + + {{/* If ingress is added at any point, here is the place to implement */}} + + {{/* Check if there are any overrides in .Values.portal */}} + {{- range $name, $portalSvc := $root.Values.portal -}} + {{- if eq $svcName $name -}} + {{- range $name, $portalPort := $portalSvc -}} + {{- if eq $portName $name -}} + {{- with $portalPort.host -}} + {{- $portalHost = (tpl . $root) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end }} +{{ $portalHost }} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/portal/_path.tpl b/library/common/1.0.0/templates/lib/portal/_path.tpl new file mode 100644 index 0000000000..9e7e459ac5 --- /dev/null +++ b/library/common/1.0.0/templates/lib/portal/_path.tpl @@ -0,0 +1,25 @@ +{{- define "ix.v1.common.portal.path" -}} + {{- $svcType := .svcType -}} + {{- $svcName := .svcName -}} + {{- $portName := .portName -}} + {{- $port := .port -}} + {{- $root := .root -}} + + {{- $portalPath := "/" -}} + + {{/* If ingress is added at any point, here is the place to implement */}} + + {{/* Check if there are any overrides in .Values.portal */}} + {{- range $name, $portalSvc := $root.Values.portal -}} + {{- if eq $svcName $name -}} + {{- range $name, $portalPort := $portalSvc -}} + {{- if eq $portName $name -}} + {{- with $portalPort.path -}} + {{- $portalPath = (tpl . $root) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end }} +{{ $portalPath }} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/portal/_port.tpl b/library/common/1.0.0/templates/lib/portal/_port.tpl new file mode 100644 index 0000000000..3bc740c54a --- /dev/null +++ b/library/common/1.0.0/templates/lib/portal/_port.tpl @@ -0,0 +1,33 @@ +{{- define "ix.v1.common.portal.port" -}} + {{- $svcType := .svcType -}} + {{- $svcName := .svcName -}} + {{- $portName := .portName -}} + {{- $port := .port -}} + {{- $root := .root -}} + + {{- $portalPort := 443 -}} + + {{- if $root.Values.hostNetwork -}} + {{- $portalPort = (default $port.port $port.targetPort) -}} + {{- else if eq $svcType "NodePort" -}} + {{- $portalPort = $port.nodePort -}} + {{- else if eq $svcType "LoadBalancer" -}} + {{- $portalPort = $port.port -}} + {{- end -}} + + {{/* If ingress is added at any point, here is the place to implement */}} + + {{/* Check if there are any overrides in .Values.portal */}} + {{- range $name, $portalSvc := $root.Values.portal -}} + {{- if eq $svcName $name -}} + {{- range $name, $portalPort := $portalSvc -}} + {{- if eq $portName $name -}} + {{- with $portalPort.port -}} + {{- $portalPort = (tpl . $root) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end }} +{{ $portalPort }} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/portal/_protocol.tpl b/library/common/1.0.0/templates/lib/portal/_protocol.tpl new file mode 100644 index 0000000000..5ed073e8f5 --- /dev/null +++ b/library/common/1.0.0/templates/lib/portal/_protocol.tpl @@ -0,0 +1,31 @@ +{{- define "ix.v1.common.portal.protocol" -}} + {{- $svcType := .svcType -}} + {{- $svcName := .svcName -}} + {{- $portName := .portName -}} + {{- $port := .port -}} + {{- $root := .root -}} + + {{- $portalProtocol := "http" -}} + + {{- if $port.protocol -}} + {{- if (has $port.protocol (list "HTTP" "HTTPS")) -}} + {{ $portalProtocol = ($port.protocol | lower) }} + {{- end -}} + {{- end -}} + + {{/* If ingress is added at any point, here is the place to implement */}} + + {{/* Check if there are any overrides in .Values.portal */}} + {{- range $name, $portalSvc := $root.Values.portal -}} + {{- if eq $svcName $name -}} + {{- range $name, $portalPort := $portalSvc -}} + {{- if eq $portName $name -}} + {{- with $portalPort.protocol -}} + {{- $portalProtocol = (tpl . $root) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end }} +{{ $portalProtocol }} +{{- end -}} diff --git a/library/common/1.0.0/templates/loader/_apply.tpl b/library/common/1.0.0/templates/loader/_apply.tpl index 58b6f56633..3e3931ea6d 100644 --- a/library/common/1.0.0/templates/loader/_apply.tpl +++ b/library/common/1.0.0/templates/loader/_apply.tpl @@ -21,4 +21,6 @@ {{- include "ix.v1.common.spawner.service" . | nindent 0 -}} {{- include "ix.v1.common.spawner.pvc" . | nindent 0 -}} + + {{- include "ix.v1.common.spawner.portal" . | nindent 0 -}} {{- end -}} diff --git a/library/common/1.0.0/templates/spawner/_portal.tpl b/library/common/1.0.0/templates/spawner/_portal.tpl new file mode 100644 index 0000000000..63f85d3669 --- /dev/null +++ b/library/common/1.0.0/templates/spawner/_portal.tpl @@ -0,0 +1,7 @@ +{{- define "ix.v1.common.spawner.portal" -}} + {{- if .Values.portal -}} + {{- if .Values.portal.enabled -}} + {{- include "ix.v1.common.class.portal" (dict "root" $) -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/library/common/1.0.0/values.yaml b/library/common/1.0.0/values.yaml index 5b6ce90e38..18b61738cf 100644 --- a/library/common/1.0.0/values.yaml +++ b/library/common/1.0.0/values.yaml @@ -147,6 +147,16 @@ global: annotations: {} labels: {} +portal: + # Whether to generate portal configMaps + enabled: true + # main: + # main: + # path: /somepath + # port: 123 + # protocol: http + # host: blabla + nameOverride: "" fullnameOverride: ""