From 6fc2e5c7a387b93288a77d083aaa5e448eb50584 Mon Sep 17 00:00:00 2001 From: linoleparquet Date: Tue, 19 Sep 2023 16:01:17 -0400 Subject: [PATCH 1/2] fix(acme): fix templating and add unit tests (#655) --- charts/acme/Chart.yaml | 2 +- charts/acme/templates/clusterIssuer.yaml | 2 ++ charts/acme/tests/defaults_test.yaml | 23 +++++++++++++++++++ charts/acme/tests/secrets_default_values.yaml | 4 ++++ charts/acme/values.yaml | 4 ++-- 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 charts/acme/tests/defaults_test.yaml create mode 100644 charts/acme/tests/secrets_default_values.yaml diff --git a/charts/acme/Chart.yaml b/charts/acme/Chart.yaml index d2043c42e..700157d22 100644 --- a/charts/acme/Chart.yaml +++ b/charts/acme/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v1 description: An acme settings chart for Jenkins infra project name: acme -version: 0.1.2 +version: 0.1.3 home: "https://github.com/jenkins-infra/charts" maintainers: - name: Olblak diff --git a/charts/acme/templates/clusterIssuer.yaml b/charts/acme/templates/clusterIssuer.yaml index 167dad03e..c8141d180 100644 --- a/charts/acme/templates/clusterIssuer.yaml +++ b/charts/acme/templates/clusterIssuer.yaml @@ -9,5 +9,7 @@ spec: privateKeySecretRef: # Secret resource used to store the account's private key. name: {{ .Values.acme.id }} + {{- if .Values.acme.solvers }} solvers: {{- toYaml .Values.acme.solvers | nindent 4 }} + {{- end}} diff --git a/charts/acme/tests/defaults_test.yaml b/charts/acme/tests/defaults_test.yaml new file mode 100644 index 000000000..966e346ca --- /dev/null +++ b/charts/acme/tests/defaults_test.yaml @@ -0,0 +1,23 @@ +suite: default tests +values: + - ../values.yaml + - secrets_default_values.yaml +templates: + - clusterIssuer.yaml + - secret.yaml +tests: + - it: should create a cluster issuer by default + template: clusterIssuer.yaml + asserts: + - hasDocuments: + count: 1 + - it: should create a Secret with the correct value + template: secret.yaml + asserts: + - hasDocuments: + count: 1 + - isKind: + of: Secret + - equal: + path: data.CLIENT_SECRET + value: cGFzc3dvcmQ= diff --git a/charts/acme/tests/secrets_default_values.yaml b/charts/acme/tests/secrets_default_values.yaml new file mode 100644 index 000000000..b71ac385c --- /dev/null +++ b/charts/acme/tests/secrets_default_values.yaml @@ -0,0 +1,4 @@ +acme: + clientSecrets: + - name: acme-test-secret + value: password diff --git a/charts/acme/values.yaml b/charts/acme/values.yaml index b563b5e01..e4306db26 100644 --- a/charts/acme/values.yaml +++ b/charts/acme/values.yaml @@ -9,8 +9,8 @@ acme: # Secrets used for dns01 settings clientSecrets: - - name: 'acme_test_secret' - value: 'password' + - name: acme-test-secret + value: "" # Accepts any values as defined here https://cert-manager.io/docs/configuration/acme/dns01/ dns01: {} From fcf2ae4414ed4f9ecc2a289178249d07242bbccb Mon Sep 17 00:00:00 2001 From: linoleparquet Date: Wed, 20 Sep 2023 08:42:59 -0400 Subject: [PATCH 2/2] fix(acme): split unit test --- ...defaults_test.yaml => custom_values_test.yaml} | 15 ++++++--------- charts/acme/tests/defaults_values_test.yaml | 10 ++++++++++ charts/acme/tests/secrets_default_values.yaml | 4 ---- 3 files changed, 16 insertions(+), 13 deletions(-) rename charts/acme/tests/{defaults_test.yaml => custom_values_test.yaml} (58%) create mode 100644 charts/acme/tests/defaults_values_test.yaml delete mode 100644 charts/acme/tests/secrets_default_values.yaml diff --git a/charts/acme/tests/defaults_test.yaml b/charts/acme/tests/custom_values_test.yaml similarity index 58% rename from charts/acme/tests/defaults_test.yaml rename to charts/acme/tests/custom_values_test.yaml index 966e346ca..f27aae8d3 100644 --- a/charts/acme/tests/defaults_test.yaml +++ b/charts/acme/tests/custom_values_test.yaml @@ -1,17 +1,14 @@ -suite: default tests -values: - - ../values.yaml - - secrets_default_values.yaml +suite: Test with custom values templates: - clusterIssuer.yaml - secret.yaml tests: - - it: should create a cluster issuer by default - template: clusterIssuer.yaml - asserts: - - hasDocuments: - count: 1 - it: should create a Secret with the correct value + set: + acme: + clientSecrets: + - name: acme-test-secret + value: password template: secret.yaml asserts: - hasDocuments: diff --git a/charts/acme/tests/defaults_values_test.yaml b/charts/acme/tests/defaults_values_test.yaml new file mode 100644 index 000000000..fea6a6192 --- /dev/null +++ b/charts/acme/tests/defaults_values_test.yaml @@ -0,0 +1,10 @@ +suite: Test with default values +templates: + - clusterIssuer.yaml + - secret.yaml +tests: + - it: should create a cluster issuer by default + template: clusterIssuer.yaml + asserts: + - hasDocuments: + count: 1 diff --git a/charts/acme/tests/secrets_default_values.yaml b/charts/acme/tests/secrets_default_values.yaml deleted file mode 100644 index b71ac385c..000000000 --- a/charts/acme/tests/secrets_default_values.yaml +++ /dev/null @@ -1,4 +0,0 @@ -acme: - clientSecrets: - - name: acme-test-secret - value: password