force ClusterIP when hostPort is defined

This commit is contained in:
Stavros kois
2022-12-05 16:45:40 +02:00
parent 90aae61d3a
commit 430f8f9fb6
2 changed files with 37 additions and 0 deletions

View File

@@ -44,3 +44,30 @@ tests:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: common-test
release: RELEASE-NAME
- it: should pass with hostPort defined, should be forced to ClusterIP
documentIndex: *serviceDoc
set:
service:
main:
type: LoadBalancer
ports:
main:
port: 65535
hostPort: 12345
asserts:
- equal:
path: spec
value:
type: ClusterIP
ports: &defaultPort
- name: main
port: 65535
protocol: TCP
targetPort: main
publishNotReadyAddresses: false
selector: &defaultSelector
app: common-test
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: common-test
release: RELEASE-NAME

View File

@@ -16,6 +16,16 @@
{{- $svcType = "ClusterIP" -}} {{/* When hostNetwork is enabled, force ClusterIP as service type */}}
{{- end -}}
{{/* When hostPort is used, this port can only be assiged to a ClusterIP Service */}}
{{/* If at least one port in a service has hostPort this service will be forced to ClusterIP */}}
{{- range $name, $port := $svcValues.ports -}}
{{- if $port.enabled -}}
{{- if $port.hostPort -}}
{{- $svcType = "ClusterIP" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $primaryPort := get $svcValues.ports (include "ix.v1.common.lib.util.service.ports.primary" (dict "values" $svcValues "svcName" $svcName)) }}
---
apiVersion: {{ include "ix.v1.common.capabilities.service.apiVersion" $root }}