Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix operator upgrade restart instance #229

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
zugao marked this conversation as resolved.
Show resolved Hide resolved
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
Loading