From 8bd9080798b306190ff537e0b49744a40a848d4d Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Tue, 12 Mar 2024 16:31:59 +0100 Subject: [PATCH] return create and sync error, not setStatus error (#2574) * return create and sync error, not possible status set error * update documentation and improve deletion logs --- docs/reference/operator_parameters.md | 9 +++++---- pkg/cluster/cluster.go | 14 +++++++++----- pkg/cluster/sync.go | 13 ++++++++----- pkg/controller/postgresql.go | 1 - 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/docs/reference/operator_parameters.md b/docs/reference/operator_parameters.md index a453e8343..00e648bb5 100644 --- a/docs/reference/operator_parameters.md +++ b/docs/reference/operator_parameters.md @@ -339,10 +339,11 @@ configuration they are grouped under the `kubernetes` key. cannot fully sync it, there can be leftovers. By enabling finalizers the operator will ensure all managed resources are deleted prior to the Postgresql resource. There is a trade-off though: The deletion is only - performed at the next cluster SYNC cycle when finding a `deletionTimestamp` - in the metadata and not immediately after issueing a delete command. The - final removal of the custom resource will add a DELETE event to the worker - queue but the child resources are already gone at this point. + performed after the next two SYNC cycles with the first one updating the + internal spec and the latter reacting on the `deletionTimestamp` while + processing the SYNC event. The final removal of the custom resource will + add a DELETE event to the worker queue but the child resources are already + gone at this point. The default is `false`. * **enable_pod_disruption_budget** diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index fad7965ba..1b1239f34 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -254,14 +254,18 @@ func (c *Cluster) Create() (err error) { ) defer func() { - var pgUpdatedStatus *acidv1.Postgresql + var ( + pgUpdatedStatus *acidv1.Postgresql + errStatus error + ) if err == nil { - pgUpdatedStatus, err = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusRunning) //TODO: are you sure it's running? + pgUpdatedStatus, errStatus = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusRunning) //TODO: are you sure it's running? } else { - pgUpdatedStatus, err = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusAddFailed) + c.logger.Warningf("cluster created failed: %v", err) + pgUpdatedStatus, errStatus = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusAddFailed) } - if err != nil { - c.logger.Warningf("could not set cluster status: %v", err) + if errStatus != nil { + c.logger.Warningf("could not set cluster status: %v", errStatus) } if pgUpdatedStatus != nil { c.setSpec(pgUpdatedStatus) diff --git a/pkg/cluster/sync.go b/pkg/cluster/sync.go index 498757251..3a48e1082 100644 --- a/pkg/cluster/sync.go +++ b/pkg/cluster/sync.go @@ -41,15 +41,18 @@ func (c *Cluster) Sync(newSpec *acidv1.Postgresql) error { c.setSpec(newSpec) defer func() { - var pgUpdatedStatus *acidv1.Postgresql + var ( + pgUpdatedStatus *acidv1.Postgresql + errStatus error + ) if err != nil { c.logger.Warningf("error while syncing cluster state: %v", err) - pgUpdatedStatus, err = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusSyncFailed) + pgUpdatedStatus, errStatus = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusSyncFailed) } else if !c.Status.Running() { - pgUpdatedStatus, err = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusRunning) + pgUpdatedStatus, errStatus = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusRunning) } - if err != nil { - c.logger.Warningf("could not set cluster status: %v", err) + if errStatus != nil { + c.logger.Warningf("could not set cluster status: %v", errStatus) } if pgUpdatedStatus != nil { c.setSpec(pgUpdatedStatus) diff --git a/pkg/controller/postgresql.go b/pkg/controller/postgresql.go index 45d520e7f..accc345ad 100644 --- a/pkg/controller/postgresql.go +++ b/pkg/controller/postgresql.go @@ -339,7 +339,6 @@ func (c *Controller) processEvent(event ClusterEvent) { lg.Error(cl.Error) return } - lg.Infof("cluster has been deleted") } else { if err = cl.Sync(event.NewSpec); err != nil { cl.Error = fmt.Sprintf("could not sync cluster: %v", err)