diff --git a/docs/reference/operator_parameters.md b/docs/reference/operator_parameters.md index 86eedd33c..2ab36fcb0 100644 --- a/docs/reference/operator_parameters.md +++ b/docs/reference/operator_parameters.md @@ -131,6 +131,10 @@ Those are top-level keys, containing both leaf keys and groups. container, change the [operator deployment manually](../../manifests/postgres-operator.yaml#L20). The default is `false`. +* **should_delete_unused_pvc** + Tells the operator to delete persistent volume claims of no longer running pods. That removes respective persistent volumes because operator configures them with the 'Delete' reclaim policy. Note operator deletes unused PVCs for clusters created both before and after this option is turned on. Deletion is not guaranteed: When it fails, operator retries at next Sync() event. + The default is `false`. + ## Postgres users Parameters describing Postgres users. In a CRD-configuration, they are grouped diff --git a/manifests/configmap.yaml b/manifests/configmap.yaml index 0300b5495..572e63c77 100644 --- a/manifests/configmap.yaml +++ b/manifests/configmap.yaml @@ -88,5 +88,6 @@ data: # teams_api_url: http://fake-teams-api.default.svc.cluster.local # toleration: "" # wal_s3_bucket: "" + # should_delete_unused_pvc: "false" watched_namespace: "*" # listen to all namespaces workers: "4" diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index e97843373..c0b31d776 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -634,8 +634,7 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error { } }() - // delete persistent volume claim after scale down - if oldSpec.Spec.NumberOfInstances > newSpec.Spec.NumberOfInstances { + if c.OpConfig.ShouldDeleteUnusedPVC && oldSpec.Spec.NumberOfInstances > newSpec.Spec.NumberOfInstances { c.logger.Debug("deleting pvc of shut down pods") for i := oldSpec.Spec.NumberOfInstances - 1; i >= newSpec.Spec.NumberOfInstances; i-- { diff --git a/pkg/cluster/sync.go b/pkg/cluster/sync.go index ffe1cb28e..78b6302a2 100644 --- a/pkg/cluster/sync.go +++ b/pkg/cluster/sync.go @@ -111,8 +111,9 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error { // remove unused PVCs in case deleting them during scale down failed; see Update() // the last pvc stays until the cluster is explicitly deleted as opposed to being scaled down to 0 pods - if c.getNumberOfInstances(&c.Spec) > 0 { + if c.OpConfig.ShouldDeleteUnusedPVC && c.getNumberOfInstances(&c.Spec) > 0 { + // XXX that also deletes PVC of pods shut down before this change is deployed for i := c.getNumberOfInstances(&c.Spec); ; i++ { podIndex := strconv.Itoa(int(i)) pvcName := "pgdata-" + c.Name + "-" + podIndex diff --git a/pkg/util/config/config.go b/pkg/util/config/config.go index fee65be81..a8380953e 100644 --- a/pkg/util/config/config.go +++ b/pkg/util/config/config.go @@ -137,6 +137,7 @@ type Config struct { ProtectedRoles []string `name:"protected_role_names" default:"admin"` PostgresSuperuserTeams []string `name:"postgres_superuser_teams" default:""` SetMemoryRequestToLimit bool `name:"set_memory_request_to_limit" default:"false"` + ShouldDeleteUnusedPVC bool `name:"should_delete_unused_pvc" default:"false"` } // MustMarshal marshals the config or panics