fix(common): ensure serviceList is correctly parsed (#379)

**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes  # <!--(issue)-->

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [ ] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] 🔃 Refactor of current code

**🧪 How Has This Been Tested?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ Checklist:**

- [ ] ⚖️ My code follows the style guidelines of this project
- [ ] 👀 I have performed a self-review of my own code
- [ ] #️⃣ I have commented my code, particularly in hard-to-understand
areas
- [ ] 📄 I have made corresponding changes to the documentation
- [ ] ⚠️ My changes generate no new warnings
- [ ] 🧪 I have added tests to this description that prove my fix is
effective or that my feature works
- [ ] ⬆️ I increased versions for any altered app according to semantic
versioning

** App addition**

If this PR is an app addition please make sure you have done the
following.

- [ ] 🪞 I have opened a PR on
[truecharts/containers](https://github.com/truecharts/containers) adding
the container to TrueCharts mirror repo.
- [ ] 🖼️ I have added an icon in the Chart's root directory called
`icon.png`

---

_Please don't blindly check all the boxes. Read them and only check
those that apply.
Those checkboxes are there for the reviewer to see what is this all
about and
the status of this PR with a quick glance._
This commit is contained in:
Stavros Kois
2023-04-11 19:56:46 +03:00
committed by GitHub
parent 5f0adb4722
commit 5cd444ce1e
5 changed files with 195 additions and 1 deletions

View File

@@ -0,0 +1,172 @@
suite: service list test
templates:
- common.yaml
tests:
- it: should pass with type LoadBalancer from serviceList with name
set:
serviceList:
- name: my-service
enabled: true
primary: true
type: LoadBalancer
ports:
port-name:
enabled: true
primary: true
port: 12345
- name: my-service2
enabled: true
type: LoadBalancer
ports:
port-name:
enabled: true
primary: true
port: 12345
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: LoadBalancer
allocateLoadBalancerNodePorts: false
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: &otherServiceDoc 2
isKind:
of: Service
- documentIndex: *otherServiceDoc
isAPIVersion:
of: v1
- documentIndex: *otherServiceDoc
equal:
path: metadata.name
value: release-name-common-test-my-service2
- documentIndex: *otherServiceDoc
equal:
path: spec
value:
type: LoadBalancer
allocateLoadBalancerNodePorts: false
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
- it: should pass with type LoadBalancer from serviceList
set:
serviceList:
- enabled: true
primary: true
type: LoadBalancer
ports:
port-name:
enabled: true
primary: true
port: 12345
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: LoadBalancer
allocateLoadBalancerNodePorts: false
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
- it: should pass with type ClusterIP from serviceList
set:
serviceList:
- enabled: true
primary: true
type: ClusterIP
ports:
port-name:
enabled: true
primary: true
port: 12345
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: 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

View File

@@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 12.4.2
version: 12.4.3

View File

@@ -2,4 +2,6 @@
{{- include "tc.v1.common.values.persistenceList" . -}}
{{- include "tc.v1.common.values.serviceList" . -}}
{{- end -}}

View File

@@ -0,0 +1,18 @@
{{- define "tc.v1.common.values.serviceList" -}}
{{- $rootCtx := . -}}
{{- range $idx, $serviceValues := $rootCtx.Values.serviceList -}}
{{- $name := (printf "persist-list-%s" (toString $idx)) -}}
{{- with $serviceValues.name -}}
{{- $name = . -}}
{{- end -}}
{{- if not (hasKey $rootCtx.Values "service") -}}
{{- $_ := set $rootCtx.Values "service" dict -}}
{{- end -}}
{{- $_ := set $rootCtx.Values.service $name $serviceValues -}}
{{- end -}}
{{- end -}}

View File

@@ -178,6 +178,8 @@ service:
primary: true
protocol: http
serviceList: []
# -- (docs/persistence/README.md)
persistence:
shared: