-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add replica exporter test and fix a go test
- Loading branch information
Showing
6 changed files
with
101 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: kuttl.dev/v1beta1 | ||
kind: TestStep | ||
apply: | ||
- files/exporter-replica-cluster.yaml | ||
assert: | ||
- files/exporter-replica-cluster-checks.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
apiVersion: kuttl.dev/v1beta1 | ||
kind: TestAssert | ||
commands: | ||
# First, check that all containers in the instance(s) pod are ready | ||
# Then, grab the exporter metrics output and check that there were no scrape errors | ||
# Finally, ensure the monitoring user exists and is configured | ||
- script: | | ||
retry() { bash -ceu 'printf "$1\nSleeping...\n" && sleep 5' - "$@"; } | ||
check_containers_ready() { bash -ceu 'echo "$1" | jq -e ".[] | select(.type==\"ContainersReady\") | .status==\"True\""' - "$@"; } | ||
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; } | ||
replica=$(kubectl get pods -o name -n "${NAMESPACE}" \ | ||
-l postgres-operator.crunchydata.com/cluster=exporter-replica \ | ||
-l postgres-operator.crunchydata.com/crunchy-postgres-exporter=true \ | ||
-l postgres-operator.crunchydata.com/role=replica) | ||
[ "$replica" = "" ] && retry "Replica Pod not found" && exit 1 | ||
replica_condition_json=$(kubectl get "${replica}" -n "${NAMESPACE}" -o jsonpath="{.status.conditions}") | ||
[ "$replica_condition_json" = "" ] && retry "Replica conditions not found" && exit 1 | ||
{ | ||
check_containers_ready "$replica_condition_json" | ||
} || { | ||
retry "containers not ready" | ||
exit 1 | ||
} | ||
kubectl exec --stdin "${replica}" --namespace "${NAMESPACE}" -c database \ | ||
-- psql -qb --set ON_ERROR_STOP=1 --file=- <<'SQL' | ||
DO $$ | ||
DECLARE | ||
result record; | ||
BEGIN | ||
SELECT * INTO result FROM pg_catalog.pg_roles WHERE rolname = 'ccp_monitoring'; | ||
ASSERT FOUND, 'user not found'; | ||
END $$ | ||
SQL | ||
collectors: | ||
# Grab the exporter container logs on failure | ||
- type: pod | ||
selector: "postgres-operator.crunchydata.com/cluster=exporter-replica,postgres-operator.crunchydata.com/crunchy-postgres-exporter=true" | ||
container: exporter | ||
# Grab the pod describe output | ||
- type: command | ||
command: kubectl -n $NAMESPACE describe pods --selector postgres-operator.crunchydata.com/cluster=exporter-replica,postgres-operator.crunchydata.com/crunchy-postgres-exporter=true |
24 changes: 24 additions & 0 deletions
24
testing/kuttl/e2e/exporter-replica/files/exporter-replica-cluster-checks.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: postgres-operator.crunchydata.com/v1beta1 | ||
kind: PostgresCluster | ||
metadata: | ||
name: exporter-replica | ||
status: | ||
instances: | ||
- name: instance1 | ||
readyReplicas: 2 | ||
replicas: 2 | ||
updatedReplicas: 2 | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
labels: | ||
postgres-operator.crunchydata.com/cluster: exporter-replica | ||
postgres-operator.crunchydata.com/crunchy-postgres-exporter: "true" | ||
status: | ||
phase: Running | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: exporter-replica-exporter-queries-config |
19 changes: 19 additions & 0 deletions
19
testing/kuttl/e2e/exporter-replica/files/exporter-replica-cluster.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: postgres-operator.crunchydata.com/v1beta1 | ||
kind: PostgresCluster | ||
metadata: | ||
name: exporter-replica | ||
spec: | ||
postgresVersion: ${KUTTL_PG_VERSION} | ||
instances: | ||
- name: instance1 | ||
replicas: 2 | ||
dataVolumeClaimSpec: { accessModes: [ReadWriteOnce], resources: { requests: { storage: 1Gi } } } | ||
backups: | ||
pgbackrest: | ||
repos: | ||
- name: repo1 | ||
volume: | ||
volumeClaimSpec: { accessModes: [ReadWriteOnce], resources: { requests: { storage: 1Gi } } } | ||
monitoring: | ||
pgmonitor: | ||
exporter: {} |