diff --git a/library/common-test/tests/service/external_ip_test.yaml b/library/common-test/tests/service/external_ip_test.yaml index 1e60c317..4489a371 100644 --- a/library/common-test/tests/service/external_ip_test.yaml +++ b/library/common-test/tests/service/external_ip_test.yaml @@ -143,3 +143,56 @@ tests: value: - addresses: - 1.1.1.1 + + - it: should pass with type ExternalIP and https + set: + service: + my-service: + enabled: true + primary: true + type: ExternalIP + externalIP: 1.1.1.1 + ports: + port-name: + enabled: true + primary: true + port: 443 + protocol: https + asserts: + - documentIndex: *serviceDoc + equal: + path: spec + value: + publishNotReadyAddresses: false + ports: + - name: port-name + port: 443 + protocol: TCP + targetPort: 443 + - documentIndex: &endpointSliceDoc 1 + isKind: + of: EndpointSlice + - documentIndex: *endpointSliceDoc + isAPIVersion: + of: discovery.k8s.io/v1 + - documentIndex: *endpointSliceDoc + equal: + path: ports + value: + - name: port-name + port: 443 + protocol: TCP + - documentIndex: *endpointSliceDoc + equal: + path: endpoints + value: + - addresses: + - 1.1.1.1 + - documentIndex: &serviceDoc 0 + isKind: + of: Service + - documentIndex: *serviceDoc + isSubset: + path: metadata.annotations + content: + traefik.ingress.kubernetes.io/service.serversscheme: https diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 17c18316..27b0191b 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 12.4.13 +version: 12.4.14 diff --git a/library/common/templates/class/_service.tpl b/library/common/templates/class/_service.tpl index 406d5df8..02ebe44f 100644 --- a/library/common/templates/class/_service.tpl +++ b/library/common/templates/class/_service.tpl @@ -19,6 +19,18 @@ objectData: The service data, that will be used to render the Service object. {{- $hostNetwork := false -}} {{- $podValues := dict -}} + {{- range $portName, $port := $objectData.ports -}} + {{- if $port.enabled -}} + {{- if eq (tpl ($port.protocol | default "") $rootCtx) "https" -}} + {{- $hasHTTPSPort = true -}} + {{- end -}} + + {{- if and (hasKey $port "hostPort") $port.hostPort -}} + {{- $hasHostPort = true -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- $specialTypes := (list "ExternalName" "ExternalIP") -}} {{/* External Name / External IP does not rely on any pod values */}} {{- if not (mustHas $svcType $specialTypes) -}} @@ -34,18 +46,6 @@ objectData: The service data, that will be used to render the Service object. {{- end -}} {{- end -}} - {{- range $portName, $port := $objectData.ports -}} - {{- if $port.enabled -}} - {{- if eq (tpl ($port.protocol | default "") $rootCtx) "https" -}} - {{- $hasHTTPSPort = true -}} - {{- end -}} - - {{- if and (hasKey $port "hostPort") $port.hostPort -}} - {{- $hasHostPort = true -}} - {{- end -}} - {{- end -}} - {{- end -}} - {{/* When hostPort is defined, force ClusterIP aswell */}} {{- if $hasHostPort -}} {{- $svcType = "ClusterIP" -}} diff --git a/library/common/templates/helpers/_getPortRange.tpl b/library/common/templates/helpers/_getPortRange.tpl index f31b64c9..8127fc5d 100644 --- a/library/common/templates/helpers/_getPortRange.tpl +++ b/library/common/templates/helpers/_getPortRange.tpl @@ -38,15 +38,14 @@ objectData: The object data to be used to render the Pod. {{- $portToCheck := ($portValues.targetPort | default $portValues.port) -}} {{- if kindIs "string" $portToCheck -}} - {{/* Helm stores ints as floats, so convert string to float before comparing */}} - {{- $portToCheck = (tpl $portToCheck $rootCtx) | float64 -}} + {{- $portToCheck = (tpl $portToCheck $rootCtx) | int -}} {{- end -}} - {{- if or (not $portRange.low) (lt $portToCheck ($portRange.low | float64)) -}} + {{- if or (not $portRange.low) (lt ($portToCheck | int) ($portRange.low | int)) -}} {{- $_ := set $portRange "low" $portToCheck -}} {{- end -}} - {{- if or (not $portRange.high) (gt $portToCheck ($portRange.high | float64)) -}} + {{- if or (not $portRange.high) (gt ($portToCheck | int) ($portRange.high | int)) -}} {{- $_ := set $portRange "high" $portToCheck -}} {{- end -}}