Skip to content

Commit

Permalink
chore(common): normalize ingress paths earlier (#29817)
Browse files Browse the repository at this point in the history
**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes  # <!--(issue)-->

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [ ] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [x] 🔃 Refactor of current code

**🧪 How Has This Been Tested?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ Checklist:**

- [x] ⚖️ My code follows the style guidelines of this project
- [x] 👀 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
- [x] ⚠️ My changes generate no new warnings
- [x] 🧪 I have added tests to this description that prove my fix is
effective or that my feature works
- [x] ⬆️ I increased versions for any altered app according to semantic
versioning
- [x] I made sure the title starts with `feat(chart-name):`,
`fix(chart-name):` or `chore(chart-name):`

**➕ 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._
  • Loading branch information
stavros-k authored Dec 10, 2024
1 parent a896a6e commit 7ea9dcf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
21 changes: 21 additions & 0 deletions charts/library/common-test/tests/ingress/homepage_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ tests:
value: some-other-value-slice
- key: some-empty-key-slice
value: ""
my-ingress5:
enabled: true
integrations:
traefik: *traefik
homepage:
enabled: true
hosts:
- host: no-paths-host
asserts:
- documentIndex: &ingressDoc 2
isKind:
Expand Down Expand Up @@ -207,6 +215,19 @@ tests:
gethomepage.dev/href: https://test-host/test-path
gethomepage.dev/icon: https://truecharts.org/img/hotlink-ok/chart-icons/common-test.webp
gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name,pod.lifecycle in (permanent)
- documentIndex: &fifthIngressDoc 6
isKind:
of: Ingress
- documentIndex: *fifthIngressDoc
isSubset:
path: metadata.annotations
content:
gethomepage.dev/enabled: "true"
gethomepage.dev/name: TestReleaseName
gethomepage.dev/description: Helper chart to test different use cases of the common library
gethomepage.dev/href: https://no-paths-host/
gethomepage.dev/icon: https://truecharts.org/img/hotlink-ok/chart-icons/common-test.webp
gethomepage.dev/pod-selector: app.kubernetes.io/instance=test-release-name,pod.lifecycle in (permanent)

# Failures
- it: should fail with podSelector not a slice
Expand Down
12 changes: 12 additions & 0 deletions charts/library/common-test/tests/ingress/rules_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ tests:
overrideService:
name: other-service
port: 8080
- host: host-no-paths
integrations: *integrations
asserts:
- documentIndex: &ingressDoc 2
Expand Down Expand Up @@ -248,3 +249,14 @@ tests:
name: test-release-name-common-test-other-service
port:
number: 8080

- host: host-no-paths
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: test-release-name-common-test-my-service2
port:
number: 9000
22 changes: 16 additions & 6 deletions charts/library/common/templates/class/_ingress.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ objectData: The object data to be used to render the Ingress.
{{- $ingressClassName = (tpl $objectData.ingressClassName $rootCtx) -}}
{{- end -}}

{{- range $h := $objectData.hosts -}}
{{- $_ := set $h "host" (tpl $h.host $rootCtx) -}}

{{- if not $h.paths -}} {{/* If no paths given, default to "/" */}}
{{- $_ := set $h "paths" (list (dict "path" "/")) -}}
{{- end -}}

{{- range $p := $h.paths -}}
{{- $_ := set $p "path" (tpl ($p.path | default "/") $rootCtx) -}}
{{- $_ := set $p "pathType" (tpl ($p.pathType | default "Prefix") $rootCtx) -}}
{{- end -}}
{{- end -}}

{{/* When Stop All is set, force ingressClass "stopped"
to yeet ingress from the ingresscontroller */}}
{{- if (include "tc.v1.common.lib.util.stopAll" $rootCtx) -}}
Expand Down Expand Up @@ -59,18 +72,15 @@ spec:
ingressClassName: {{ $ingressClassName | default nil }}
rules:
{{- range $h := $objectData.hosts }}
- host: {{ (tpl $h.host $rootCtx) | quote }}
- host: {{ $h.host | quote }}
http:
paths:
{{- if not $h.paths -}} {{/* If no paths given, default to "/" */}}
{{- $_ := set $h "paths" (list (dict "path" "/")) -}}
{{- end -}}
{{- range $p := $h.paths -}}
{{- $newSvcData := (include "tc.v1.common.lib.ingress.backend.data" (dict
"rootCtx" $rootCtx "svcData" $svcData "override" $p.overrideService)) | fromYaml
}}
- path: {{ tpl ($p.path | default "/") $rootCtx }}
pathType: {{ tpl ($p.pathType | default "Prefix") $rootCtx }}
- path: {{ $p.path }}
pathType: {{ $p.pathType }}
backend:
service:
name: {{ $newSvcData.name }}
Expand Down

0 comments on commit 7ea9dcf

Please sign in to comment.