From 5e4312ad4799f50bc08e13147d78a9a7559a22a2 Mon Sep 17 00:00:00 2001 From: Gabriel Saratura Date: Thu, 5 Sep 2024 15:12:27 +0200 Subject: [PATCH 1/2] Fix operator upgrade restart instance --- apis/stackgres/v1/sgcluster.go | 3 ++- .../functions/vshnpostgres/restart.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apis/stackgres/v1/sgcluster.go b/apis/stackgres/v1/sgcluster.go index 79e638f49..cb783e1ee 100644 --- a/apis/stackgres/v1/sgcluster.go +++ b/apis/stackgres/v1/sgcluster.go @@ -5,10 +5,11 @@ import ( ) const SGClusterConditionTypePendingRestart = "PendingRestart" +const SGClusterConditionTypePendingUpgrade = "PendingUpgrade" // +kubebuilder:object:root=true -// VSHNPostgreSQL is the API for creating Postgresql clusters. +// SGCluster is the API for creating Postgresql clusters. type SGCluster struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` diff --git a/pkg/comp-functions/functions/vshnpostgres/restart.go b/pkg/comp-functions/functions/vshnpostgres/restart.go index ab8ddba31..aff695494 100644 --- a/pkg/comp-functions/functions/vshnpostgres/restart.go +++ b/pkg/comp-functions/functions/vshnpostgres/restart.go @@ -68,10 +68,15 @@ func getPendingRestart(ctx context.Context, svc *runtime.ServiceRuntime) (time.T return time.Time{}, nil } + if hasPendingUpgrade(*cluster.Status.Conditions) { + return time.Time{}, nil + } + for _, cond := range *cluster.Status.Conditions { if cond.Type == nil || *cond.Type != sgv1.SGClusterConditionTypePendingRestart || cond.Status == nil || cond.LastTransitionTime == nil { continue } + status, err := strconv.ParseBool(*cond.Status) if err != nil || !status { continue @@ -89,6 +94,16 @@ func getPendingRestart(ctx context.Context, svc *runtime.ServiceRuntime) (time.T return time.Time{}, nil } +// In case the operator was updated and the PostgreSQL clusters requires immediate restart we will postpone it during the maintenance +func hasPendingUpgrade(items []sgv1.SGClusterStatusConditionsItem) bool { + for _, i := range items { + if *i.Type == sgv1.SGClusterConditionTypePendingUpgrade && *i.Status == "True" { + return true + } + } + return false +} + func scheduleRestart(ctx context.Context, svc *runtime.ServiceRuntime, compName string, restartTime time.Time) error { name := fmt.Sprintf("pg-restart-%d", restartTime.Unix()) ops := &sgv1.SGDbOps{ From ee4bf091ea33f73db1960e319fee9e9150bf60fb Mon Sep 17 00:00:00 2001 From: Gabriel Saratura <58511627+zugao@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:10:05 +0200 Subject: [PATCH 2/2] Update pkg/comp-functions/functions/vshnpostgres/restart.go Co-authored-by: Kidswiss --- pkg/comp-functions/functions/vshnpostgres/restart.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/comp-functions/functions/vshnpostgres/restart.go b/pkg/comp-functions/functions/vshnpostgres/restart.go index aff695494..5af97add5 100644 --- a/pkg/comp-functions/functions/vshnpostgres/restart.go +++ b/pkg/comp-functions/functions/vshnpostgres/restart.go @@ -94,7 +94,7 @@ func getPendingRestart(ctx context.Context, svc *runtime.ServiceRuntime) (time.T return time.Time{}, nil } -// In case the operator was updated and the PostgreSQL clusters requires immediate restart we will postpone it during the maintenance +// In case the operator was updated and the PostgreSQL clusters require a security maintenance, we ensure that it only happens during the maintenance window func hasPendingUpgrade(items []sgv1.SGClusterStatusConditionsItem) bool { for _, i := range items { if *i.Type == sgv1.SGClusterConditionTypePendingUpgrade && *i.Status == "True" {