diff --git a/charts/library/common-test/tests/ingress/homepage_test.yaml b/charts/library/common-test/tests/ingress/homepage_test.yaml index d7a587f40ba9..a6918ec7a942 100644 --- a/charts/library/common-test/tests/ingress/homepage_test.yaml +++ b/charts/library/common-test/tests/ingress/homepage_test.yaml @@ -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: @@ -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 diff --git a/charts/library/common-test/tests/ingress/rules_test.yaml b/charts/library/common-test/tests/ingress/rules_test.yaml index 2b36ef01bdb4..6fc4ee3e5cc8 100644 --- a/charts/library/common-test/tests/ingress/rules_test.yaml +++ b/charts/library/common-test/tests/ingress/rules_test.yaml @@ -208,6 +208,7 @@ tests: overrideService: name: other-service port: 8080 + - host: host-no-paths integrations: *integrations asserts: - documentIndex: &ingressDoc 2 @@ -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 diff --git a/charts/library/common/templates/class/_ingress.tpl b/charts/library/common/templates/class/_ingress.tpl index 1880739dab42..2125528b26ed 100644 --- a/charts/library/common/templates/class/_ingress.tpl +++ b/charts/library/common/templates/class/_ingress.tpl @@ -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) -}} @@ -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 }}