From e014dc220beb293fa6adf563398bf2025fae232d Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Mon, 21 Apr 2025 18:06:38 +0200 Subject: [PATCH] feat(common): list internal urls in notes.txt (#34048) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** This renders a line in notes.txt for each service-port combo. That way users have an easy representation of how they can connect things internally without needing to guess/know/calculate the url themselves. ⚒️ Fixes #31882 **⚙️ Type of change** - [x] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code - [ ] 📜 Documentation Changes **🧪 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 changes to the documentation - [ ] 🧪 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 - [ ] I made sure the title starts with `feat(chart-name):`, `fix(chart-name):`, `chore(chart-name):`, `docs(chart-name):` or `fix(docs):` **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🖼️ 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._ --------- Signed-off-by: Kjeld Schouten Signed-off-by: Alfred Göppel <43101280+alfi0812@users.noreply.github.com> Co-authored-by: Alfred Göppel <43101280+alfi0812@users.noreply.github.com> Co-authored-by: Stavros Kois --- charts/library/common/Chart.yaml | 3 +- .../common/templates/spawner/_service.tpl | 80 +++++++++++-------- charts/library/common/values.yaml | 10 +++ 3 files changed, 58 insertions(+), 35 deletions(-) diff --git a/charts/library/common/Chart.yaml b/charts/library/common/Chart.yaml index 2220e23172b..99c7c19a02b 100644 --- a/charts/library/common/Chart.yaml +++ b/charts/library/common/Chart.yaml @@ -48,5 +48,4 @@ sources: - https://hub.docker.com/_/ - https://hub.docker.com/r/mikefarah/yq type: library -version: 28.2.4 - +version: 28.3.0 diff --git a/charts/library/common/templates/spawner/_service.tpl b/charts/library/common/templates/spawner/_service.tpl index b9f84703050..8d03e8b478b 100644 --- a/charts/library/common/templates/spawner/_service.tpl +++ b/charts/library/common/templates/spawner/_service.tpl @@ -8,6 +8,8 @@ {{/* Primary validation for enabled service. */}} {{- include "tc.v1.common.lib.service.primaryValidation" $ -}} + {{/* Initialize with existing URLs or an empty list */}} + {{- $allUrls := $.Values.chartContext.internalUrls | default list -}} {{- range $name, $service := .Values.service -}} {{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict @@ -15,45 +17,57 @@ "name" $name "caller" "Service" "key" "service")) -}} - {{- if eq $enabled "true" -}} + {{- if ne $enabled "true" -}}{{- continue -}}{{- end -}} - {{/* Create a copy of the configmap */}} - {{- $objectData := (mustDeepCopy $service) -}} + {{/* Create a copy of the configmap */}} + {{- $objectData := (mustDeepCopy $service) -}} + {{- $namespace := (include "tc.v1.common.lib.metadata.namespace" (dict "rootCtx" $ "objectData" $service "caller" "Service")) -}} - {{/* Init object name */}} - {{- $objectName := $name -}} + {{/* Init object name */}} + {{- $objectName := $name -}} - {{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict - "rootCtx" $ "objectData" $objectData - "name" $name "caller" "Service" - "key" "service")) -}} - - {{- if eq $expandName "true" -}} - {{/* Expand the name of the service if expandName resolves to true */}} - {{- $objectName = $fullname -}} - {{- end -}} - - {{- if and (eq $expandName "true") (not $objectData.primary) -}} - {{/* If the service is not primary append its name to fullname */}} - {{- $objectName = (printf "%s-%s" $fullname $name) -}} - {{- end -}} - - {{- include "tc.v1.common.lib.util.metaListToDict" (dict "objectData" $objectData) -}} - - {{/* Perform validations */}} - {{- include "tc.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}} - {{- include "tc.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Service") -}} - {{- include "tc.v1.common.lib.service.validation" (dict "rootCtx" $ "objectData" $objectData) -}} - - {{/* Set the name of the service */}} - {{- $_ := set $objectData "name" $objectName -}} - {{- $_ := set $objectData "shortName" $name -}} - - {{/* Call class to create the object */}} - {{- include "tc.v1.common.class.service" (dict "rootCtx" $ "objectData" $objectData) -}} + {{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict + "rootCtx" $ "objectData" $objectData + "name" $name "caller" "Service" + "key" "service")) -}} + {{- if eq $expandName "true" -}} + {{/* Expand the name of the service if expandName resolves to true */}} + {{- $objectName = $fullname -}} {{- end -}} + {{- if and (eq $expandName "true") (not $objectData.primary) -}} + {{/* If the service is not primary append its name to fullname */}} + {{- $objectName = (printf "%s-%s" $fullname $name) -}} + {{- end -}} + + {{- include "tc.v1.common.lib.util.metaListToDict" (dict "objectData" $objectData) -}} + + {{/* Perform validations */}} + {{- include "tc.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}} + {{- include "tc.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" "Service") -}} + {{- include "tc.v1.common.lib.service.validation" (dict "rootCtx" $ "objectData" $objectData) -}} + + {{/* Set the name of the service */}} + {{- $_ := set $objectData "name" $objectName -}} + {{- $_ := set $objectData "shortName" $name -}} + + {{/* Now iterate over the ports in the service */}} + {{- range $port := $service.ports -}} + {{- $enabledP := (include "tc.v1.common.lib.util.enabled" (dict + "rootCtx" $ "objectData" $port + "name" $name "caller" "service" + "key" "port")) -}} + {{- if ne $enabledP "true" -}}{{- continue -}}{{- end -}} + {{- $internalUrl := (printf "%s.%s.svc.cluster.local:%s" $objectName $namespace $port.port) -}} + {{/* Append URLS */}} + {{- $allUrls = mustAppend $allUrls $internalUrl -}} + {{- end -}} + + {{/* Call class to create the object */}} + {{- include "tc.v1.common.class.service" (dict "rootCtx" $ "objectData" $objectData) -}} {{- end -}} + {{/* Update internalUrls after the loop */}} + {{- $_ := set $.Values.chartContext "internalUrls" $allUrls -}} {{- end -}} diff --git a/charts/library/common/values.yaml b/charts/library/common/values.yaml index 3a91580e94d..fe9762e7645 100644 --- a/charts/library/common/values.yaml +++ b/charts/library/common/values.yaml @@ -450,6 +450,16 @@ notes: {{- end }} {{- end }} + + {{- if .Values.chartContext.internalUrls }} + ## Connecting Internally + + You can reach this chart inside your cluster, using the following service URLS: + {{- range $url := .Values.chartContext.internalUrls -}} + - {{ $url }} + {{- end }} + {{- end }} + ## Sources for {{ .Chart.Name }} {{- range .Chart.Sources }}