diff --git a/library/common-test/tests/ingress/rules_test.yaml b/library/common-test/tests/ingress/rules_test.yaml index dd78b5f2..49d4a4ae 100644 --- a/library/common-test/tests/ingress/rules_test.yaml +++ b/library/common-test/tests/ingress/rules_test.yaml @@ -82,6 +82,10 @@ tests: # must be just the fullname name: my-service port: 8080 + - host: "host-without-explicit-paths" + - host: "host-without-explicit-path" + paths: + - pathPrefix: Exact integrations: *integrations asserts: - documentIndex: &ingressDoc 1 @@ -132,6 +136,26 @@ tests: name: test-release-name-common-test port: number: 8080 + - host: "host-without-explicit-paths" + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: test-release-name-common-test + port: + number: 80 + - host: "host-without-explicit-path" + http: + paths: + - path: / + pathType: Exact + backend: + service: + name: test-release-name-common-test + port: + number: 80 - it: should pass with ingress created with rules with targetSelector set: diff --git a/library/common-test/tests/ingress/validation_test.yaml b/library/common-test/tests/ingress/validation_test.yaml index eaa0af62..72dbb2d9 100644 --- a/library/common-test/tests/ingress/validation_test.yaml +++ b/library/common-test/tests/ingress/validation_test.yaml @@ -70,8 +70,8 @@ tests: integrations: &integrations traefik: enabled: false - my-ingress-super-long-name-that-is-longer-than-253-characters-my-ingress-super-long-name-that-is-longer-than-253-characters-my-ingress-super-long-name-that-is-longer-than-253-characters-my-ingress-super-long-long-long-long-long-long-long-long-name: - enabled: true + ? my-ingress-super-long-name-that-is-longer-than-253-characters-my-ingress-super-long-name-that-is-longer-than-253-characters-my-ingress-super-long-name-that-is-longer-than-253-characters-my-ingress-super-long-long-long-long-long-long-long-long-name + : enabled: true asserts: - failedTemplate: errorMessage: Name [test-release-name-common-test-my-ingress-super-long-name-that-is-longer-than-253-characters-my-ingress-super-long-name-that-is-longer-than-253-characters-my-ingress-super-long-name-that-is-longer-than-253-characters-my-ingress-super-long-long-long-long-long-long-long-long-name] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 253 characters. @@ -287,18 +287,6 @@ tests: - failedTemplate: errorMessage: Ingress - Expected [hosts.host] to not contain [:], but got [test-host:123] - - it: should fail without paths - set: - ingress: - my-ingress: - enabled: true - primary: true - hosts: - - host: test-host - asserts: - - failedTemplate: - errorMessage: Ingress - Expected non-empty [hosts.paths] - - it: should fail with paths not a slice set: ingress: @@ -521,7 +509,7 @@ tests: hosts: *hosts tls: - hosts: - - "" + - "" asserts: - failedTemplate: errorMessage: Ingress - Expected non-empty entry in [tls.hosts] @@ -536,7 +524,7 @@ tests: hosts: *hosts tls: - hosts: - - https://test-host + - https://test-host asserts: - failedTemplate: errorMessage: Ingress - Expected entry in [tls.hosts] to not start with [https://], but got [https://test-host] @@ -551,7 +539,7 @@ tests: hosts: *hosts tls: - hosts: - - http://test-host + - http://test-host asserts: - failedTemplate: errorMessage: Ingress - Expected entry in [tls.hosts] to not start with [http://], but got [http://test-host] @@ -566,7 +554,7 @@ tests: hosts: *hosts tls: - hosts: - - test-host:123 + - test-host:123 asserts: - failedTemplate: errorMessage: Ingress - Expected entry in [tls.hosts] to not contain [:], but got [test-host:123] @@ -581,7 +569,7 @@ tests: hosts: *hosts tls: - hosts: - - test-host + - test-host secretName: test-secret clusterCertificate: some-cert asserts: diff --git a/library/common/templates/class/_ingress.tpl b/library/common/templates/class/_ingress.tpl index 553cbea8..46e48a3c 100644 --- a/library/common/templates/class/_ingress.tpl +++ b/library/common/templates/class/_ingress.tpl @@ -60,11 +60,14 @@ spec: - host: {{ (tpl $h.host $rootCtx) | quote }} http: paths: + {{- if not $h.paths -}} {{/* If no paths given, default to "/" */}} + {{- $_ := set $h "paths" (dict "path" "/") -}} + {{- end -}} {{- range $p := $h.paths -}} {{- $svcData = (include "tc.v1.common.lib.ingress.backend.data" (dict "rootCtx" $rootCtx "svcData" $svcData "override" $p.overrideService)) | fromYaml }} - - path: {{ tpl $p.path $rootCtx }} + - path: {{ (tpl $p.path $rootCtx) | default "/" }} pathType: {{ tpl ($p.pathType | default "Prefix") $rootCtx }} backend: service: diff --git a/library/common/templates/lib/ingress/_validation.tpl b/library/common/templates/lib/ingress/_validation.tpl index db4a3cf3..d4e5b3d0 100644 --- a/library/common/templates/lib/ingress/_validation.tpl +++ b/library/common/templates/lib/ingress/_validation.tpl @@ -62,11 +62,7 @@ objectData: {{- fail (printf "Ingress - Expected [hosts.host] to not contain [:], but got [%s]" $host) -}} {{- end -}} - {{- if not $h.paths -}} - {{- fail "Ingress - Expected non-empty [hosts.paths]" -}} - {{- end -}} - - {{- if not (kindIs "slice" $h.paths) -}} + {{- if and $h.paths (not (kindIs "slice" $h.paths)) -}} {{- fail (printf "Ingress - Expected [hosts.paths] to be a [slice], but got [%s]" (kindOf $h.paths)) -}} {{- end -}} @@ -84,7 +80,7 @@ objectData: {{- $path := tpl $p.path $rootCtx -}} {{- $prefixSlashTypes := (list "Prefix" "Exact") -}} {{- if (mustHas $pathType $prefixSlashTypes) -}} - {{- if not (hasPrefix "/" $path) -}} + {{- if and $path (not (hasPrefix "/" $path)) -}} {{- fail (printf "Ingress - Expected [hosts.paths.path] to start with [/], but got [%s]" $path) -}} {{- end -}} {{- end -}}