diff --git a/library/common-test/tests/service/cluster_ip_test.yaml b/library/common-test/tests/service/cluster_ip_test.yaml index 2c8a86249c..67cafbd3e3 100644 --- a/library/common-test/tests/service/cluster_ip_test.yaml +++ b/library/common-test/tests/service/cluster_ip_test.yaml @@ -42,16 +42,21 @@ tests: some_policy: PreferDualStack some_family: IPv6 some_ip: 172.16.20.35 + some_other_ip: 10.200.34.53 service: my-service: enabled: true primary: true type: ClusterIP clusterIP: "{{ .Values.some_ip }}" + publishNotReadyAddresses: true ipFamilyPolicy: "{{ .Values.some_policy }}" ipFamilies: - IPv4 - "{{ .Values.some_family }}" + externalIPs: + - "{{ .Values.some_other_ip }}" + - 10.200.34.54 ports: port-name: enabled: true @@ -70,7 +75,10 @@ tests: type: ClusterIP clusterIP: 172.16.20.35 ipFamilyPolicy: PreferDualStack - publishNotReadyAddresses: false + publishNotReadyAddresses: true ipFamilies: - IPv4 - IPv6 + externalIPs: + - 10.200.34.53 + - 10.200.34.54 diff --git a/library/common-test/tests/service/external_ip_test.yaml b/library/common-test/tests/service/external_ip_test.yaml new file mode 100644 index 0000000000..b4cc261a76 --- /dev/null +++ b/library/common-test/tests/service/external_ip_test.yaml @@ -0,0 +1,73 @@ +suite: service externalIP test +templates: + - common.yaml +tests: + - it: should pass with type externalIP + set: + service: + my-service: + enabled: true + primary: true + type: ExternalIP + externalName: my-external-name + 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: + publishNotReadyAddresses: false + + - it: should pass with type ExternalIP and available options set + set: + some_policy: Local + some_ip: 10.200.34.53 + service: + my-service: + enabled: true + primary: true + type: ExternalIP + publishNotReadyAddresses: true + externalTrafficPolicy: "{{ .Values.some_policy }}" + externalIPs: + - "{{ .Values.some_ip }}" + - 10.200.34.54 + ports: + port-name: + enabled: true + primary: true + workload: + my-workload: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: *serviceDoc + equal: + path: spec + value: + externalTrafficPolicy: Local + publishNotReadyAddresses: true + externalIPs: + - 10.200.34.53 + - 10.200.34.54 diff --git a/library/common-test/tests/service/external_name_test.yaml b/library/common-test/tests/service/external_name_test.yaml index b638cd52c9..aab68e0b50 100644 --- a/library/common-test/tests/service/external_name_test.yaml +++ b/library/common-test/tests/service/external_name_test.yaml @@ -42,7 +42,9 @@ tests: - it: should pass with type ExternalName and available options set set: some_ip: 172.16.20.35 + some_other_ip: 10.200.34.53 some_name: my-external-name + some_policy: Local service: my-service: enabled: true @@ -50,7 +52,11 @@ tests: type: ExternalName clusterIP: "{{ .Values.some_ip }}" externalName: "{{ .Values.some_name }}" - externalTrafficPolicy: Local + publishNotReadyAddresses: true + externalTrafficPolicy: "{{ .Values.some_policy }}" + externalIPs: + - "{{ .Values.some_other_ip }}" + - 10.200.34.54 ports: port-name: enabled: true @@ -70,4 +76,7 @@ tests: clusterIP: 172.16.20.35 externalTrafficPolicy: Local externalName: my-external-name - publishNotReadyAddresses: false + publishNotReadyAddresses: true + externalIPs: + - 10.200.34.53 + - 10.200.34.54 diff --git a/library/common-test/tests/service/load_balancer_test.yaml b/library/common-test/tests/service/load_balancer_test.yaml index 5c316ca6d2..790cfe40d1 100644 --- a/library/common-test/tests/service/load_balancer_test.yaml +++ b/library/common-test/tests/service/load_balancer_test.yaml @@ -41,6 +41,8 @@ tests: set: some_ip: 172.16.20.35 some_other_ip: 10.100.200.45 + some_extra_ip: 10.200.34.53 + some_policy: Local some_range: 11.100.200.0/24 some_family: IPv6 service: @@ -53,11 +55,15 @@ tests: loadBalancerSourceRanges: - "{{ .Values.some_range }}" - 10.100.200.0/24 - externalTrafficPolicy: Local + externalTrafficPolicy: "{{ .Values.some_policy }}" + publishNotReadyAddresses: true ipFamilyPolicy: PreferDualStack ipFamilies: - IPv4 - "{{ .Values.some_family }}" + externalIPs: + - "{{ .Values.some_extra_ip }}" + - 10.200.34.54 ports: port-name: enabled: true @@ -81,7 +87,10 @@ tests: - 10.100.200.0/24 externalTrafficPolicy: Local ipFamilyPolicy: PreferDualStack - publishNotReadyAddresses: false + publishNotReadyAddresses: true ipFamilies: - IPv4 - IPv6 + externalIPs: + - 10.200.34.53 + - 10.200.34.54 diff --git a/library/common-test/tests/service/node_port_test.yaml b/library/common-test/tests/service/node_port_test.yaml index 16f3347354..9d25add334 100644 --- a/library/common-test/tests/service/node_port_test.yaml +++ b/library/common-test/tests/service/node_port_test.yaml @@ -41,17 +41,23 @@ tests: set: some_ip: 172.16.20.35 some_family: IPv6 + some_policy: Local + some_other_ip: 10.200.34.53 service: my-service: enabled: true primary: true type: NodePort clusterIP: "{{ .Values.some_ip }}" - externalTrafficPolicy: Local + externalTrafficPolicy: "{{ .Values.some_policy }}" + publishNotReadyAddresses: true ipFamilyPolicy: PreferDualStack ipFamilies: - IPv4 - "{{ .Values.some_family }}" + externalIPs: + - "{{ .Values.some_other_ip }}" + - 10.200.34.54 ports: port-name: enabled: true @@ -71,7 +77,10 @@ tests: clusterIP: 172.16.20.35 externalTrafficPolicy: Local ipFamilyPolicy: PreferDualStack - publishNotReadyAddresses: false + publishNotReadyAddresses: true ipFamilies: - IPv4 - IPv6 + externalIPs: + - 10.200.34.53 + - 10.200.34.54 diff --git a/library/common/1.0.0/docs/service.md b/library/common/1.0.0/docs/service.md index 1a286f79a1..ba9415fdc8 100644 --- a/library/common/1.0.0/docs/service.md +++ b/library/common/1.0.0/docs/service.md @@ -9,6 +9,8 @@ | service.[service-name].annotations | `dict` | ❌ | ✅ (On value only) | `{}` | Additional annotations for service | | service.[service-name].type | `string` | ❌ | ✅ | `ClusterIP` | Define the service type (ClusterIP, LoadBalancer, NodePort, ExternalIP, ExternalName) | | service.[service-name].publishNotReadyAddresses | `boolean` | ❌ | ❌ | `false` | Define whether to publishNotReadyAddresses or not | +| service.[service-name].externalIPs | `list` | ❌ | ❌ | | Define externalIPs | +| service.[service-name].externalIPs.[externalIP] | `string` | ✅ | ✅ | | The external IP | | service.[service-name].sharedKey | `string` | ❌ | ✅ | `$FullName` | Custom Shared Key for MetalLB Annotation | | service.[service-name].clusterIP | `string` | ❌ | ✅ | | Custom Cluster IP | | service.[service-name].ipFamilyPolicy | `string` | ❌ | ✅ | | Define the ipFamilyPolicy (SingleStack, PreferDualStack, RequireDualStack) | @@ -45,9 +47,12 @@ service: primary: true publishNotReadyAddresses: true clusterIP: 172.16.20.233 + publishNotReadyAddresses: true ipFamilyPolicy: SingleStack ipFamilies: - IPv4 + externalIPs: + - 10.200.230.34 targetSelector: pod-name ports: port-name: @@ -64,9 +69,12 @@ service: - 10.100.100.0/24 clusterIP: 172.16.20.233 sharedKey: custom-shared-key + publishNotReadyAddresses: true ipFamilyPolicy: SingleStack ipFamilies: - IPv4 + externalIPs: + - 10.200.230.34 externalTrafficPolicy: Cluster targetSelector: pod-name ports: @@ -75,6 +83,38 @@ service: primary: true container-name: container-name + service-nodeport: + enabled: true + primary: true + type: NodePort + clusterIP: 172.16.20.233 + publishNotReadyAddresses: true + externalIPs: + - 10.200.230.34 + externalTrafficPolicy: Cluster + targetSelector: pod-name + ports: + port-name: + enabled: true + primary: true + container-name: container-name + + service-externalname: + enabled: true + primary: true + type: ExternalName + externalName: external-name + clusterIP: 172.16.20.233 + publishNotReadyAddresses: true + externalIPs: + - 10.200.230.34 + externalTrafficPolicy: Cluster + ports: + port-name: + enabled: true + primary: true + container-name: container-name + other-service-name: enabled: true type: ClusterIP diff --git a/library/common/1.0.0/templates/classes/_service.tpl b/library/common/1.0.0/templates/classes/_service.tpl index d3afa7ccb5..1dbf52f491 100644 --- a/library/common/1.0.0/templates/classes/_service.tpl +++ b/library/common/1.0.0/templates/classes/_service.tpl @@ -14,6 +14,7 @@ objectData: The service data, that will be used to render the Service object. {{- $svcType := $objectData.type | default "ClusterIP" -}} {{/* Get Pod Values based on the selector (or the absence of it) */}} + {{/* TODO: handle caes that svcType does not need a pod to link with */}} {{- $podValues := fromJson (include "ix.v1.common.lib.service.getSelectedPodValues" (dict "rootCtx" $rootCtx "objectData" $objectData)) -}} {{/* Get Pod's hostNetwork configuration */}} @@ -74,10 +75,20 @@ spec: {{- include "ix.v1.common.lib.service.spec.nodePort" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }} {{- else if eq $svcType "ExternalName" -}} {{- include "ix.v1.common.lib.service.spec.externalName" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }} + {{- else if eq $svcType "ExternalIP" -}} + {{- include "ix.v1.common.lib.service.spec.externalIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }} {{- end }} publishNotReadyAddresses: {{ include "ix.v1.common.lib.service.publishNotReadyAddresses" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim }} + {{- with (include "ix.v1.common.lib.service.externalIPs" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }} + externalIPs: + {{- . | nindent 2 }} + {{- end -}} + {{/* TODO: sessionAffinity */}} + +{{/* TODO: ports */}} {{- if not (mustHas $svcType (list "ExternalName" "ExternalIP")) }} selector: {{- include "ix.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "podName" $podValues.shortName) | trim | nindent 2 }} {{- end -}} +{{/* TODO: endpoints */}} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/service/serviceTypeConfig/_externalIPs.tpl b/library/common/1.0.0/templates/lib/service/serviceTypeConfig/_externalIPs.tpl index 6acb432084..bdcd09fd8e 100644 --- a/library/common/1.0.0/templates/lib/service/serviceTypeConfig/_externalIPs.tpl +++ b/library/common/1.0.0/templates/lib/service/serviceTypeConfig/_externalIPs.tpl @@ -7,13 +7,11 @@ objectData: The service object data {{- define "ix.v1.common.lib.service.externalIPs" -}} {{- $rootCtx := .rootCtx -}} - {{- $objectData := .objectData }} + {{- $objectData := .objectData -}} - {{- $publishAddr := false -}} - - {{- if (kindIs "bool" $objectData.publishNotReadyAddresses) -}} - {{- $publishAddr = $objectData.publishNotReadyAddresses -}} + {{- with $objectData.externalIPs -}} + {{- range . }} +- {{ tpl . $rootCtx }} + {{- end -}} {{- end -}} - - {{- $publishAddr -}} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/service/serviceTypeSpecs/_externalIP.tpl b/library/common/1.0.0/templates/lib/service/serviceTypeSpecs/_externalIP.tpl new file mode 100644 index 0000000000..01c64fd055 --- /dev/null +++ b/library/common/1.0.0/templates/lib/service/serviceTypeSpecs/_externalIP.tpl @@ -0,0 +1,13 @@ +{{/* Service - ExternalIP Spec */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.service.spec.externalIP" (dict "rootCtx" $rootCtx "objectData" $objectData) -}} +rootCtx: The root context of the service +objectData: The service object data +*/}} + +{{- define "ix.v1.common.lib.service.spec.externalIP" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData }} + + {{- include "ix.v1.common.lib.service.externalTrafficPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }} +{{- end -}}