diff --git a/library/common-test/tests/service/load_balancer_test.yaml b/library/common-test/tests/service/load_balancer_test.yaml index b0484491c0..66b2af8fab 100644 --- a/library/common-test/tests/service/load_balancer_test.yaml +++ b/library/common-test/tests/service/load_balancer_test.yaml @@ -41,6 +41,7 @@ tests: some_ip: 172.16.20.35 some_other_ip: 10.100.200.45 some_range: 11.100.200.0/24 + some_family: IPv6 service: my-service: enabled: true @@ -55,7 +56,7 @@ tests: ipFamilyPolicy: PreferDualStack ipFamilies: - IPv4 - - IPv6 + - "{{ .Values.some_family }}" ports: port-name: enabled: true diff --git a/library/common-test/tests/service/node_port_test.yaml b/library/common-test/tests/service/node_port_test.yaml new file mode 100644 index 0000000000..9d2428dbc9 --- /dev/null +++ b/library/common-test/tests/service/node_port_test.yaml @@ -0,0 +1,75 @@ +suite: service nodePort test +templates: + - common.yaml +tests: + - it: should pass with type nodePort + set: + service: + my-service: + enabled: true + primary: true + type: NodePort + ports: + port-name: + enabled: true + primary: true + workload: + my-workload: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: &serviceDoc 1 + isKind: + of: Service + - documentIndex: *serviceDoc + isAPIVersion: + of: v1 + - documentIndex: *serviceDoc + equal: + path: metadata.name + value: release-name-common-test + - documentIndex: *serviceDoc + equal: + path: spec + value: + type: NodePort + + - it: should pass with type NodePort and available options set + set: + some_ip: 172.16.20.35 + some_family: IPv6 + service: + my-service: + enabled: true + primary: true + type: NodePort + clusterIP: "{{ .Values.some_ip }}" + externalTrafficPolicy: Local + ipFamilyPolicy: PreferDualStack + ipFamilies: + - IPv4 + - "{{ .Values.some_family }}" + ports: + port-name: + enabled: true + primary: true + workload: + my-workload: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: *serviceDoc + equal: + path: spec + value: + type: NodePort + clusterIP: 172.16.20.35 + externalTrafficPolicy: Local + ipFamilyPolicy: PreferDualStack + ipFamilies: + - IPv4 + - IPv6 diff --git a/library/common/1.0.0/templates/classes/_service.tpl b/library/common/1.0.0/templates/classes/_service.tpl index 958759e13d..c7a3b55200 100644 --- a/library/common/1.0.0/templates/classes/_service.tpl +++ b/library/common/1.0.0/templates/classes/_service.tpl @@ -12,8 +12,6 @@ objectData: The service data, that will be used to render the Service object. {{- $objectData := .objectData -}} {{- $svcType := $objectData.type | default "ClusterIP" -}} - {{/* Expand svcType in case it has tpl */}} - {{- $svcType = (tpl $svcType $rootCtx) -}} {{/* Get Pod Values based on the selector (or the absence of it) */}} {{- $podValues := fromJson (include "ix.v1.common.lib.service.getSelectedPodValues" (dict "rootCtx" $rootCtx "objectData" $objectData)) -}} @@ -72,6 +70,8 @@ spec: {{- include "ix.v1.common.lib.service.spec.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }} {{- else if eq $svcType "LoadBalancer" -}} {{- include "ix.v1.common.lib.service.spec.loadBalancer" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }} + {{- else if eq $svcType "NodePort" -}} + {{- include "ix.v1.common.lib.service.spec.nodePort" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }} {{- end }} {{- if not (mustHas $svcType (list "ExternalName" "ExternalIP")) }} selector: diff --git a/library/common/1.0.0/templates/lib/service/serviceTypeSpecs/_nodePort.tpl b/library/common/1.0.0/templates/lib/service/serviceTypeSpecs/_nodePort.tpl new file mode 100644 index 0000000000..bc68a349e3 --- /dev/null +++ b/library/common/1.0.0/templates/lib/service/serviceTypeSpecs/_nodePort.tpl @@ -0,0 +1,16 @@ +{{/* Service - NodePort Spec */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.service.spec.nodePort" (dict "rootCtx" $rootCtx "objectData" $objectData) -}} +rootCtx: The root context of the service +objectData: The service object data +*/}} + +{{- define "ix.v1.common.lib.service.spec.nodePort" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData }} + +type: NodePort + {{- include "ix.v1.common.lib.service.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }} + {{- include "ix.v1.common.lib.service.ipFamily" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }} + {{- include "ix.v1.common.lib.service.externalTrafficPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }} +{{- end -}}