Skip to content

Commit

Permalink
Update makefile to generate kuttl tests
Browse files Browse the repository at this point in the history
All tests in the `testing/kuttl/e2e` directory will be templates and the
target `make generate-kuttl` will envsubst variables and output to a
gitignored `testing/kuttl/e2e-generated` directory

Tests from the sources directory have been synced with the e2e
directory. There were minor differences in the duplicated tests.

Tests in the e2e directory now have environment variables for the
postgres version and the psql connect image.
  • Loading branch information
jmckulk committed Mar 11, 2022
1 parent dc9d6a0 commit b5a9cc5
Show file tree
Hide file tree
Showing 61 changed files with 58 additions and 396 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.DS_Store
/vendor/
tools
/testing/kuttl/generated/
/testing/kuttl/e2e-generated/
36 changes: 10 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,34 +217,18 @@ check-kuttl:
${PGO_KUBE_CLIENT} ${KUTTL_TEST} \
--config testing/kuttl/kuttl-test.yaml

# Set reasonable default for KUTTL_ env vars for templating
KUTTL_PG_VERSION ?= 14
KUTTL_PG_UPGRADE_FROM_VERSION ?= 13
KUTTL_PSQL_IMAGE ?= registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0

# TODO: When I attempted to loop through the directories and find the yaml files,
# due to how makefile expands variables, each file would end up in each directory.
# So this implementation loops through to create the folders under generated
# and then loops through all the yaml files, using a `sed` substition to place them
# For safety, this removes the `testing/kuttl/generated` folder if it exists
.PHONY: generate-kuttl
generate-kuttl: export KUTTL_PG_VERSION ?= 14
generate-kuttl: export KUTTL_PSQL_IMAGE ?= registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
generate-kuttl:
[ ! -d testing/kuttl/generated ] || rm -r testing/kuttl/generated
for SRCDIR in $(shell ls testing/kuttl/source); do \
mkdir -p testing/kuttl/generated/$${SRCDIR}; \
done;
for FILEPATH in $(wildcard testing/kuttl/source/*/*.yaml); do \
NEW_FILEPATH=`echo $${FILEPATH} | sed 's/source/generated/'`; \
KUTTL_PG_VERSION=$(KUTTL_PG_VERSION) \
KUTTL_PG_UPGRADE_FROM_VERSION=$(KUTTL_PG_UPGRADE_FROM_VERSION) \
KUTTL_PSQL_IMAGE=$(KUTTL_PSQL_IMAGE) \
envsubst < $${FILEPATH} > $${NEW_FILEPATH}; \
done

.PHONY: check-generated-kuttl
check-generated-kuttl: generate-kuttl
${PGO_KUBE_CLIENT} ${KUTTL_TEST} \
--config testing/kuttl/kuttl-test-generated.yaml
[ ! -d testing/kuttl/e2e-generated ] || rm -r testing/kuttl/e2e-generated
bash -ceu ' \
render() { envsubst '"'"'$$KUTTL_PG_VERSION $$KUTTL_PSQL_IMAGE'"'"'; }; \
while [ $$# -gt 0 ]; do \
source="$${1}" target="$${1/e2e/e2e-generated}"; \
mkdir -p "$${target%/*}"; render < "$${source}" > "$${target}"; \
shift; \
done' - $(wildcard testing/kuttl/e2e/*/*.yaml)

