initial portal work

This commit is contained in:
Stavros kois
2022-12-07 18:00:40 +02:00
parent 49046be60a
commit 59a581ed26
8 changed files with 171 additions and 0 deletions

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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 -}}

View File

@@ -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: ""