diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index a19cf9217..05af1e0a6 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -1063,25 +1063,30 @@ func (c *Cluster) Delete() error { c.logger.Warningf("could not delete event streams: %v", err) c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Delete", "Could not delete event streams: %v", err) } + var anyErrors = false // delete the backup job before the stateful set of the cluster to prevent connections to non-existing pods // deleting the cron job also removes pods and batch jobs it created if err := c.deleteLogicalBackupJob(); err != nil { + anyErrors = true c.logger.Warningf("could not remove the logical backup k8s cron job; %v", err) c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Delete", "Could not remove the logical backup k8s cron job; %v", err) } if err := c.deleteStatefulSet(); err != nil { + anyErrors = true c.logger.Warningf("could not delete statefulset: %v", err) c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Delete", "Could not delete statefulset: %v", err) } if err := c.deleteSecrets(); err != nil { + anyErrors = true c.logger.Warningf("could not delete secrets: %v", err) c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Delete", "Could not delete secrets: %v", err) } if err := c.deletePodDisruptionBudget(); err != nil { + anyErrors = true c.logger.Warningf("could not delete pod disruption budget: %v", err) c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Delete", "Could not delete pod disruption budget: %v", err) } @@ -1090,18 +1095,21 @@ func (c *Cluster) Delete() error { if !c.patroniKubernetesUseConfigMaps() { if err := c.deleteEndpoint(role); err != nil { + anyErrors = true c.logger.Warningf("could not delete %s endpoint: %v", role, err) c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Delete", "Could not delete %s endpoint: %v", role, err) } } if err := c.deleteService(role); err != nil { + anyErrors = true c.logger.Warningf("could not delete %s service: %v", role, err) c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Delete", "Could not delete %s service: %v", role, err) } } if err := c.deletePatroniClusterObjects(); err != nil { + anyErrors = true c.logger.Warningf("could not remove leftover patroni objects; %v", err) c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Delete", "Could not remove leftover patroni objects; %v", err) } @@ -1111,17 +1119,22 @@ func (c *Cluster) Delete() error { // wrong for _, role := range [2]PostgresRole{Master, Replica} { if err := c.deleteConnectionPooler(role); err != nil { + anyErrors = true c.logger.Warningf("could not remove connection pooler: %v", err) c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeWarning, "Delete", "Could not remove connection pooler: %v", err) } } // If we are done deleting our various resources we remove the finalizer to let K8S finally delete the Postgres CR - c.logger.Info("Done cleaning up, removing our finalizer.") + if anyErrors { + c.eventRecorder.Event(c.GetReference(), v1.EventTypeWarning, "Delete", "Some resources could be successfully deleted yet") + return fmt.Errorf("some error(s) occured when deleting resources, NOT removing finalizer yet") + } if err := c.RemoveFinalizer(); err != nil { return fmt.Errorf("Done cleaning up, but error when trying to remove our finalizer: %v", err) } + c.logger.Info("Done cleaning up our resources, removed finalizer.") return nil }