.PHONY: check-generate
check-generate: generate-crd generate-deepcopy generate-rbac
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/cluster-start/00--cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: PostgresCluster
metadata:
name: cluster-start
spec:
postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
instances:
- name: instance1
dataVolumeClaimSpec:
Expand Down
4 changes: 3 additions & 1 deletion testing/kuttl/e2e/cluster-start/01--psql-connect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- -c
Expand All @@ -24,3 +24,5 @@ spec:
valueFrom: { secretKeyRef: { name: cluster-start-pguser-cluster-start, key: user } }
- name: PGPASSWORD
valueFrom: { secretKeyRef: { name: cluster-start-pguser-cluster-start, key: password } }
# Do not wait indefinitely.
- { name: PGCONNECT_TIMEOUT, value: '5' }
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/password-change/00--cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: PostgresCluster
metadata:
name: password-change
spec:
postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
instances:
- name: instance1
dataVolumeClaimSpec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- "$(PGURI)"
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/password-change/01--psql-connect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- -c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- "$(PGURI)"
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/password-change/03--psql-connect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- -c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- "$(PGURI)"
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/password-change/05--psql-connect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- -c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- "$(PGURI)"
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/password-change/07--psql-connect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- -c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- "$(PGURI)"
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/password-change/09--psql-connect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- -c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- "$(PGURI)"
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/password-change/11--psql-connect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- -c
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgadmin/01--cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ metadata:
name: interfaced
labels: { postgres-operator-test: kuttl }
spec:
postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
instances:
- name: instance1
replicas: 1
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgbackrest-init/00--cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: PostgresCluster
metadata:
name: init-pgbackrest
spec:
postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
instances:
- name: instance1
dataVolumeClaimSpec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
name: original
labels: { postgres-operator-test: kuttl }
spec:
postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
patroni:
dynamicConfiguration:
postgresql:
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgbackrest-restore/02--create-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
restartPolicy: Never
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
env:
- name: PGURI
valueFrom: { secretKeyRef: { name: original-pguser-original, key: uri } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
clusterName: original
repoName: repo1

postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
instances:
- dataVolumeClaimSpec: { accessModes: [ReadWriteOnce], resources: { requests: { storage: 1Gi } } }
backups:
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgbackrest-restore/05--check-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
restartPolicy: Never
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
env:
# Connect to the cluster using the restored database and original credentials.
- name: PGHOST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
name: original
labels: { postgres-operator-test: kuttl }
spec:
postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
patroni:
dynamicConfiguration:
postgresql:
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgbackrest-restore/09--add-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
restartPolicy: Never
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
env:
- name: PGURI
valueFrom: { secretKeyRef: { name: original-pguser-original, key: uri } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spec:
clusterName: original
repoName: repo1

postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
instances:
- dataVolumeClaimSpec: { accessModes: [ReadWriteOnce], resources: { requests: { storage: 1Gi } } }
backups:
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgbackrest-restore/12--check-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
restartPolicy: Never
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
env:
# Connect to the cluster using the restored database and original credentials.
- name: PGHOST
Expand Down
4 changes: 2 additions & 2 deletions testing/kuttl/e2e/pgbackrest-restore/16--check-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
restartPolicy: Never
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
env:
- name: PGURI
valueFrom: { secretKeyRef: { name: original-pguser-original, key: uri } }
Expand Down Expand Up @@ -57,7 +57,7 @@ spec:
restartPolicy: Never
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
env:
- name: PGPORT
valueFrom: { secretKeyRef: { name: original-pguser-original, key: port } }
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgbouncer/00--cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ metadata:
name: proxied
labels: { postgres-operator-test: kuttl }
spec:
postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
instances:
- name: instance1
replicas: 2
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgbouncer/01--psql-connect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
restartPolicy: Never
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
- psql
- -c
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgbouncer/10--read-certificate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
restartPolicy: Never
containers:
- name: openssl
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
env:
- name: PGHOST
valueFrom: { secretKeyRef: { name: proxied-pguser-proxied, key: pgbouncer-host } }
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgbouncer/11--open-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
- { name: tls, secret: { secretName: proxied-cluster-cert } }
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
env:
# Connect through PgBouncer.
- name: PGURI
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgbouncer/13--read-certificate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
restartPolicy: Never
containers:
- name: openssl
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
env:
- name: PGHOST
valueFrom: { secretKeyRef: { name: proxied-pguser-proxied, key: pgbouncer-host } }
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/pgbouncer/16--reconnect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
- { name: tls, secret: { secretName: proxied-cluster-cert } }
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
env:
# Connect through PgBouncer.
- name: PGURI
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/replica-read/00--cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: PostgresCluster
metadata:
name: replica-read
spec:
postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
instances:
- name: instance1
dataVolumeClaimSpec:
Expand Down
6 changes: 3 additions & 3 deletions testing/kuttl/e2e/replica-read/01--psql-replica-read.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ spec:
restartPolicy: "OnFailure"
containers:
- name: psql
image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-14.1-0
image: ${KUTTL_PSQL_IMAGE}
command:
# https://www.postgresql.org/docs/current/plpgsql-errors-and-messages.html#PLPGSQL-STATEMENTS-ASSERT
# If run on a non-replica, this assertion fails, resulting in the pod erroring
# Note: the `$$$$` is reduced to `$$` by kuttl
# - https://kuttl.dev/docs/testing/steps.html#running-commands
# Note: the `$$$$` is reduced to `$$` by Kubernetes.
# - https://kubernetes.io/docs/tasks/inject-data-application/
- psql
- -qc
- |
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/scaledown/00--create-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: PostgresCluster
metadata:
name: scaledown
spec:
postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
instances:
- name: instance1
dataVolumeClaimSpec:
Expand Down
2 changes: 1 addition & 1 deletion testing/kuttl/e2e/scaledown/01--update-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: PostgresCluster
metadata:
name: scaledown
spec:
postgresVersion: 14
postgresVersion: ${KUTTL_PG_VERSION}
instances:
- name: instance1
dataVolumeClaimSpec:
Expand Down
Loading

0 comments on commit b5a9cc5

Please sign in to comment.