-
Notifications
You must be signed in to change notification settings - Fork 622
Move pgbackrest-restore test to Kyverno Chainsaw #4228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cbandy
wants to merge
3
commits into
CrunchyData:main
Choose a base branch
from
cbandy:restore-e2e
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,11 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha2 | ||
kind: Configuration | ||
metadata: | ||
name: end-to-end | ||
spec: | ||
namespace: | ||
template: | ||
metadata: | ||
labels: { postgres-operator-test: chainsaw } | ||
timeouts: | ||
assert: 3m |
57 changes: 57 additions & 0 deletions
57
testing/chainsaw/e2e/pgbackrest-restore/01-create-cluster.yaml
This file contains hidden or 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,57 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: StepTemplate | ||
metadata: | ||
name: 01-create-cluster | ||
spec: | ||
try: | ||
- | ||
description: > | ||
Create a cluster with a single pgBackRest repository | ||
and some parameters that require attention during PostgreSQL recovery | ||
apply: | ||
resource: | ||
apiVersion: postgres-operator.crunchydata.com/v1beta1 | ||
kind: PostgresCluster | ||
metadata: | ||
name: original | ||
spec: | ||
postgresVersion: ($postgres.version) | ||
config: | ||
parameters: | ||
archive_timeout: 15 | ||
checkpoint_timeout: 30 | ||
max_connections: 200 | ||
instances: | ||
- dataVolumeClaimSpec: ($volume) | ||
tablespaceVolumes: | ||
- { name: barn, dataVolumeClaimSpec: ($volume) } | ||
replicas: 2 | ||
backups: | ||
pgbackrest: | ||
manual: | ||
repoName: repo1 | ||
repos: | ||
- name: repo1 | ||
volume: | ||
volumeClaimSpec: ($volume) | ||
|
||
- | ||
description: > | ||
Wait for the replica backup to complete | ||
assert: | ||
resource: | ||
apiVersion: postgres-operator.crunchydata.com/v1beta1 | ||
kind: PostgresCluster | ||
metadata: | ||
name: original | ||
status: | ||
pgbackrest: | ||
repos: | ||
- name: repo1 | ||
replicaCreateBackupComplete: true | ||
stanzaCreated: true | ||
|
||
catch: | ||
- podLogs: | ||
selector: postgres-operator.crunchydata.com/cluster in (original) | ||
tail: 50 |
71 changes: 71 additions & 0 deletions
71
testing/chainsaw/e2e/pgbackrest-restore/02-create-data.yaml
This file contains hidden or 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,71 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: StepTemplate | ||
metadata: | ||
name: 02-create-data | ||
spec: | ||
try: | ||
- | ||
description: > | ||
Create a tablespace and grant access to all Postgres users | ||
script: | ||
skipCommandOutput: true | ||
content: | | ||
PRIMARY=$( | ||
kubectl get pod --namespace "${NAMESPACE}" \ | ||
--output name --selector ' | ||
postgres-operator.crunchydata.com/cluster=original, | ||
postgres-operator.crunchydata.com/role=master' | ||
) | ||
|
||
kubectl exec --stdin --namespace "${NAMESPACE}" "${PRIMARY}" -- psql -q --file=- <<'SQL' | ||
CREATE TABLESPACE barn LOCATION '/tablespaces/barn/data'; | ||
GRANT ALL ON TABLESPACE barn TO public; | ||
SQL | ||
|
||
- | ||
description: > | ||
Create some data that will be restored | ||
apply: | ||
resource: | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: original-data | ||
spec: | ||
backoffLimit: 3 | ||
template: | ||
spec: | ||
restartPolicy: Never | ||
containers: | ||
- name: psql | ||
image: ($psql.image) | ||
env: | ||
- ($psql.connect) | ||
- name: PGURI | ||
valueFrom: { secretKeyRef: { name: original-pguser-original, key: uri } } | ||
command: | ||
- psql | ||
- $(PGURI) | ||
- --set=ON_ERROR_STOP=1 | ||
- --command | ||
- | | ||
CREATE SCHEMA IF NOT EXISTS "original"; | ||
CREATE TABLE important (data) AS VALUES ('treasure'); | ||
CREATE TABLE cows (name) TABLESPACE barn AS VALUES ('nellie'); | ||
|
||
- assert: | ||
resource: | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: original-data | ||
status: | ||
succeeded: 1 | ||
|
||
catch: | ||
- | ||
description: > | ||
Read all log lines from the job pods | ||
podLogs: | ||
selector: batch.kubernetes.io/job-name in (original-data) | ||
tail: -1 |
33 changes: 33 additions & 0 deletions
33
testing/chainsaw/e2e/pgbackrest-restore/03-create-backup.yaml
This file contains hidden or 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,33 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: StepTemplate | ||
metadata: | ||
name: 03-create-backup | ||
spec: | ||
try: | ||
- | ||
description: > | ||
Annotate the cluster to trigger a backup | ||
patch: | ||
resource: | ||
apiVersion: postgres-operator.crunchydata.com/v1beta1 | ||
kind: PostgresCluster | ||
metadata: | ||
name: original | ||
annotations: | ||
postgres-operator.crunchydata.com/pgbackrest-backup: one | ||
|
||
- | ||
description: > | ||
Wait for it to complete | ||
assert: | ||
resource: | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
annotations: | ||
postgres-operator.crunchydata.com/pgbackrest-backup: one | ||
labels: | ||
postgres-operator.crunchydata.com/cluster: original | ||
postgres-operator.crunchydata.com/pgbackrest-backup: manual | ||
status: | ||
succeeded: 1 |
83 changes: 83 additions & 0 deletions
83
testing/chainsaw/e2e/pgbackrest-restore/11-update-cluster.yaml
This file contains hidden or 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,83 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: StepTemplate | ||
metadata: | ||
name: 11-update-cluster | ||
spec: | ||
try: | ||
- | ||
description: > | ||
Find the primary pod | ||
command: | ||
outputs: | ||
- name: primary | ||
value: (trim_space($stdout)) | ||
entrypoint: kubectl | ||
args: | ||
- get | ||
- pod | ||
- --namespace=${NAMESPACE} | ||
- --output=name | ||
- --selector | ||
- >- | ||
postgres-operator.crunchydata.com/cluster=original, | ||
postgres-operator.crunchydata.com/role=master | ||
|
||
- | ||
description: > | ||
Read the timestamp at which PostgreSQL last started | ||
command: | ||
outputs: | ||
- name: start_before | ||
value: (trim_space($stdout)) | ||
env: | ||
- name: PRIMARY | ||
value: ($primary) | ||
entrypoint: kubectl | ||
args: | ||
- exec | ||
- --namespace=${NAMESPACE} | ||
- ${PRIMARY} | ||
- -- | ||
- psql | ||
- -qAt | ||
- --command | ||
- SELECT pg_postmaster_start_time() | ||
|
||
- | ||
description: > | ||
Update the cluster with parameters that require attention during recovery | ||
patch: | ||
resource: | ||
apiVersion: postgres-operator.crunchydata.com/v1beta1 | ||
kind: PostgresCluster | ||
metadata: | ||
name: original | ||
spec: | ||
config: | ||
parameters: | ||
max_connections: 1000 | ||
|
||
- | ||
description: > | ||
Wait for Postgres to restart | ||
script: | ||
skipCommandOutput: true | ||
timeout: 30s | ||
env: | ||
- name: BEFORE | ||
value: ($start_before) | ||
- name: PRIMARY | ||
value: ($primary) | ||
content: | | ||
while true; do | ||
START=$( | ||
kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \ | ||
-- psql -qAt --command 'SELECT pg_postmaster_start_time()' | ||
) | ||
if [ "${START}" ] && [ "${START}" != "${BEFORE}" ]; then break; else sleep 1; fi | ||
done | ||
echo "${START} != ${BEFORE}" | ||
|
||
# Reset counters in the "pg_stat_archiver" view. | ||
kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \ | ||
-- psql -qb --command "SELECT pg_stat_reset_shared('archiver')" --output /dev/null |
74 changes: 74 additions & 0 deletions
74
testing/chainsaw/e2e/pgbackrest-restore/12-update-data.yaml
This file contains hidden or 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,74 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: StepTemplate | ||
metadata: | ||
name: 12-update-data | ||
spec: | ||
try: | ||
- | ||
description: > | ||
Add more data to the WAL archive | ||
apply: | ||
resource: | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: original-more-data | ||
spec: | ||
backoffLimit: 3 | ||
template: | ||
spec: | ||
restartPolicy: Never | ||
containers: | ||
- name: psql | ||
image: ($psql.image) | ||
env: | ||
- ($psql.connect) | ||
- name: PGURI | ||
valueFrom: { secretKeyRef: { name: original-pguser-original, key: uri } } | ||
|
||
command: | ||
- psql | ||
- $(PGURI) | ||
- --set=ON_ERROR_STOP=1 | ||
- --command | ||
- | | ||
INSERT INTO important (data) VALUES ('water'), ('socks'); | ||
- assert: | ||
resource: | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
name: original-more-data | ||
status: | ||
succeeded: 1 | ||
|
||
- | ||
description: > | ||
Wait for the data to be sent to the WAL archive | ||
script: | ||
skipCommandOutput: true | ||
content: | | ||
PRIMARY=$( | ||
kubectl get pod --namespace "${NAMESPACE}" \ | ||
--output name --selector ' | ||
postgres-operator.crunchydata.com/cluster=original, | ||
postgres-operator.crunchydata.com/role=master' | ||
) | ||
kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \ | ||
-- psql --command 'SELECT pg_switch_wal()' --pset footer=off | ||
# A prior step reset the "pg_stat_archiver" counters, so anything more than zero should suffice. | ||
while [ 0 = "$( | ||
kubectl exec --namespace "${NAMESPACE}" "${PRIMARY}" \ | ||
-- psql -qAt --command 'SELECT archived_count FROM pg_stat_archiver' | ||
)" ]; do sleep 1; done | ||
catch: | ||
- | ||
description: > | ||
Read all log lines from the job pods | ||
podLogs: | ||
selector: batch.kubernetes.io/job-name in (original-more-data) | ||
tail: -1 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to install KUTTL any longer?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Make targets do
go run ...@latest
by default. The binary download is faster, but not as easy tolatest
.I'm on the fence. Do you have a preference?