postgres-operator icon indicating copy to clipboard operation
postgres-operator copied to clipboard

Remove PVCs when cluster is deleted

Open aceeric opened this issue 7 years ago • 6 comments

When bringing up - and tearing down - test environments, I'd like to be able to configure the PG Operator to remove any PVCs that it created when a cluster is torn down. Looking at the pgo.yaml docs, and based on experience with the operator, it does not look like this is possible. When we delete a cluster, the PVCs remain and have to be manually removed.

The environment we would use this in is OpenShift 3.11

aceeric avatar Sep 27 '19 16:09 aceeric

If you use : $pgo delete cluster -b -d --all -n

The pvc are also removed

jose-joye avatar Oct 02 '19 11:10 jose-joye

The context here is: we have an operator that spins up Postgres by 1) subscribing the Postgres operator, and then 2) deploying resources that in turn cause the Postgres operator to instance a cluster. (This operator also spins up other backing components -- In other words - it's an "umbrella" operator that creates an entire stack.)

To tear down the entire stack of components, we delete the various top-level resources and then rely on the backing component operators to completely clean themselves up. As an analogy, if you bring up a Strimzi/Kafka cluster with persistent storage, then simply delete the Kafka cluster CR, the PVCs are also removed by the Strimzi operator.

The analogy for Postgres is, if the umbrella operator deletes the Pgcluster CR, then the PG operator should detect that and - if so configured - remove all child resources - including PVCs. We'd want this configurable because in production, you don't want this but in test, you may or may not. In a CI/CD pipeline with automated functional tests, you definitely want it.

Requiring our operator to have a copy of the pgo command and to run shell scripts is certainly possibly but it seems inconsistent with the clean-up approach used by other operators we're using.

aceeric avatar Oct 03 '19 12:10 aceeric

@aceeric

Currently, the Postgres Operator does not support a CR-based workflow as you have described but it is something we are looking into.

As another way of interfacing with the operator, take a look at the API Documentation here: https://crunchydata.github.io/postgres-operator/latest/gettingstarted/design/direct-api-calls/

While not CR based, it may make integration easier than using the operators binary command line to accomplish your goals.

Thanks

flamingdumpster avatar Oct 03 '19 13:10 flamingdumpster

Ok thanks

aceeric avatar Oct 03 '19 15:10 aceeric

by adding OwnerReference to the PVC you can delete PVCs by removing Owner - pg-cluster/deployment/etc WARNING autofailover may also delete PVC when promoting replica

lkhomenk avatar Nov 04 '19 10:11 lkhomenk

Note: in v4.2.0 the default behavior for pgo delete cluster is to delete the PVCs associated with it. To retain the PVCs, one must specify the --keep-data and --keep-backups flags.

Nothing has changed with respect to the CR-only workflow nor interfacing with the API.

jkatz avatar Dec 31 '19 21:12 jkatz