Remove PVCs when cluster is deleted
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
If you use :
$pgo delete cluster -b -d --all
The pvc are also removed
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
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
Ok thanks
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
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.