From ee1c48a1af690c3387e2c96bfebc820ab3b5cbbc Mon Sep 17 00:00:00 2001 From: Kjeld Schouten-Lebbing Date: Sun, 9 Apr 2023 11:55:24 +0200 Subject: [PATCH] fix(common): Chartcontextfixes (#376) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** There are still some things needed to have clean chartContext output. **โš™๏ธ Type of change** - [ ] โš™๏ธ Feature/App addition - [ ] ๐Ÿช› Bugfix - [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] ๐Ÿ”ƒ Refactor of current code **๐Ÿงช How Has This Been Tested?** **๐Ÿ“ƒ Notes:** **โœ”๏ธ Checklist:** - [ ] โš–๏ธ My code follows the style guidelines of this project - [ ] ๐Ÿ‘€ I have performed a self-review of my own code - [ ] #๏ธโƒฃ I have commented my code, particularly in hard-to-understand areas - [ ] ๐Ÿ“„ I have made corresponding changes to the documentation - [ ] โš ๏ธ My changes generate no new warnings - [ ] ๐Ÿงช I have added tests to this description that prove my fix is effective or that my feature works - [ ] โฌ†๏ธ I increased versions for any altered app according to semantic versioning **โž• App addition** If this PR is an app addition please make sure you have done the following. - [ ] ๐Ÿชž I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] ๐Ÿ–ผ๏ธ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Co-authored-by: Stavros kois Co-authored-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> --- library/common-test/Chart.yaml | 2 +- .../templates/lib/util/_chartcontext.tpl | 103 +++++++++--------- library/common/templates/spawner/_ingress.tpl | 2 + library/common/values.yaml | 3 + 4 files changed, 56 insertions(+), 54 deletions(-) diff --git a/library/common-test/Chart.yaml b/library/common-test/Chart.yaml index 69d230cf..9e6ec1a4 100644 --- a/library/common-test/Chart.yaml +++ b/library/common-test/Chart.yaml @@ -3,7 +3,7 @@ appVersion: "" dependencies: - name: common repository: file://../common - version: ~12.3.0 + version: ~12.4.0 deprecated: false description: Helper chart to test different use cases of the common library home: https://github.com/truecharts/apps/tree/master/charts/library/common-test diff --git a/library/common/templates/lib/util/_chartcontext.tpl b/library/common/templates/lib/util/_chartcontext.tpl index fc888e10..92a28802 100644 --- a/library/common/templates/lib/util/_chartcontext.tpl +++ b/library/common/templates/lib/util/_chartcontext.tpl @@ -2,21 +2,20 @@ {{- define "tc.v1.common.lib.util.chartcontext" -}} {{/* Create defaults */}} {{- $protocol := "https" -}} - {{- $host := "$node_ip" -}} + {{- $host := "127.0.0.1" -}} {{- $port := "443" -}} {{- $url := "" -}} {{- $podCIDR := "172.16.0.0/16" -}} - {{- $svcCIDR := "172.17.0.0/16" -}} + {{- $svcCIDR := "172.17.0.0/16" -}} {{/* set temporary storage for ingress name and port */}} {{- $targetIngress := "" -}} {{- $selectedIngress := "" -}} - {{/* Get service, default to primary */}} - {{- $selectedService := fromYaml ( include "tc.v1.common.lib.helpers.getSelectedServiceValues" (dict "rootCtx" $ )) }} + {{- $selectedService := fromYaml (include "tc.v1.common.lib.helpers.getSelectedServiceValues" (dict "rootCtx" $ )) -}} - {{/* read loadbalancer IP's for metallb */}} + {{/* read loadbalancer IPs for metallb */}} {{- if eq $selectedService.type "LoadBalancer" -}} {{- with $selectedService.loadBalancerIP -}} {{- $host = toString . -}} @@ -26,41 +25,41 @@ {{- $targetPort := "" -}} {{- $selectedPort := "" -}} {{/* Fetch port values */}} - {{- $targetPort = include "tc.v1.common.lib.util.service.ports.primary" (dict "svcName" $selectedService.shortName "svcValues" $selectedService ) -}} + {{- $targetPort = include "tc.v1.common.lib.util.service.ports.primary" (dict "svcName" $selectedService.shortName "svcValues" $selectedService) -}} {{- $selectedPort = get $selectedService.ports $targetPort -}} {{/* store port number */}} {{- $port = $selectedPort.port -}} {{- end -}} {{/* Fetch ingress values */}} - {{- $targetIngress = ( include "tc.v1.common.lib.util.ingress.primary" $ ) -}} + {{- $targetIngress = include "tc.v1.common.lib.util.ingress.primary" $ -}} {{- $selectedIngress = get $.Values.ingress $targetIngress -}} {{/* store host from ingress number */}} {{- if $selectedIngress -}} {{- if $selectedIngress.enabled -}} - {{- with (index $selectedIngress.hosts 0) }} + {{- with (index $selectedIngress.hosts 0) -}} {{- $host = .host -}} - {{- end }} + {{- end -}} {{/* Get the port for the ingress entrypoint */}} - {{- $namespace := "tc-system" }} - {{- if $selectedIngress.ingressClassName }} - {{- $namespace := ( printf "ix-%s" $selectedIngress.ingressClassName ) }} - {{- end }} - {{- $traefikportalhook := lookup "v1" "ConfigMap" $namespace "portalhook" }} - {{- $entrypoint := "websecure" }} - {{- if $selectedIngress.entrypoint }} - {{- $entrypoint = $selectedIngress.entrypoint }} - {{- end }} - {{- if $traefikportalhook }} - {{- if ( index $traefikportalhook.data $entrypoint ) }} - {{- $port = ( index $traefikportalhook.data $entrypoint ) }} - {{- end }} - {{- end }} - {{- end }} - {{- end }} + {{- $namespace := "tc-system" -}} + {{- if $selectedIngress.ingressClassName -}} + {{- $namespace = (printf "ix-%s" $selectedIngress.ingressClassName) -}} + {{- end -}} + {{- $traefikportalhook := lookup "v1" "ConfigMap" $namespace "portalhook" -}} + {{- $entrypoint := "websecure" -}} + {{- if $selectedIngress.entrypoint -}} + {{- $entrypoint = $selectedIngress.entrypoint -}} + {{- end -}} + {{- if $traefikportalhook -}} + {{- if (index $traefikportalhook.data $entrypoint) -}} + {{- $port = (index $traefikportalhook.data $entrypoint) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} - {{- $port = ( toString $port ) -}} + {{- $port = toString $port -}} {{/* sanitise */}} {{- if eq $port "443" -}} @@ -71,44 +70,42 @@ {{- $protocol = "http" -}} {{- end -}} - {{- if or ( and ( eq $protocol "https" ) ( eq $port "443" ) ) ( and ( eq $protocol "http" ) ( eq $port "80" ) ) -}} + {{- if or (and (eq $protocol "https") (eq $port "443")) (and (eq $protocol "http") (eq $port "80")) -}} {{- $port = "" -}} {{- end -}} - {{- $port = toString $port -}} - {{/* Construct URL*/}} {{- if $port -}} - {{- $url = printf "%s://%s:%s%s" $protocol $host $port -}} + {{- $url = printf "%s://%s:%s" $protocol $host $port -}} {{- else -}} - {{- $url = printf "%s://%s%s" $protocol $host -}} + {{- $url = printf "%s://%s" $protocol $host -}} {{- end -}} {{/* TrueNAS SCALE specific code */}} {{- if $.Values.ixChartContext -}} - {{- if $.Values.ixChartContext.kubernetes_config -}} - {{- $podCIDR = $.Values.ixChartContext.kubernetes_config.cluster_cidr -}} - {{- $svcCIDR = $.Values.ixChartContext.kubernetes_config.service_cidr -}} - {{- end -}} - {{- else -}} - {{/* TODO: Find ways to implement CIDR detection */}} - {{- end -}} + {{- if $.Values.ixChartContext.kubernetes_config -}} + {{- $podCIDR = $.Values.ixChartContext.kubernetes_config.cluster_cidr -}} + {{- $svcCIDR = $.Values.ixChartContext.kubernetes_config.service_cidr -}} + {{- end -}} + {{- else -}} + {{/* TODO: Find ways to implement CIDR detection */}} + {{- end -}} - {{- if $.Values.chartContext -}} - {{- if $.Values.chartContext.APPURL -}} - {{- $url = $.Values.chartContext.APPURL -}} - {{- end -}} - - {{- if $.Values.chartContext.podCIDR -}} - {{- $podCIDR = $.Values.chartContext.podCIDR -}} - {{- end -}} - - {{- if $.Values.chartContext.svcCIDR -}} - {{- $svcCIDR = $.Values.chartContext.svcCIDR -}} - {{- end -}} + {{- if $.Values.chartContext -}} + {{- if $.Values.chartContext.APPURL -}} + {{- $url = $.Values.chartContext.APPURL -}} {{- end -}} - {{- $_ := set $.Values.chartContext "APPURL" $url -}} - {{- $_ := set $.Values.chartContext "podCIDR" $podCIDR -}} - {{- $_ := set $.Values.chartContext "svcCIDR" $svcCIDR -}} + {{- if $.Values.chartContext.podCIDR -}} + {{- $podCIDR = $.Values.chartContext.podCIDR -}} + {{- end -}} + + {{- if $.Values.chartContext.svcCIDR -}} + {{- $svcCIDR = $.Values.chartContext.svcCIDR -}} + {{- end -}} + {{- end -}} + + {{- $_ := set $.Values.chartContext "APPURL" $url -}} + {{- $_ := set $.Values.chartContext "podCIDR" $podCIDR -}} + {{- $_ := set $.Values.chartContext "svcCIDR" $svcCIDR -}} {{- end -}} diff --git a/library/common/templates/spawner/_ingress.tpl b/library/common/templates/spawner/_ingress.tpl index 8dee64ab..8b45d26f 100644 --- a/library/common/templates/spawner/_ingress.tpl +++ b/library/common/templates/spawner/_ingress.tpl @@ -53,6 +53,8 @@ {{- end -}} {{- end -}} {{- end -}} + {{- else if $ingress.required -}} + {{- fail (printf "Ingress - is set to be [required] and cannot be disabled" $name) -}} {{- end -}} {{- end -}} {{- end -}} diff --git a/library/common/values.yaml b/library/common/values.yaml index 195cfa15..a22f476c 100644 --- a/library/common/values.yaml +++ b/library/common/values.yaml @@ -397,6 +397,9 @@ ingress: # If there is more than 1 ingress, make sure that only 1 ingress is marked as primary. primary: true + # -- Ensure this ingress is always enabled. + required: false + # -- Override the name suffix that is used for this ingress. nameOverride: