From 446c134797ce1bfd3a86543d49ce57fef9849034 Mon Sep 17 00:00:00 2001 From: Steven Berler Date: Tue, 18 Nov 2025 16:47:26 -0800 Subject: [PATCH 1/4] fix switchover schedule tests Previously the tests would fail depending on the local time zone and the time of day the test was being run. --- pkg/cluster/cluster.go | 6 +++++- pkg/cluster/cluster_test.go | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 9cd750e84..7e9baabdb 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -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) diff --git a/pkg/cluster/cluster_test.go b/pkg/cluster/cluster_test.go index 25f61db98..288840d3f 100644 --- a/pkg/cluster/cluster_test.go +++ b/pkg/cluster/cluster_test.go @@ -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") futureTimeStart := now.Add(1 * time.Hour) futureWindowTimeStart := futureTimeStart.Format("15:04") @@ -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) } From 0b9df9dae97facb8f737f01025cdca1992bb1f50 Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Thu, 11 Dec 2025 09:31:53 +0100 Subject: [PATCH 2/4] Update pkg/cluster/cluster.go Co-authored-by: Mikkel Oscar Lyderik Larsen --- pkg/cluster/cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 7e9baabdb..e26abcd74 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -1771,7 +1771,7 @@ func (c *Cluster) GetSwitchoverSchedule() string { return c.GetSwitchoverScheduleAtTime(now) } -func (c *Cluster) GetSwitchoverScheduleAtTime(now time.Time) string { +func (c *Cluster) getSwitchoverScheduleAtTime(now time.Time) string { var possibleSwitchover, schedule time.Time for _, window := range c.Spec.MaintenanceWindows { From 8f53b667ae0eded1c82e4c8e3f7c1d99181df2d2 Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Thu, 11 Dec 2025 09:32:04 +0100 Subject: [PATCH 3/4] Update pkg/cluster/cluster.go --- pkg/cluster/cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index e26abcd74..b6a4e24a8 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -1768,7 +1768,7 @@ func (c *Cluster) GetStatus() *ClusterStatus { func (c *Cluster) GetSwitchoverSchedule() string { now := time.Now().UTC() - return c.GetSwitchoverScheduleAtTime(now) + return c.getSwitchoverScheduleAtTime(now) } func (c *Cluster) getSwitchoverScheduleAtTime(now time.Time) string { From c0c03678e8976ef0074d274af1ae25c5560f51fc Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Thu, 11 Dec 2025 09:32:14 +0100 Subject: [PATCH 4/4] Update pkg/cluster/cluster_test.go --- pkg/cluster/cluster_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cluster/cluster_test.go b/pkg/cluster/cluster_test.go index 288840d3f..d78d4c92e 100644 --- a/pkg/cluster/cluster_test.go +++ b/pkg/cluster/cluster_test.go @@ -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.GetSwitchoverScheduleAtTime(now) + schedule := cluster.getSwitchoverScheduleAtTime(now) if schedule != tt.expected { t.Errorf("Expected GetSwitchoverSchedule to return %s, returned: %s", tt.expected, schedule) }