From e298f7c513b6bf0d753174feed4b3c49e80ceb2c Mon Sep 17 00:00:00 2001 From: Jonathan Innis Date: Thu, 12 Sep 2024 11:13:12 -0700 Subject: [PATCH] fix: Fix unintentionally importing envtest when running NewTestingQueue (#1660) --- .../disruption/orchestration/queue.go | 18 ------------- .../disruption/orchestration/suite_test.go | 25 ++++++++++++++++--- pkg/controllers/disruption/suite_test.go | 24 +++++++++++++++--- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/pkg/controllers/disruption/orchestration/queue.go b/pkg/controllers/disruption/orchestration/queue.go index b6b71338c4..7da499e0d8 100644 --- a/pkg/controllers/disruption/orchestration/queue.go +++ b/pkg/controllers/disruption/orchestration/queue.go @@ -45,7 +45,6 @@ import ( "sigs.k8s.io/karpenter/pkg/events" "sigs.k8s.io/karpenter/pkg/metrics" "sigs.k8s.io/karpenter/pkg/operator/injection" - "sigs.k8s.io/karpenter/pkg/test" ) const ( @@ -141,23 +140,6 @@ func NewQueue(kubeClient client.Client, recorder events.Recorder, cluster *state return queue } -func NewTestingQueue(kubeClient client.Client, recorder events.Recorder, cluster *state.Cluster, clock clock.Clock, - provisioner *provisioning.Provisioner) *Queue { - - queue := &Queue{ - // nolint:staticcheck - // We need to implement a deprecated interface since Command currently doesn't implement "comparable" - RateLimitingInterface: test.NewRateLimitingInterface(workqueue.QueueConfig{Name: "disruption.workqueue"}), - providerIDToCommand: map[string]*Command{}, - kubeClient: kubeClient, - recorder: recorder, - cluster: cluster, - clock: clock, - provisioner: provisioner, - } - return queue -} - // NewCommand creates a command key and adds in initial data for the orchestration queue. func NewCommand(replacements []string, candidates []*state.StateNode, id types.UID, reason v1.DisruptionReason, consolidationType string) *Command { return &Command{ diff --git a/pkg/controllers/disruption/orchestration/suite_test.go b/pkg/controllers/disruption/orchestration/suite_test.go index d2b6fa22ce..2b4538ffe0 100644 --- a/pkg/controllers/disruption/orchestration/suite_test.go +++ b/pkg/controllers/disruption/orchestration/suite_test.go @@ -21,9 +21,15 @@ import ( "testing" "time" + "github.com/samber/lo" + "k8s.io/client-go/util/workqueue" + + "sigs.k8s.io/karpenter/pkg/events" + + "sigs.k8s.io/karpenter/pkg/test/v1alpha1" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - "github.com/samber/lo" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -41,8 +47,9 @@ import ( "sigs.k8s.io/karpenter/pkg/operator/options" "sigs.k8s.io/karpenter/pkg/test" . "sigs.k8s.io/karpenter/pkg/test/expectations" - "sigs.k8s.io/karpenter/pkg/test/v1alpha1" . "sigs.k8s.io/karpenter/pkg/utils/testing" + + clockiface "k8s.io/utils/clock" ) var ctx context.Context @@ -79,7 +86,7 @@ var _ = BeforeSuite(func() { nodeClaimStateController = informer.NewNodeClaimController(env.Client, cluster) recorder = test.NewEventRecorder() prov = provisioning.NewProvisioner(env.Client, recorder, cloudProvider, cluster) - queue = orchestration.NewTestingQueue(env.Client, recorder, cluster, fakeClock, prov) + queue = NewTestingQueue(env.Client, recorder, cluster, fakeClock, prov) }) var _ = AfterSuite(func() { @@ -87,7 +94,7 @@ var _ = AfterSuite(func() { }) var _ = BeforeEach(func() { - *queue = lo.FromPtr(orchestration.NewTestingQueue(env.Client, recorder, cluster, fakeClock, prov)) + *queue = lo.FromPtr(NewTestingQueue(env.Client, recorder, cluster, fakeClock, prov)) recorder.Reset() // Reset the events that we captured during the run cluster.Reset() cloudProvider.Reset() @@ -341,3 +348,13 @@ var _ = Describe("Queue", func() { }) }) + +func NewTestingQueue(kubeClient client.Client, recorder events.Recorder, cluster *state.Cluster, clock clockiface.Clock, + provisioner *provisioning.Provisioner) *orchestration.Queue { + + q := orchestration.NewQueue(kubeClient, recorder, cluster, clock, provisioner) + // nolint:staticcheck + // We need to implement a deprecated interface since Command currently doesn't implement "comparable" + q.RateLimitingInterface = test.NewRateLimitingInterface(workqueue.QueueConfig{Name: "disruption.workqueue"}) + return q +} diff --git a/pkg/controllers/disruption/suite_test.go b/pkg/controllers/disruption/suite_test.go index 692110f560..1288a21ed2 100644 --- a/pkg/controllers/disruption/suite_test.go +++ b/pkg/controllers/disruption/suite_test.go @@ -24,6 +24,14 @@ import ( "testing" "time" + "k8s.io/client-go/util/workqueue" + clockiface "k8s.io/utils/clock" + + "sigs.k8s.io/karpenter/pkg/events" + "sigs.k8s.io/karpenter/pkg/metrics" + + "sigs.k8s.io/karpenter/pkg/test/v1alpha1" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/samber/lo" @@ -44,12 +52,10 @@ import ( "sigs.k8s.io/karpenter/pkg/controllers/provisioning" "sigs.k8s.io/karpenter/pkg/controllers/state" "sigs.k8s.io/karpenter/pkg/controllers/state/informer" - "sigs.k8s.io/karpenter/pkg/metrics" "sigs.k8s.io/karpenter/pkg/operator/options" "sigs.k8s.io/karpenter/pkg/scheduling" "sigs.k8s.io/karpenter/pkg/test" . "sigs.k8s.io/karpenter/pkg/test/expectations" - "sigs.k8s.io/karpenter/pkg/test/v1alpha1" disruptionutils "sigs.k8s.io/karpenter/pkg/utils/disruption" "sigs.k8s.io/karpenter/pkg/utils/pdb" . "sigs.k8s.io/karpenter/pkg/utils/testing" @@ -91,7 +97,7 @@ var _ = BeforeSuite(func() { nodeClaimStateController = informer.NewNodeClaimController(env.Client, cluster) recorder = test.NewEventRecorder() prov = provisioning.NewProvisioner(env.Client, recorder, cloudProvider, cluster) - queue = orchestration.NewTestingQueue(env.Client, recorder, cluster, fakeClock, prov) + queue = NewTestingQueue(env.Client, recorder, cluster, fakeClock, prov) disruptionController = disruption.NewController(fakeClock, env.Client, prov, cloudProvider, recorder, cluster, queue) }) @@ -111,7 +117,7 @@ var _ = BeforeEach(func() { } fakeClock.SetTime(time.Now()) cluster.Reset() - *queue = lo.FromPtr(orchestration.NewTestingQueue(env.Client, recorder, cluster, fakeClock, prov)) + *queue = lo.FromPtr(NewTestingQueue(env.Client, recorder, cluster, fakeClock, prov)) cluster.MarkUnconsolidated() // Reset Feature Flags to test defaults @@ -2114,3 +2120,13 @@ func ExpectMakeNewNodeClaimsReady(ctx context.Context, c client.Client, wg *sync } }() } + +func NewTestingQueue(kubeClient client.Client, recorder events.Recorder, cluster *state.Cluster, clock clockiface.Clock, + provisioner *provisioning.Provisioner) *orchestration.Queue { + + q := orchestration.NewQueue(kubeClient, recorder, cluster, clock, provisioner) + // nolint:staticcheck + // We need to implement a deprecated interface since Command currently doesn't implement "comparable" + q.RateLimitingInterface = test.NewRateLimitingInterface(workqueue.QueueConfig{Name: "disruption.workqueue"}) + return q +}