Skip to content

Commit

Permalink
return create and sync error, not setStatus error (#2574)
Browse files Browse the repository at this point in the history
* return create and sync error, not possible status set error
* update documentation and improve deletion logs
  • Loading branch information
FxKu committed Mar 12, 2024
1 parent a63a075 commit 8bd9080
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
9 changes: 5 additions & 4 deletions docs/reference/operator_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
14 changes: 9 additions & 5 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions pkg/cluster/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8bd9080

Please sign in to comment.