From e9084e18339a5b455e30a8f780643b8cce46fdb3 Mon Sep 17 00:00:00 2001 From: justusbunsi Date: Wed, 18 Dec 2024 11:12:29 +0000 Subject: [PATCH] Ensure default customization of Chart dependencies (#748) ### Description of the change This adds unittests for the default configuration of our dependencies. ### Benefits We are able to detect changes in upstream Charts for those settings. ### Applicable issues - fixes #409 ### Additional information I merged existing unittests with the new ones for `postgresql-ha` and `postgresql`. However, I decided to not do this for `redis-cluster` and `redis`, because the existing tests[^1] also ensure how the Chart behaves when both redis dependencies are disabled. It didn't felt right to split those files. ### Checklist - [x] Templating unittests are added Signed-off-by: justusbunsi [^1]: https://gitea.com/gitea/helm-chart/src/commit/e733287dc236e34a6caebf6bd8de5e6f25533eae/unittests/config/cache-config.yaml, https://gitea.com/gitea/helm-chart/src/commit/e733287dc236e34a6caebf6bd8de5e6f25533eae/unittests/config/queue-config.yaml, https://gitea.com/gitea/helm-chart/src/commit/e733287dc236e34a6caebf6bd8de5e6f25533eae/unittests/config/session-config.yaml Reviewed-on: https://gitea.com/gitea/helm-chart/pulls/748 Co-authored-by: justusbunsi Co-committed-by: justusbunsi --- Makefile | 2 +- .../database-section_postgresql-ha.yaml | 30 ----- .../config/database-section_postgresql.yaml | 30 ----- ...customization-integrity-postgresql-ha.yaml | 121 ++++++++++++++++++ .../customization-integrity-postgresql.yaml | 88 +++++++++++++ ...customization-integrity-redis-cluster.yaml | 90 +++++++++++++ .../customization-integrity-redis.yaml | 52 ++++++++ .../major-image-bump.yaml} | 2 +- 8 files changed, 353 insertions(+), 62 deletions(-) delete mode 100644 unittests/config/database-section_postgresql-ha.yaml delete mode 100644 unittests/config/database-section_postgresql.yaml create mode 100644 unittests/dependency-checks/customization-integrity-postgresql-ha.yaml create mode 100644 unittests/dependency-checks/customization-integrity-postgresql.yaml create mode 100644 unittests/dependency-checks/customization-integrity-redis-cluster.yaml create mode 100644 unittests/dependency-checks/customization-integrity-redis.yaml rename unittests/{dependency-major-image-check.yaml => dependency-checks/major-image-bump.yaml} (97%) diff --git a/Makefile b/Makefile index cc92433..bb58f72 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ readme: prepare-environment .PHONY: unittests unittests: - helm unittest --strict -f 'unittests/**/*.yaml' -f 'unittests/dependency-major-image-check.yaml' -f 'unittests/values-conflicting-checks.yaml' ./ + helm unittest --strict -f 'unittests/**/*.yaml' -f 'unittests/values-conflicting-checks.yaml' ./ .PHONY: helm update-helm-dependencies: diff --git a/unittests/config/database-section_postgresql-ha.yaml b/unittests/config/database-section_postgresql-ha.yaml deleted file mode 100644 index f416d79..0000000 --- a/unittests/config/database-section_postgresql-ha.yaml +++ /dev/null @@ -1,30 +0,0 @@ -suite: config template | database section (postgresql-ha) -release: - name: gitea-unittests - namespace: testing -tests: - - it: connects to pgpool service - template: templates/gitea/config.yaml - set: - postgresql: - enabled: false - postgresql-ha: - enabled: true - asserts: - - documentIndex: 0 - matchRegex: - path: stringData.database - pattern: HOST=gitea-unittests-postgresql-ha-pgpool.testing.svc.cluster.local:5432 - - it: renders the referenced service - template: charts/postgresql-ha/templates/pgpool/service.yaml - set: - postgresql: - enabled: false - postgresql-ha: - enabled: true - asserts: - - containsDocument: - kind: Service - apiVersion: v1 - name: gitea-unittests-postgresql-ha-pgpool - namespace: testing diff --git a/unittests/config/database-section_postgresql.yaml b/unittests/config/database-section_postgresql.yaml deleted file mode 100644 index 5a7501b..0000000 --- a/unittests/config/database-section_postgresql.yaml +++ /dev/null @@ -1,30 +0,0 @@ -suite: config template | database section (postgresql) -release: - name: gitea-unittests - namespace: testing -tests: - - it: "connects to postgresql service" - template: templates/gitea/config.yaml - set: - postgresql: - enabled: true - postgresql-ha: - enabled: false - asserts: - - documentIndex: 0 - matchRegex: - path: stringData.database - pattern: HOST=gitea-unittests-postgresql.testing.svc.cluster.local:5432 - - it: "renders the referenced service" - template: charts/postgresql/templates/primary/svc.yaml - set: - postgresql: - enabled: true - postgresql-ha: - enabled: false - asserts: - - containsDocument: - kind: Service - apiVersion: v1 - name: gitea-unittests-postgresql - namespace: testing diff --git a/unittests/dependency-checks/customization-integrity-postgresql-ha.yaml b/unittests/dependency-checks/customization-integrity-postgresql-ha.yaml new file mode 100644 index 0000000..efef6ef --- /dev/null +++ b/unittests/dependency-checks/customization-integrity-postgresql-ha.yaml @@ -0,0 +1,121 @@ +suite: Dependency checks | Customization integrity | postgresql-ha +release: + name: gitea-unittests + namespace: testing +set: + postgresql: + enabled: false + postgresql-ha: + enabled: true + global: + postgresql: + database: gitea-database + password: gitea-password + username: gitea-username + postgresql: + repmgrPassword: custom-password-repmgr + postgresPassword: custom-password-postgres + password: custom-password-overwritten-by-global-postgresql-password + pgpool: + adminPassword: custom-password-pgpool + service: + ports: + postgresql: 1234 + persistence: + size: 1337Mi +tests: + - it: "[postgresql-ha] DB settings are applied as expected" + template: charts/postgresql-ha/templates/postgresql/statefulset.yaml + asserts: + - documentIndex: 0 + contains: + path: spec.template.spec.containers[0].env + content: + name: POSTGRES_DB + value: "gitea-database" + - documentIndex: 0 + contains: + path: spec.template.spec.containers[0].env + content: + name: POSTGRES_USER + value: "gitea-username" + - it: "[postgresql-ha] DB passwords are applied as expected" + template: charts/postgresql-ha/templates/postgresql/secrets.yaml + asserts: + - documentIndex: 0 + equal: + path: data["repmgr-password"] + value: "Y3VzdG9tLXBhc3N3b3JkLXJlcG1ncg==" + - documentIndex: 0 + equal: + path: data["postgres-password"] + value: "Y3VzdG9tLXBhc3N3b3JkLXBvc3RncmVz" + - documentIndex: 0 + equal: + path: data["password"] + value: "Z2l0ZWEtcGFzc3dvcmQ=" # postgresql-ha.postgresql.password is overwritten by postgresql-ha.global.postgresql.password and should not be referenced here + - it: "[postgresql-ha] pgpool.adminPassword is applied as expected" + template: charts/postgresql-ha/templates/pgpool/secrets.yaml + asserts: + - documentIndex: 0 + equal: + path: data["admin-password"] + value: "Y3VzdG9tLXBhc3N3b3JkLXBncG9vbA==" + - it: "[postgresql-ha] pgpool.adminPassword is applied as expected" + template: charts/postgresql-ha/templates/pgpool/secrets.yaml + asserts: + - documentIndex: 0 + equal: + path: data["admin-password"] + value: "Y3VzdG9tLXBhc3N3b3JkLXBncG9vbA==" + - it: "[postgresql-ha] pgpool.adminPassword is applied as expected" + template: charts/postgresql-ha/templates/pgpool/secrets.yaml + asserts: + - documentIndex: 0 + equal: + path: data["admin-password"] + value: "Y3VzdG9tLXBhc3N3b3JkLXBncG9vbA==" + - it: "[postgresql-ha] persistence.size is applied as expected" + template: charts/postgresql-ha/templates/postgresql/statefulset.yaml + asserts: + - documentIndex: 0 + equal: + path: spec.volumeClaimTemplates[0].spec.resources.requests.storage + value: "1337Mi" + - it: "[postgresql-ha] service.ports.postgresql is applied as expected" + template: charts/postgresql-ha/templates/pgpool/service.yaml + asserts: + - documentIndex: 0 + equal: + path: spec.ports[0].port + value: 1234 + - it: "[postgresql-ha] renders the referenced service" + template: charts/postgresql-ha/templates/pgpool/service.yaml + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: gitea-unittests-postgresql-ha-pgpool + namespace: testing + - it: "[gitea] connects to pgpool service" + template: templates/gitea/config.yaml + asserts: + - documentIndex: 0 + matchRegex: + path: stringData.database + pattern: HOST=gitea-unittests-postgresql-ha-pgpool.testing.svc.cluster.local:1234 + - it: "[gitea] connects to configured database" + template: templates/gitea/config.yaml + asserts: + - documentIndex: 0 + matchRegex: + path: stringData.database + pattern: NAME=gitea-database + - documentIndex: 0 + matchRegex: + path: stringData.database + pattern: USER=gitea-username + - documentIndex: 0 + matchRegex: + path: stringData.database + pattern: PASSWD=gitea-password diff --git a/unittests/dependency-checks/customization-integrity-postgresql.yaml b/unittests/dependency-checks/customization-integrity-postgresql.yaml new file mode 100644 index 0000000..a84ddc3 --- /dev/null +++ b/unittests/dependency-checks/customization-integrity-postgresql.yaml @@ -0,0 +1,88 @@ +suite: Dependency checks | Customization integrity | postgresql +release: + name: gitea-unittests + namespace: testing +set: + postgresql-ha: + enabled: false + postgresql: + enabled: true + global: + postgresql: + auth: + password: gitea-password + database: gitea-database + username: gitea-username + service: + ports: + postgresql: 1234 + primary: + persistence: + size: 1337Mi +tests: + - it: "[postgresql] DB settings are applied as expected" + template: charts/postgresql/templates/primary/statefulset.yaml + asserts: + - documentIndex: 0 + contains: + path: spec.template.spec.containers[0].env + content: + name: POSTGRES_DATABASE + value: "gitea-database" + - documentIndex: 0 + contains: + path: spec.template.spec.containers[0].env + content: + name: POSTGRES_USER + value: "gitea-username" + - it: "[postgresql] DB password is applied as expected" + template: charts/postgresql/templates/secrets.yaml + asserts: + - documentIndex: 0 + equal: + path: data["password"] + value: "Z2l0ZWEtcGFzc3dvcmQ=" + - it: "[postgresql] primary.persistence.size is applied as expected" + template: charts/postgresql/templates/primary/statefulset.yaml + asserts: + - documentIndex: 0 + equal: + path: spec.volumeClaimTemplates[0].spec.resources.requests.storage + value: "1337Mi" + - it: "[postgresql] global.postgresql.service.ports.postgresql is applied as expected" + template: charts/postgresql/templates/primary/svc.yaml + asserts: + - documentIndex: 0 + equal: + path: spec.ports[0].port + value: 1234 + - it: "[postgresql] renders the referenced service" + template: charts/postgresql/templates/primary/svc.yaml + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: gitea-unittests-postgresql + namespace: testing + - it: "[gitea] connects to postgresql service" + template: templates/gitea/config.yaml + asserts: + - documentIndex: 0 + matchRegex: + path: stringData.database + pattern: HOST=gitea-unittests-postgresql.testing.svc.cluster.local:1234 + - it: "[gitea] connects to configured database" + template: templates/gitea/config.yaml + asserts: + - documentIndex: 0 + matchRegex: + path: stringData.database + pattern: NAME=gitea-database + - documentIndex: 0 + matchRegex: + path: stringData.database + pattern: USER=gitea-username + - documentIndex: 0 + matchRegex: + path: stringData.database + pattern: PASSWD=gitea-password diff --git a/unittests/dependency-checks/customization-integrity-redis-cluster.yaml b/unittests/dependency-checks/customization-integrity-redis-cluster.yaml new file mode 100644 index 0000000..4d5b553 --- /dev/null +++ b/unittests/dependency-checks/customization-integrity-redis-cluster.yaml @@ -0,0 +1,90 @@ +suite: Dependency checks | Customization integrity | redis-cluster +release: + name: gitea-unittests + namespace: testing +set: + redis: + enabled: false + redis-cluster: + enabled: true + usePassword: false + cluster: + nodes: 5 + replicas: 2 +tests: + - it: "[redis-cluster] configures correct nodes/replicas" + template: charts/redis-cluster/templates/redis-statefulset.yaml + asserts: + - documentIndex: 0 + equal: + path: spec.replicas + value: 5 + - documentIndex: 0 + matchRegex: + path: spec.template.spec.containers[0].args[0] + pattern: REDIS_CLUSTER_REPLICAS="2" + - it: "[redis-cluster] support auth-less connections" + asserts: + - template: charts/redis-cluster/templates/secret.yaml + hasDocuments: + count: 0 + - template: charts/redis-cluster/templates/redis-statefulset.yaml + documentIndex: 0 + contains: + path: spec.template.spec.containers[0].env + content: + name: ALLOW_EMPTY_PASSWORD + value: "yes" + - it: "[redis-cluster] support auth-full connections" + set: + redis-cluster: + usePassword: true + asserts: + - template: charts/redis-cluster/templates/secret.yaml + containsDocument: + kind: Secret + apiVersion: v1 + name: gitea-unittests-redis-cluster + namespace: testing + - template: charts/redis-cluster/templates/redis-statefulset.yaml + documentIndex: 0 + contains: + path: spec.template.spec.containers[0].env + content: + name: REDISCLI_AUTH + valueFrom: + secretKeyRef: + name: gitea-unittests-redis-cluster + key: redis-password + - template: charts/redis-cluster/templates/redis-statefulset.yaml + documentIndex: 0 + contains: + path: spec.template.spec.containers[0].env + content: + name: REDIS_PASSWORD + valueFrom: + secretKeyRef: + name: gitea-unittests-redis-cluster + key: redis-password + - it: "[redis-cluster] renders the referenced service" + template: charts/redis-cluster/templates/headless-svc.yaml + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: gitea-unittests-redis-cluster-headless + namespace: testing + - documentIndex: 0 + contains: + path: spec.ports + content: + name: tcp-redis + port: 6379 + targetPort: tcp-redis + - it: "[gitea] waits for redis-cluster to be up and running" + template: templates/gitea/init.yaml + asserts: + - documentIndex: 0 + matchRegex: + path: stringData["configure_gitea.sh"] + pattern: nc -vz -w2 gitea-unittests-redis-cluster-headless.testing.svc.cluster.local 6379 diff --git a/unittests/dependency-checks/customization-integrity-redis.yaml b/unittests/dependency-checks/customization-integrity-redis.yaml new file mode 100644 index 0000000..42779f3 --- /dev/null +++ b/unittests/dependency-checks/customization-integrity-redis.yaml @@ -0,0 +1,52 @@ +suite: Dependency checks | Customization integrity | redis +release: + name: gitea-unittests + namespace: testing +set: + redis-cluster: + enabled: false + redis: + enabled: true + architecture: standalone + global: + redis: + password: gitea-password + master: + count: 2 +tests: + - it: "[redis] configures correct 'master' nodes" + template: charts/redis/templates/master/application.yaml + asserts: + - documentIndex: 0 + equal: + path: spec.replicas + value: 2 + - it: "[redis] redis.global.redis.password is applied as expected" + template: charts/redis/templates/secret.yaml + asserts: + - documentIndex: 0 + equal: + path: data["redis-password"] + value: "Z2l0ZWEtcGFzc3dvcmQ=" + - it: "[redis] renders the referenced service" + template: charts/redis/templates/headless-svc.yaml + asserts: + - containsDocument: + kind: Service + apiVersion: v1 + name: gitea-unittests-redis-headless + namespace: testing + - documentIndex: 0 + contains: + path: spec.ports + content: + name: tcp-redis + port: 6379 + targetPort: redis + - it: "[gitea] waits for redis to be up and running" + template: templates/gitea/init.yaml + asserts: + - documentIndex: 0 + matchRegex: + path: stringData["configure_gitea.sh"] + pattern: nc -vz -w2 gitea-unittests-redis-headless.testing.svc.cluster.local 6379 diff --git a/unittests/dependency-major-image-check.yaml b/unittests/dependency-checks/major-image-bump.yaml similarity index 97% rename from unittests/dependency-major-image-check.yaml rename to unittests/dependency-checks/major-image-bump.yaml index 2646ade..506982b 100644 --- a/unittests/dependency-major-image-check.yaml +++ b/unittests/dependency-checks/major-image-bump.yaml @@ -1,4 +1,4 @@ -suite: Dependency update consistency +suite: Dependency checks | Major image bumps release: name: gitea-unittests namespace: testing