port recent fixes from stavros

This commit is contained in:
Stavros kois
2023-02-23 16:19:23 +02:00
committed by Kjeld Schouten-Lebbing
parent 19eaafbdcc
commit 4ac4cf1de6
2 changed files with 60 additions and 8 deletions

View File

@@ -49,6 +49,56 @@ tests:
app.kubernetes.io/name: common-test
pod.name: my-workload
- it: should pass with type NodePort and hostnetwork enabled
set:
service:
my-service:
enabled: true
primary: true
type: NodePort
ports:
port-name:
enabled: true
primary: true
port: 12345
nodePort: 30000
workload:
my-workload:
enabled: true
primary: true
type: Deployment
podSpec:
hostNetwork: true
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: ClusterIP
publishNotReadyAddresses: false
ports:
- name: port-name
port: 12345
protocol: TCP
targetPort: 12345
selector:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: common-test
pod.name: my-workload
- documentIndex: *serviceDoc
isNull:
path: spec.ports[0].nodePort
- it: should pass with type NodePort and available options set
set:
some_ip: 172.16.20.35

View File

@@ -52,6 +52,8 @@ objectData: The service data, that will be used to render the Service object.
{{- $svcType = "ClusterIP" -}}
{{- end -}}
{{- end }}
{{- end -}}
{{- $_ := set $objectData "type" $svcType }}
---
apiVersion: v1
@@ -65,7 +67,7 @@ metadata:
{{- . | nindent 4 }}
{{- end -}}
{{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "tc.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
{{- if eq $svcType "LoadBalancer" -}}
{{- if eq $objectData.type "LoadBalancer" -}}
{{- include "tc.v1.common.lib.service.metalLBAnnotations" (dict "rootCtx" $rootCtx "objectData" $objectData "annotations" $annotations) -}}
{{- end -}}
{{- if $hasHTTPSPort -}}
@@ -76,26 +78,26 @@ metadata:
{{- . | nindent 4 }}
{{- end }}
spec:
{{- if eq $svcType "ClusterIP" -}}
{{- if eq $objectData.type "ClusterIP" -}}
{{- include "tc.v1.common.lib.service.spec.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 -}}
{{- else if eq $svcType "LoadBalancer" -}}
{{- else if eq $objectData.type "LoadBalancer" -}}
{{- include "tc.v1.common.lib.service.spec.loadBalancer" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 -}}
{{- else if eq $svcType "NodePort" -}}
{{- else if eq $objectData.type "NodePort" -}}
{{- include "tc.v1.common.lib.service.spec.nodePort" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 -}}
{{- else if eq $svcType "ExternalName" -}}
{{- else if eq $objectData.type "ExternalName" -}}
{{- include "tc.v1.common.lib.service.spec.externalName" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 -}}
{{- else if eq $svcType "ExternalIP" -}}
{{- else if eq $objectData.type "ExternalIP" -}}
{{- include "tc.v1.common.lib.service.spec.externalIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 -}}
{{- end -}}
{{- with (include "tc.v1.common.lib.service.ports" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
ports:
{{- . | nindent 4 }}
{{- end -}}
{{- if not (mustHas $svcType $specialTypes) }}
{{- if not (mustHas $objectData.type $specialTypes) }}
selector:
{{- include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" "pod" "objectName" $podValues.shortName) | trim | nindent 4 -}}
{{- end -}}
{{- if eq $svcType "ExternalIP" -}}
{{- if eq $objectData.type "ExternalIP" -}}
{{- include "tc.v1.common.class.endpointSlice" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- end -}}
{{- end -}}