From e3e1771fb3b1e132f640faa8a1d52f32394ea2c9 Mon Sep 17 00:00:00 2001 From: Brendan Dalpe Date: Thu, 13 Apr 2023 07:35:12 -0500 Subject: [PATCH 1/5] Upgrade to latest helm-unittest * Pin version at 0.3.1 --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0c0b246..2e9ca86 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -15,7 +15,7 @@ jobs: version: 3.9.4 - name: Install unittest plugin - run: helm plugin install https://github.com/quintush/helm-unittest + run: helm plugin install https://github.com/helm-unittest/helm-unittest --version 0.3.1 - name: helm lint run: helm lint helm-chart-sources/* From 32ab7953288efa889541927726d48a6520af5a1c Mon Sep 17 00:00:00 2001 From: Brendan Dalpe Date: Thu, 13 Apr 2023 07:35:23 -0500 Subject: [PATCH 2/5] Remove -3 flag as it is now redundant --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 2e9ca86..0ced082 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -21,4 +21,4 @@ jobs: run: helm lint helm-chart-sources/* - name: helm unittest - run: helm unittest -3 helm-chart-sources/* + run: helm unittest helm-chart-sources/* From 35a955d9fa1bb8c258118b4017552c27ae16204d Mon Sep 17 00:00:00 2001 From: Brendan Dalpe Date: Thu, 13 Apr 2023 07:35:44 -0500 Subject: [PATCH 3/5] Bump helm to latest version 3.11.3 --- .github/workflows/pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 0ced082..f7d9639 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -12,7 +12,7 @@ jobs: - name: Install Helm uses: azure/setup-helm@v3 with: - version: 3.9.4 + version: 3.11.3 - name: Install unittest plugin run: helm plugin install https://github.com/helm-unittest/helm-unittest --version 0.3.1 From d13d5bbc256e9df54beccf0d76339fa7353ce5dd Mon Sep 17 00:00:00 2001 From: Brendan Dalpe Date: Thu, 13 Apr 2023 09:06:46 -0500 Subject: [PATCH 4/5] Fix Edge extras and extras tests --- .../edge/templates/common/_extras.tpl | 12 +++-- .../edge/tests/extras_test.yaml | 53 +++++++++++++++++++ 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/helm-chart-sources/edge/templates/common/_extras.tpl b/helm-chart-sources/edge/templates/common/_extras.tpl index a6eee5b..658b7f1 100644 --- a/helm-chart-sources/edge/templates/common/_extras.tpl +++ b/helm-chart-sources/edge/templates/common/_extras.tpl @@ -1,6 +1,10 @@ -{{- define "common.extras" }} -{{ range .Values.extraObjects }} +{{- define "common.extras" -}} +{{- range .Values.extraObjects }} --- -{{ tpl (toYaml .) $ }} -{{ end }} +{{- if typeIs "string" . }} + {{ . | nindent 0 }} +{{- else }} + {{- toYaml . | nindent 0 }} +{{- end }} +{{- end }} {{- end }} \ No newline at end of file diff --git a/helm-chart-sources/edge/tests/extras_test.yaml b/helm-chart-sources/edge/tests/extras_test.yaml index e69de29..0e3da04 100644 --- a/helm-chart-sources/edge/tests/extras_test.yaml +++ b/helm-chart-sources/edge/tests/extras_test.yaml @@ -0,0 +1,53 @@ +suite: Extras +templates: + - extras.yaml +tests: + - it: Creates something extra + template: extras.yaml + values: + - ./values/values.yaml + set: + extraObjects: + - | + kind: Foo + fake2: true + apiVersion: cribl.io/v1 + asserts: + - hasDocuments: + count: 1 + - equal: + path: kind + value: Foo + - equal: + path: fake2 + value: true + - isAPIVersion: + of: cribl.io/v1 + + - it: Creates from object + template: extras.yaml + values: + - ./values/values.yaml + set: + extraObjects: + - apiVersion: v1 + kind: Pod + - apiVersion: v1 + kind: Secret + metadata: + name: foo + fake: 1234 + asserts: + - hasDocuments: + count: 2 + - containsDocument: + apiVersion: v1 + kind: Pod + - equal: + path: metadata.name + value: foo + documentIndex: 1 + - equal: + path: fake + value: 1234 + documentIndex: 1 \ No newline at end of file From b164f13139b0c2b3b8736b34c8ba87053cf7e06b Mon Sep 17 00:00:00 2001 From: Brendan Dalpe Date: Thu, 13 Apr 2023 09:24:04 -0500 Subject: [PATCH 5/5] Fix UTs --- .../edge/templates/networking/service.yaml | 2 ++ .../edge/tests/daemonset_test.yaml | 2 ++ helm-chart-sources/edge/tests/extras_test.yaml | 7 +++---- helm-chart-sources/edge/tests/ingress_test.yaml | 2 ++ helm-chart-sources/edge/tests/rbac_test.yaml | 2 ++ helm-chart-sources/edge/tests/secret_test.yaml | 7 +++++++ helm-chart-sources/edge/tests/service_test.yaml | 6 ++++-- helm-chart-sources/edge/tests/values/leader.yaml | 16 ++++++++++++++++ 8 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 helm-chart-sources/edge/tests/values/leader.yaml diff --git a/helm-chart-sources/edge/templates/networking/service.yaml b/helm-chart-sources/edge/templates/networking/service.yaml index 06497fd..c8e4aed 100644 --- a/helm-chart-sources/edge/templates/networking/service.yaml +++ b/helm-chart-sources/edge/templates/networking/service.yaml @@ -25,6 +25,8 @@ spec: {{- include "common.selectorLabels" . | nindent 4 }} {{- if (and (not (empty .Values.service.loadBalancerIP)) (eq $.Values.service.type "LoadBalancer")) }} loadBalancerIP: {{ .Values.service.loadBalancerIP }} + {{- end }} + {{- if .Values.service.externalTrafficPolicy }} externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }} {{- end -}} {{- end -}} \ No newline at end of file diff --git a/helm-chart-sources/edge/tests/daemonset_test.yaml b/helm-chart-sources/edge/tests/daemonset_test.yaml index 6aa0fc2..6219db9 100644 --- a/helm-chart-sources/edge/tests/daemonset_test.yaml +++ b/helm-chart-sources/edge/tests/daemonset_test.yaml @@ -1,6 +1,8 @@ suite: DaemonSet templates: - daemonset.yaml +values: + - ./values/leader.yaml tests: - it: Creates a DaemonSet asserts: diff --git a/helm-chart-sources/edge/tests/extras_test.yaml b/helm-chart-sources/edge/tests/extras_test.yaml index 0e3da04..2aa5dcf 100644 --- a/helm-chart-sources/edge/tests/extras_test.yaml +++ b/helm-chart-sources/edge/tests/extras_test.yaml @@ -1,11 +1,12 @@ suite: Extras templates: - extras.yaml +values: + - ./values/leader.yaml tests: - it: Creates something extra template: extras.yaml - values: - - ./values/values.yaml + set: extraObjects: - | @@ -26,8 +27,6 @@ tests: - it: Creates from object template: extras.yaml - values: - - ./values/values.yaml set: extraObjects: - apiVersion: v1 diff --git a/helm-chart-sources/edge/tests/ingress_test.yaml b/helm-chart-sources/edge/tests/ingress_test.yaml index 8f8fb6d..7ad2dde 100644 --- a/helm-chart-sources/edge/tests/ingress_test.yaml +++ b/helm-chart-sources/edge/tests/ingress_test.yaml @@ -1,6 +1,8 @@ suite: Ingress templates: - networking/ingress.yaml +values: + - ./values/leader.yaml tests: - it: Doesn't create an Ingress by default asserts: diff --git a/helm-chart-sources/edge/tests/rbac_test.yaml b/helm-chart-sources/edge/tests/rbac_test.yaml index ab2d138..07156c9 100644 --- a/helm-chart-sources/edge/tests/rbac_test.yaml +++ b/helm-chart-sources/edge/tests/rbac_test.yaml @@ -2,6 +2,8 @@ suite: RBAC templates: - rbac/serviceaccount.yaml - rbac/clusterrole.yaml +values: + - ./values/leader.yaml tests: - it: Creates a ServiceAccount template: rbac/serviceaccount.yaml diff --git a/helm-chart-sources/edge/tests/secret_test.yaml b/helm-chart-sources/edge/tests/secret_test.yaml index c781ca4..7f59d53 100644 --- a/helm-chart-sources/edge/tests/secret_test.yaml +++ b/helm-chart-sources/edge/tests/secret_test.yaml @@ -49,3 +49,10 @@ tests: - equal: path: spec.template.spec.containers[0].env[0].valueFrom.secretKeyRef.name value: sup3rsecr3t + +# temp disable while this is fixed https://github.com/helm-unittest/helm-unittest/issues/133 +# - it: Fails if not set +# template: daemonset.yaml +# asserts: +# - failedTemplate: +# errorMessage: A valid CRIBL_DIST_MASTER_URL is required to be defined in the cribl.leader value! diff --git a/helm-chart-sources/edge/tests/service_test.yaml b/helm-chart-sources/edge/tests/service_test.yaml index 471c422..6b73e92 100644 --- a/helm-chart-sources/edge/tests/service_test.yaml +++ b/helm-chart-sources/edge/tests/service_test.yaml @@ -1,6 +1,8 @@ suite: Service templates: - networking/service.yaml +values: + - ./values/leader.yaml tests: - it: Doesn't create a Service by default asserts: @@ -63,7 +65,7 @@ tests: enable: true type: ClusterIP # redundant loadBalancerIP: 1.2.3.4 - assert: + asserts: - isNull: path: spec.loadBalancerIP @@ -72,7 +74,7 @@ tests: service: enable: true externalTrafficPolicy: Local - assert: + asserts: - equal: path: spec.externalTrafficPolicy value: Local \ No newline at end of file diff --git a/helm-chart-sources/edge/tests/values/leader.yaml b/helm-chart-sources/edge/tests/values/leader.yaml new file mode 100644 index 0000000..17b824d --- /dev/null +++ b/helm-chart-sources/edge/tests/values/leader.yaml @@ -0,0 +1,16 @@ +cribl: + leader: "for-UTs" + +extraObjects: + - apiVersion: v1 + kind: foo + - apiVersion: v1 + kind: foo + extra: + test: + deep: + value: 1 + - | + apiVersion: v1 + foo: 1 + asdf: asdfas \ No newline at end of file