Skip to content

Commit

Permalink
consider it for rollingUpdate as well
Browse files Browse the repository at this point in the history
  • Loading branch information
hughcapet committed Jan 7, 2025
1 parent a67621a commit 3baa072
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
6 changes: 6 additions & 0 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,12 @@ func (c *Cluster) Switchover(curMaster *v1.Pod, candidate spec.NamespacedName) e

var err error
c.logger.Debugf("switching over from %q to %q", curMaster.Name, candidate)

if !isInMaintenanceWindow(c.Spec.MaintenanceWindows) {
c.logger.Infof("skipping switchover, not in maintenance window")
return nil
}

c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "Switchover", "Switching over from %q to %q", curMaster.Name, candidate)
stopCh := make(chan struct{})
ch := c.registerPodSubscriber(candidate)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/majorversionupgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (c *Cluster) majorVersionUpgrade() error {
return nil
}

if !IsInMaintenanceWindow(c.Spec.MaintenanceWindows) {
if !isInMaintenanceWindow(c.Spec.MaintenanceWindows) {
c.logger.Infof("skipping major version upgrade, not in maintenance window")
return nil
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/cluster/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,9 @@ func (c *Cluster) syncStatefulSet() error {
// if we get here we also need to re-create the pods (either leftovers from the old
// statefulset or those that got their configuration from the outdated statefulset)
if len(podsToRecreate) > 0 {
if isSafeToRecreatePods {
if !isInMaintenanceWindow(c.Spec.MaintenanceWindows) {
c.logger.Infof("skipping pod recreation, not in maintenance window")
} else if isSafeToRecreatePods {
c.logger.Info("performing rolling update")
c.eventRecorder.Event(c.GetReference(), v1.EventTypeNormal, "Update", "Performing rolling update")
if err := c.recreatePods(podsToRecreate, switchoverCandidates); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ func parseResourceRequirements(resourcesRequirement v1.ResourceRequirements) (ac
return resources, nil
}

func IsInMaintenanceWindow(specMaintenanceWindows []acidv1.MaintenanceWindow) bool {
func isInMaintenanceWindow(specMaintenanceWindows []acidv1.MaintenanceWindow) bool {
if len(specMaintenanceWindows) == 0 {
return true
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/cluster/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ func Test_trimCronjobName(t *testing.T) {
}
}

func TestIsInMaintenanceWindow(t *testing.T) {
func TestisInMaintenanceWindow(t *testing.T) {
now := time.Now()
futureTimeStart := now.Add(1 * time.Hour)
futureTimeStartFormatted := futureTimeStart.Format("15:04")
Expand Down Expand Up @@ -705,8 +705,8 @@ func TestIsInMaintenanceWindow(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cluster.Spec.MaintenanceWindows = tt.windows
if IsInMaintenanceWindow(cluster.Spec.MaintenanceWindows) != tt.expected {
t.Errorf("Expected IsInMaintenanceWindow to return %t", tt.expected)
if isInMaintenanceWindow(cluster.Spec.MaintenanceWindows) != tt.expected {
t.Errorf("Expected isInMaintenanceWindow to return %t", tt.expected)
}
})
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/controller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ func (c *Controller) attemptToMoveMasterPodsOffNode(node *v1.Node) error {
for pod, cl := range masterPods {
podName := util.NameFromMeta(pod.ObjectMeta)

if !cluster.IsInMaintenanceWindow(cl.Spec.MaintenanceWindows) {
c.logger.Infof("skipping master pod migration, not in maintenance window")
continue
}

if err := cl.MigrateMasterPod(podName); err != nil {
c.logger.Errorf("could not move master pod %q: %v", podName, err)
} else {
Expand Down

0 comments on commit 3baa072

Please sign in to comment.