diff --git a/library/common-test/tests/service/cluster_ip_test.yaml b/library/common-test/tests/service/cluster_ip_test.yaml index 3700e13e38..2c8a86249c 100644 --- a/library/common-test/tests/service/cluster_ip_test.yaml +++ b/library/common-test/tests/service/cluster_ip_test.yaml @@ -35,6 +35,7 @@ tests: path: spec value: type: ClusterIP + publishNotReadyAddresses: false - it: should pass with type ClusterIP and available options set set: @@ -69,6 +70,7 @@ tests: type: ClusterIP clusterIP: 172.16.20.35 ipFamilyPolicy: PreferDualStack + publishNotReadyAddresses: false ipFamilies: - IPv4 - IPv6 diff --git a/library/common-test/tests/service/external_name_test.yaml b/library/common-test/tests/service/external_name_test.yaml new file mode 100644 index 0000000000..b638cd52c9 --- /dev/null +++ b/library/common-test/tests/service/external_name_test.yaml @@ -0,0 +1,73 @@ +suite: service externalName test +templates: + - common.yaml +tests: + - it: should pass with type externalName + set: + service: + my-service: + enabled: true + primary: true + type: ExternalName + 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: + type: ExternalName + externalName: my-external-name + publishNotReadyAddresses: false + + - it: should pass with type ExternalName and available options set + set: + some_ip: 172.16.20.35 + some_name: my-external-name + service: + my-service: + enabled: true + primary: true + type: ExternalName + clusterIP: "{{ .Values.some_ip }}" + externalName: "{{ .Values.some_name }}" + externalTrafficPolicy: Local + 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: ExternalName + clusterIP: 172.16.20.35 + externalTrafficPolicy: Local + externalName: my-external-name + publishNotReadyAddresses: false diff --git a/library/common-test/tests/service/load_balancer_test.yaml b/library/common-test/tests/service/load_balancer_test.yaml index 66b2af8fab..5c316ca6d2 100644 --- a/library/common-test/tests/service/load_balancer_test.yaml +++ b/library/common-test/tests/service/load_balancer_test.yaml @@ -35,6 +35,7 @@ tests: path: spec value: type: LoadBalancer + publishNotReadyAddresses: false - it: should pass with type LoadBalancer and available options set set: @@ -80,6 +81,7 @@ tests: - 10.100.200.0/24 externalTrafficPolicy: Local ipFamilyPolicy: PreferDualStack + publishNotReadyAddresses: false ipFamilies: - IPv4 - IPv6 diff --git a/library/common-test/tests/service/node_port_test.yaml b/library/common-test/tests/service/node_port_test.yaml index 9d2428dbc9..16f3347354 100644 --- a/library/common-test/tests/service/node_port_test.yaml +++ b/library/common-test/tests/service/node_port_test.yaml @@ -35,6 +35,7 @@ tests: path: spec value: type: NodePort + publishNotReadyAddresses: false - it: should pass with type NodePort and available options set set: @@ -70,6 +71,7 @@ tests: clusterIP: 172.16.20.35 externalTrafficPolicy: Local ipFamilyPolicy: PreferDualStack + publishNotReadyAddresses: false ipFamilies: - IPv4 - IPv6 diff --git a/library/common-test/tests/service/validation_test.yaml b/library/common-test/tests/service/validation_test.yaml index cebc4f15e9..21cb6dfa24 100644 --- a/library/common-test/tests/service/validation_test.yaml +++ b/library/common-test/tests/service/validation_test.yaml @@ -293,3 +293,25 @@ tests: asserts: - failedTemplate: errorMessage: Service - Expected to be one of [Cluster, Local], but got [not-a-policy] + + - it: should fail with invalid externalName + set: + service: + service-name1: + enabled: true + primary: true + type: ExternalName + externalName: "" + ports: + port-name1: + enabled: true + primary: true + workload: + some-pod-name: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - failedTemplate: + errorMessage: Service - Expected non-empty on ExternalName service type. diff --git a/library/common/1.0.0/docs/service.md b/library/common/1.0.0/docs/service.md index 994bb7d489..1a286f79a1 100644 --- a/library/common/1.0.0/docs/service.md +++ b/library/common/1.0.0/docs/service.md @@ -8,6 +8,7 @@ | service.[service-name].labels | `dict` | ❌ | ✅ (On value only) | `{}` | Additional labels for service | | 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].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) | @@ -42,6 +43,7 @@ service: service-clusterip: enabled: true primary: true + publishNotReadyAddresses: true clusterIP: 172.16.20.233 ipFamilyPolicy: SingleStack ipFamilies: diff --git a/library/common/1.0.0/templates/classes/_service.tpl b/library/common/1.0.0/templates/classes/_service.tpl index c7a3b55200..d3afa7ccb5 100644 --- a/library/common/1.0.0/templates/classes/_service.tpl +++ b/library/common/1.0.0/templates/classes/_service.tpl @@ -72,7 +72,10 @@ spec: {{- 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 }} + {{- else if eq $svcType "ExternalName" -}} + {{- include "ix.v1.common.lib.service.spec.externalName" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 2 }} {{- end }} + publishNotReadyAddresses: {{ include "ix.v1.common.lib.service.publishNotReadyAddresses" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim }} {{- if not (mustHas $svcType (list "ExternalName" "ExternalIP")) }} selector: {{- include "ix.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "podName" $podValues.shortName) | trim | nindent 2 }} 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 new file mode 100644 index 0000000000..6acb432084 --- /dev/null +++ b/library/common/1.0.0/templates/lib/service/serviceTypeConfig/_externalIPs.tpl @@ -0,0 +1,19 @@ +{{/* Service - externalIPs */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.service.externalIPs" (dict "rootCtx" $rootCtx "objectData" $objectData) -}} +rootCtx: The root context of the service +objectData: The service object data +*/}} + +{{- define "ix.v1.common.lib.service.externalIPs" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData }} + + {{- $publishAddr := false -}} + + {{- if (kindIs "bool" $objectData.publishNotReadyAddresses) -}} + {{- $publishAddr = $objectData.publishNotReadyAddresses -}} + {{- end -}} + + {{- $publishAddr -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/service/serviceTypeConfig/_publishNotReadyAddresses.tpl b/library/common/1.0.0/templates/lib/service/serviceTypeConfig/_publishNotReadyAddresses.tpl new file mode 100644 index 0000000000..77e8af2ba7 --- /dev/null +++ b/library/common/1.0.0/templates/lib/service/serviceTypeConfig/_publishNotReadyAddresses.tpl @@ -0,0 +1,19 @@ +{{/* Service - publishNotReadyAddresses */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.service.publishNotReadyAddresses" (dict "rootCtx" $rootCtx "objectData" $objectData) -}} +rootCtx: The root context of the service +objectData: The service object data +*/}} + +{{- define "ix.v1.common.lib.service.publishNotReadyAddresses" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData }} + + {{- $publishAddr := false -}} + + {{- if (kindIs "bool" $objectData.publishNotReadyAddresses) -}} + {{- $publishAddr = $objectData.publishNotReadyAddresses -}} + {{- end -}} + + {{- $publishAddr -}} +{{- end -}} diff --git a/library/common/1.0.0/templates/lib/service/serviceTypeSpecs/_externalName.tpl b/library/common/1.0.0/templates/lib/service/serviceTypeSpecs/_externalName.tpl new file mode 100644 index 0000000000..5572a46ebd --- /dev/null +++ b/library/common/1.0.0/templates/lib/service/serviceTypeSpecs/_externalName.tpl @@ -0,0 +1,20 @@ +{{/* Service - ExternalName Spec */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.service.spec.externalName" (dict "rootCtx" $rootCtx "objectData" $objectData) -}} +rootCtx: The root context of the service +objectData: The service object data +*/}} + +{{- define "ix.v1.common.lib.service.spec.externalName" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData }} + + {{- if not $objectData.externalName -}} + {{- fail "Service - Expected non-empty on ExternalName service type." -}} + {{- end }} + +type: ExternalName +externalName: {{ tpl $objectData.externalName $rootCtx }} + {{- include "ix.v1.common.lib.service.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }} + {{- include "ix.v1.common.lib.service.externalTrafficPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }} +{{- end -}}