Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
6 changes: 5 additions & 1 deletion pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1767,9 +1767,13 @@ func (c *Cluster) GetStatus() *ClusterStatus {
}

func (c *Cluster) GetSwitchoverSchedule() string {
now := time.Now().UTC()
return c.GetSwitchoverScheduleAtTime(now)
}

func (c *Cluster) GetSwitchoverScheduleAtTime(now time.Time) string {
var possibleSwitchover, schedule time.Time

now := time.Now().UTC()
for _, window := range c.Spec.MaintenanceWindows {
// in the best case it is possible today
possibleSwitchover = time.Date(now.Year(), now.Month(), now.Day(), window.StartTime.Hour(), window.StartTime.Minute(), 0, 0, time.UTC)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ func TestCompareVolumeMounts(t *testing.T) {
}

func TestGetSwitchoverSchedule(t *testing.T) {
now := time.Now()
now, _ := time.Parse(time.RFC3339, "2025-11-11T12:35:00Z")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that you can reproduce the test failures I had when running locally by passing in some other times here like

  • 2025-11-11T20:35:00-08:00
  • 2025-11-11T23:35:00Z

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jup, could reproduce. Thanks for the pointer


futureTimeStart := now.Add(1 * time.Hour)
futureWindowTimeStart := futureTimeStart.Format("15:04")
Expand Down Expand Up @@ -2195,7 +2195,7 @@ func TestGetSwitchoverSchedule(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cluster.Spec.MaintenanceWindows = tt.windows
schedule := cluster.GetSwitchoverSchedule()
schedule := cluster.GetSwitchoverScheduleAtTime(now)
if schedule != tt.expected {
t.Errorf("Expected GetSwitchoverSchedule to return %s, returned: %s", tt.expected, schedule)
}
Expand Down