From b0be856963edbdb1d5e9e50998cc3d02fc182deb Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Mon, 25 Dec 2023 14:54:30 +0200 Subject: [PATCH] chore(ingress): expand by default the override name (#657) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** ⚒️ Fixes #16519 When users create custom ingress and set to point to a service, the name must be expanded in order to work, of course a flag to disable the expansion is added (`expandObjectName`) so native helm users can opt out **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [x] ⚠️ 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: Kjeld Schouten --- .../common-test/tests/ingress/rules_test.yaml | 7 +++--- library/common/Chart.yaml | 2 +- library/common/templates/class/_ingress.tpl | 6 ++--- .../templates/lib/ingress/_serviceData.tpl | 22 +++++++++++++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 library/common/templates/lib/ingress/_serviceData.tpl diff --git a/library/common-test/tests/ingress/rules_test.yaml b/library/common-test/tests/ingress/rules_test.yaml index db3c6876..572423a4 100644 --- a/library/common-test/tests/ingress/rules_test.yaml +++ b/library/common-test/tests/ingress/rules_test.yaml @@ -77,7 +77,8 @@ tests: - path: /test-other-path - path: /test-other-path2 overrideService: - name: other-service + name: some-other-service + expandObjectName: false port: 8080 integrations: *integrations asserts: @@ -116,7 +117,7 @@ tests: pathType: Prefix backend: service: - name: other-service + name: some-other-service port: number: 8080 @@ -194,6 +195,6 @@ tests: pathType: Prefix backend: service: - name: other-service + name: test-release-name-common-test-other-service port: number: 8080 diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index cd8eaac2..fcb93695 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 16.2.24 +version: 17.0.0 diff --git a/library/common/templates/class/_ingress.tpl b/library/common/templates/class/_ingress.tpl index ea3f9a11..dd25cda3 100644 --- a/library/common/templates/class/_ingress.tpl +++ b/library/common/templates/class/_ingress.tpl @@ -61,9 +61,9 @@ spec: http: paths: {{- range $p := $h.paths -}} - {{- with $p.overrideService -}} - {{- $svcData = (dict "name" .name "port" .port) -}} - {{- end }} + {{- $svcData = (include "tc.v1.common.lib.ingress.backend.data" (dict + "rootCtx" $rootCtx "svcData" $svcData "override" $p.overrideService)) | fromYaml + }} - path: {{ tpl $p.path $rootCtx }} pathType: {{ tpl ($p.pathType | default "Prefix") $rootCtx }} backend: diff --git a/library/common/templates/lib/ingress/_serviceData.tpl b/library/common/templates/lib/ingress/_serviceData.tpl new file mode 100644 index 00000000..3b66494d --- /dev/null +++ b/library/common/templates/lib/ingress/_serviceData.tpl @@ -0,0 +1,22 @@ +{{- define "tc.v1.common.lib.ingress.backend.data" -}} + {{- $rootCtx := .rootCtx -}} + {{- $svcData := .svcData -}} + {{- $override := .override -}} + + {{- $fullname := include "tc.v1.common.lib.chart.names.fullname" $rootCtx -}} + + {{- with $override -}} + {{- $name := .name -}} + {{- $expandName := (include "tc.v1.common.lib.util.expandName" (dict + "rootCtx" $rootCtx "objectData" . "name" .name + "caller" "Ingress" "key" "overrideService" + )) -}} + + {{- if eq $expandName "true" -}} + {{- $name = (printf "%s-%s" $fullname .name) -}} + {{- end -}} + {{- $svcData = (dict "name" $name "port" .port) -}} + {{- end -}} + + {{- $svcData | toYaml -}} +{{- end -}}