diff --git a/library/common-test/tests/lists/serviceList_test.yaml b/library/common-test/tests/lists/serviceList_test.yaml new file mode 100644 index 00000000..8e694c02 --- /dev/null +++ b/library/common-test/tests/lists/serviceList_test.yaml @@ -0,0 +1,180 @@ +suite: serviceList test +templates: + - common.yaml +tests: + - it: should pass with default values + documentIndex: &deploymentDoc 0 + asserts: + - hasDocuments: + count: 3 + - isKind: + of: Deployment + + - it: should pass with serviceList defined (container) + documentIndex: *deploymentDoc + set: + serviceList: + - enabled: true + type: ClusterIP + portsList: + - enabled: true + primary: true + protocol: HTTP + targetPort: 1234 + port: 3425 + - enabled: true + protocol: HTTP + targetPort: 12346 + port: 3427 + - enabled: true + type: NodePort + portsList: + - enabled: true + protocol: HTTP + targetPort: 12345 + nodePort: 30000 + port: 3426 + asserts: + - isSubset: + path: spec.template.spec.containers[0] + content: + ports: + - containerPort: 65535 + name: main + protocol: TCP + - name: port-list-0-0 + containerPort: 1234 + protocol: TCP + - name: port-list-0-1 + containerPort: 12346 + protocol: TCP + - name: port-list-1-0 + containerPort: 12345 + protocol: TCP + + - it: should pass with serviceList defined (service 1/2) + documentIndex: &serviceDoc 3 + set: + serviceList: + - enabled: true + type: ClusterIP + portsList: + - enabled: true + primary: true + protocol: HTTP + targetPort: 1234 + port: 3425 + - enabled: true + protocol: HTTP + targetPort: 12346 + port: 3427 + - enabled: true + type: NodePort + portsList: + - enabled: true + protocol: HTTP + targetPort: 12345 + nodePort: 30000 + port: 3426 + asserts: + - isSubset: + path: spec + content: + type: NodePort + ports: + - name: port-list-1-0 + port: 3426 + protocol: TCP + targetPort: 12345 + nodePort: 30000 + + - it: should pass with serviceList defined (service 2/2) + documentIndex: &otherServiceDoc 2 + set: + serviceList: + - enabled: true + type: ClusterIP + portsList: + - enabled: true + primary: true + protocol: HTTP + targetPort: 1234 + port: 3425 + - enabled: true + protocol: HTTP + targetPort: 12346 + port: 3427 + - enabled: true + type: NodePort + portsList: + - enabled: true + protocol: HTTP + targetPort: 12345 + nodePort: 30000 + port: 3426 + asserts: + - isSubset: + path: spec + content: + type: ClusterIP + ports: + - name: port-list-0-0 + port: 3425 + protocol: TCP + targetPort: 1234 + - name: port-list-0-1 + port: 3427 + protocol: TCP + targetPort: 12346 + + - it: should pass with serviceList defined (portal) + documentIndex: &portalDoc 4 + set: + serviceList: + - enabled: true + type: ClusterIP + portsList: + - enabled: true + primary: true + protocol: HTTP + targetPort: 1234 + port: 3425 + - enabled: true + protocol: HTTP + targetPort: 12346 + port: 3427 + - enabled: true + type: NodePort + portsList: + - enabled: true + protocol: HTTP + targetPort: 12345 + nodePort: 30000 + port: 3426 + asserts: + - equal: + path: kind + value: ConfigMap + - equal: + path: data + value: + host-main-main: $node_ip + host-svc-list-0-port-list-0-0: $node_ip + host-svc-list-0-port-list-0-1: $node_ip + host-svc-list-1-port-list-1-0: $node_ip + path-main-main: / + path-svc-list-0-port-list-0-0: / + path-svc-list-0-port-list-0-1: / + path-svc-list-1-port-list-1-0: / + port-main-main: "443" + port-svc-list-0-port-list-0-0: "443" + port-svc-list-0-port-list-0-1: "443" + port-svc-list-1-port-list-1-0: "30000" + protocol-main-main: http + protocol-svc-list-0-port-list-0-0: http + protocol-svc-list-0-port-list-0-1: http + protocol-svc-list-1-port-list-1-0: http + url-main-main: http://$node_ip:443/ + url-svc-list-0-port-list-0-0: http://$node_ip:443/ + url-svc-list-0-port-list-0-1: http://$node_ip:443/ + url-svc-list-1-port-list-1-0: http://$node_ip:30000/ diff --git a/library/common/1.0.0/templates/lib/values/lists/_deviceList.tpl b/library/common/1.0.0/templates/lib/values/lists/_deviceList.tpl index a5f8eceb..cc76faac 100644 --- a/library/common/1.0.0/templates/lib/values/lists/_deviceList.tpl +++ b/library/common/1.0.0/templates/lib/values/lists/_deviceList.tpl @@ -6,8 +6,8 @@ {{/* Generate the name */}} {{- $name := (printf "device-%s" (toString $index)) -}} - {{- if $device.name -}} - {{- $name = $device.name -}} + {{- with $device.name -}} + {{- $name = . -}} {{- end -}} {{/* Make sure a persistence dict exists before trying to add items */}} diff --git a/library/common/1.0.0/templates/lib/values/lists/_persistenceList.tpl b/library/common/1.0.0/templates/lib/values/lists/_persistenceList.tpl index a2d5788a..e77c236f 100644 --- a/library/common/1.0.0/templates/lib/values/lists/_persistenceList.tpl +++ b/library/common/1.0.0/templates/lib/values/lists/_persistenceList.tpl @@ -6,8 +6,8 @@ {{/* Generate the name */}} {{- $name := (printf "persist-list-%s" (toString $index)) -}} - {{- if $persistence.name -}} - {{- $name = $persistence.name -}} + {{- with $persistence.name -}} + {{- $name = . -}} {{- end -}} {{/* Make sure a persistence dict exists before trying to add items */}} diff --git a/library/common/1.0.0/templates/lib/values/lists/_serviceList.tpl b/library/common/1.0.0/templates/lib/values/lists/_serviceList.tpl new file mode 100644 index 00000000..c61b3392 --- /dev/null +++ b/library/common/1.0.0/templates/lib/values/lists/_serviceList.tpl @@ -0,0 +1,50 @@ +{{- define "ix.v1.common.lib.values.serviceList" -}} + {{- $root := . -}} + + {{/* Go over the service list */}} + {{- range $svcIndex, $service := $root.Values.serviceList -}} + + {{/* Used to track if the service is complete with at least one port */}} + {{- $complete := false -}} + + {{- if $service.enabled -}} + {{/* Generate the name */}} + {{- $svcName := (printf "svc-list-%s" (toString $svcIndex)) -}} + + {{- with $service.name -}} + {{- $svcName = . -}} + {{- end -}} + + {{- range $portIndex, $port := $service.portsList -}} + {{- if $port.enabled -}} + {{/* Generate the name */}} + {{- $portName := (printf "port-list-%s-%s" (toString $svcIndex) (toString $portIndex)) -}} + + {{- with $port.name -}} + {{- $portName = . -}} + {{- end -}} + + {{- if not (hasKey $service "ports") -}} + {{- $_ := set $service "ports" dict -}} + {{- end -}} + + {{- $_ := set $service.ports $portName $port -}} + {{- $complete = true -}} + {{- end -}} + {{- end -}} + + {{/* Make sure a service dict exists before trying to add items */}} + {{- if not (hasKey $root.Values "service") -}} + {{- $_ := set $root.Values "service" dict -}} + {{- end -}} + + {{/* Add the device as a service dict, + other templates will take care of the + service and ports */}} + {{- if $complete -}} + {{- $_ := set $root.Values.service $svcName $service -}} + {{- end -}} + {{- end -}} + {{- end -}} + +{{- end -}} diff --git a/library/common/1.0.0/templates/loader/_lists.tpl b/library/common/1.0.0/templates/loader/_lists.tpl index ba2b2dc1..1c1efc5c 100644 --- a/library/common/1.0.0/templates/loader/_lists.tpl +++ b/library/common/1.0.0/templates/loader/_lists.tpl @@ -4,4 +4,6 @@ {{- include "ix.v1.common.lib.values.deviceList" . -}} + {{- include "ix.v1.common.lib.values.serviceList" . -}} + {{- end -}}