Skip to content

Commit

Permalink
Fix operator upgrade restart instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Saratura committed Sep 5, 2024
1 parent 5b6952e commit 5e4312a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apis/stackgres/v1/sgcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
15 changes: 15 additions & 0 deletions pkg/comp-functions/functions/vshnpostgres/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand Down

0 comments on commit 5e4312a

Please sign in to comment.