From 3986090aea8e799a53b274ac53c4d7bcceaa3cdb Mon Sep 17 00:00:00 2001 From: ccremer Date: Tue, 11 Oct 2022 17:56:05 +0200 Subject: [PATCH] Add e2e test case for PostgreSQL --- test/e2e/postgresql/00-assert.yaml | 62 +++++++++++++++++++++++++++++ test/e2e/postgresql/00-install.yaml | 24 +++++++++++ test/e2e/postgresql/01-assert.yaml | 11 +++++ test/e2e/postgresql/01-connect.yaml | 42 +++++++++++++++++++ test/e2e/postgresql/02-delete.yaml | 14 +++++++ test/local.mk | 5 ++- 6 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 test/e2e/postgresql/00-assert.yaml create mode 100644 test/e2e/postgresql/00-install.yaml create mode 100644 test/e2e/postgresql/01-assert.yaml create mode 100644 test/e2e/postgresql/01-connect.yaml create mode 100644 test/e2e/postgresql/02-delete.yaml diff --git a/test/e2e/postgresql/00-assert.yaml b/test/e2e/postgresql/00-assert.yaml new file mode 100644 index 00000000..4356e68a --- /dev/null +++ b/test/e2e/postgresql/00-assert.yaml @@ -0,0 +1,62 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 600 +--- +apiVersion: exoscale.crossplane.io/v1 +kind: PostgreSQL +metadata: + name: e2e-test-postgresql + annotations: + crossplane.io/external-name: e2e-test-postgresql + finalizers: + - finalizer.managedresource.crossplane.io +spec: + forProvider: + backup: + timeOfDay: '13:00:00' + ipFilter: + - 0.0.0.0/0 + maintenance: + dayOfWeek: monday + timeOfDay: '12:00:00' + size: + plan: hobbyist-2 + version: '14' + zone: ch-dk-2 + pgSettings: + timezone: Europe/Zurich + providerConfigRef: + name: provider-config + writeConnectionSecretToRef: + name: e2e-test-postgresql-details + namespace: default +status: + atProvider: + backup: + timeOfDay: '13:00:00' + maintenance: + dayOfWeek: monday + timeOfDay: '12:00:00' + noteStates: + - name: e2e-test-postgresql-1 + role: master + state: running + conditions: + - message: The service is running + reason: Available + status: 'True' + type: Ready + - reason: ReconcileSuccess + status: 'True' + type: Synced +--- +apiVersion: v1 +kind: Secret +type: connection.crossplane.io/v1alpha1 +metadata: + name: e2e-test-postgresql-details + namespace: default + ownerReferences: + - apiVersion: exoscale.crossplane.io/v1 + kind: PostgreSQL + name: e2e-test-postgresql diff --git a/test/e2e/postgresql/00-install.yaml b/test/e2e/postgresql/00-install.yaml new file mode 100644 index 00000000..8afc282c --- /dev/null +++ b/test/e2e/postgresql/00-install.yaml @@ -0,0 +1,24 @@ +apiVersion: exoscale.crossplane.io/v1 +kind: PostgreSQL +metadata: + name: e2e-test-postgresql +spec: + forProvider: + backup: + timeOfDay: "13:00:00" + ipFilter: + - 0.0.0.0/0 + maintenance: + dayOfWeek: monday + timeOfDay: "12:00:00" + size: + plan: hobbyist-2 + version: "14" + zone: ch-dk-2 + pgSettings: + timezone: Europe/Zurich + providerConfigRef: + name: provider-config + writeConnectionSecretToRef: + name: e2e-test-postgresql-details + namespace: default diff --git a/test/e2e/postgresql/01-assert.yaml b/test/e2e/postgresql/01-assert.yaml new file mode 100644 index 00000000..1ee4b1f5 --- /dev/null +++ b/test/e2e/postgresql/01-assert.yaml @@ -0,0 +1,11 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: connect-postgresql + namespace: default +status: + conditions: + - type: Complete + status: 'True' + succeeded: 1 + ready: 0 diff --git a/test/e2e/postgresql/01-connect.yaml b/test/e2e/postgresql/01-connect.yaml new file mode 100644 index 00000000..d148a3fc --- /dev/null +++ b/test/e2e/postgresql/01-connect.yaml @@ -0,0 +1,42 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: connect-postgresql + namespace: default +spec: + backoffLimit: 5 + template: + metadata: + labels: + e2e-test: postgresql + spec: + restartPolicy: Never + containers: + - name: connect + image: docker.io/bitnami/postgresql:latest + imagePullPolicy: IfNotPresent + command: + - bash + securityContext: + # with an arbitrary user, "psql" complains it can't find the user ID. + # For e2e test using root should be ok + runAsUser: 0 + args: + - -c + - echo "Testing Select...\n" && PGDATABASE="$POSTGRESQL_DB" PGUSER="$POSTGRESQL_USER" PGPASSWORD="$POSTGRESQL_PASSWORD" PGHOST="$POSTGRESQL_HOST" PGPORT="$POSTGRESQL_PORT" psql -c "select 1;" + env: + - name: PGSSLMODE + value: verify-ca + envFrom: + - secretRef: + name: e2e-test-postgresql-details + volumeMounts: + - name: ca + mountPath: /root/.postgresql + volumes: + - name: ca + secret: + secretName: e2e-test-postgresql-details + items: + - key: ca.crt + path: root.crt diff --git a/test/e2e/postgresql/02-delete.yaml b/test/e2e/postgresql/02-delete.yaml new file mode 100644 index 00000000..eb38ef3c --- /dev/null +++ b/test/e2e/postgresql/02-delete.yaml @@ -0,0 +1,14 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +delete: + # This will wait until resources are really gone + - apiVersion: batch/v1 + kind: Job + name: connect-postgresql + - apiVersion: v1 + kind: Pod + labels: + e2e-test: postgresql + - apiVersion: exoscale.crossplane.io/v1 + kind: PostgreSQL + name: e2e-test-postgresql diff --git a/test/local.mk b/test/local.mk index 0252e510..68a19cf1 100644 --- a/test/local.mk +++ b/test/local.mk @@ -133,6 +133,7 @@ test-e2e: $(kuttl_bin) $(mc_bin) local-install provider-config ## E2E tests .PHONY: .e2e-test-clean .e2e-test-clean: export KUBECONFIG = $(KIND_KUBECONFIG) .e2e-test-clean: - if [ -f $(KIND_KUBECONFIG) ]; then kubectl delete buckets --all; else echo "no kubeconfig found"; fi - if [ -f $(KIND_KUBECONFIG) ]; then kubectl delete iamkeys --all; else echo "no kubeconfig found"; fi + @if [ -f $(KIND_KUBECONFIG) ]; then kubectl delete buckets --all; else echo "no kubeconfig found"; fi + @if [ -f $(KIND_KUBECONFIG) ]; then kubectl delete iamkeys --all; else echo "no kubeconfig found"; fi + @if [ -f $(KIND_KUBECONFIG) ]; then kubectl delete postgresql --all; else echo "no kubeconfig found"; fi rm -f $(kuttl_bin) $(mc_bin)