Skip to content

Commit

Permalink
Merge pull request #229 from vshn/fix-security-upgrade-postgres
Browse files Browse the repository at this point in the history
Fix operator upgrade restart instance
  • Loading branch information
zugao committed Sep 9, 2024
2 parents 5b6952e + ee4bf09 commit e75bdb5
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 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" {
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 e75bdb5

Please sign in to comment.