From cb3b335bdb3d130bd1ac6c79e60dae1131d762c3 Mon Sep 17 00:00:00 2001 From: m00g3n Date: Wed, 20 Dec 2023 10:58:02 +0100 Subject: [PATCH] fix linter --- internal/controller/find_last_sync_time.go | 9 ++++----- internal/controller/find_last_sync_time_test.go | 2 +- internal/controller/gardener_cluster_controller.go | 4 ++-- internal/controller/next_requeue_test.go | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/controller/find_last_sync_time.go b/internal/controller/find_last_sync_time.go index cc199ea4..3f03f500 100644 --- a/internal/controller/find_last_sync_time.go +++ b/internal/controller/find_last_sync_time.go @@ -4,17 +4,16 @@ import ( "time" ) -// TODO replace order -func findLastSyncTime(annotations map[string]string) (bool, time.Time) { +func findLastSyncTime(annotations map[string]string) (time.Time, bool) { _, found := annotations[lastKubeconfigSyncAnnotation] if !found { - return false, time.Time{} + return time.Time{}, false } lastSyncTimeString := annotations[lastKubeconfigSyncAnnotation] lastSyncTime, err := time.Parse(time.RFC3339, lastSyncTimeString) if err != nil { - return false, time.Time{} + return time.Time{}, false } - return true, lastSyncTime + return lastSyncTime, true } diff --git a/internal/controller/find_last_sync_time_test.go b/internal/controller/find_last_sync_time_test.go index 7fa1d1b4..60c7af33 100644 --- a/internal/controller/find_last_sync_time_test.go +++ b/internal/controller/find_last_sync_time_test.go @@ -11,7 +11,7 @@ var _ = Describe("findLastSyncTime", func() { DescribeTable("should return expected values when", func(annotations map[string]string, expectedFound bool, expectedTime time.Time) { - found, lastSyncTime := findLastSyncTime(annotations) + lastSyncTime, found := findLastSyncTime(annotations) Expect(found).To(Equal(expectedFound)) Expect(lastSyncTime).To(Equal(expectedTime)) }, diff --git a/internal/controller/gardener_cluster_controller.go b/internal/controller/gardener_cluster_controller.go index f670a514..6bd8c859 100644 --- a/internal/controller/gardener_cluster_controller.go +++ b/internal/controller/gardener_cluster_controller.go @@ -113,7 +113,7 @@ func (controller *GardenerClusterController) Reconcile(ctx context.Context, req annotations = secret.Annotations } - _, lastSyncTime := findLastSyncTime(annotations) + lastSyncTime, _ := findLastSyncTime(annotations) now := time.Now().UTC() requeueAfter := nextRequeue(now, lastSyncTime, controller.rotationPeriod, rotationPeriodRatio) @@ -283,7 +283,7 @@ func secretRotationTimePassed(secret *corev1.Secret, rotationPeriod time.Duratio } annotations := secret.GetAnnotations() - found, lastSyncTime := findLastSyncTime(annotations) + lastSyncTime, found := findLastSyncTime(annotations) if !found { return true } diff --git a/internal/controller/next_requeue_test.go b/internal/controller/next_requeue_test.go index b8a23c49..fc496db6 100644 --- a/internal/controller/next_requeue_test.go +++ b/internal/controller/next_requeue_test.go @@ -16,7 +16,7 @@ var _ = Describe("nextRequeueAfter", func() { DescribeTable("should return expected values when", func(now, lastSyncTime time.Time, rotationPeriod time.Duration, modifier float64, expectedDuration time.Duration) { result := nextRequeue(now, lastSyncTime, rotationPeriod, modifier) - Expect(result).To(Equal(expectedDuration)) + Expect(result).To(BeNumerically("~", expectedDuration, 1)) }, Entry("receives all zero arguments", now, time.Time{}, time.Duration(0), 0.0, time.Duration(0)), Entry("receives arguments (now, zero, 1[m], 0.95)", now, time.Time{}, time.Minute, 0.95, time.Second*57),