This commit is contained in:
Stavros kois
2023-02-05 13:12:12 +02:00
parent cd65e0574a
commit 86396a529d
4 changed files with 95 additions and 3 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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:

View File

@@ -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 -}}