diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 4b6c3492e7f8..a93f15ed5ddc 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -74,7 +74,7 @@ func main() { // Set up controller runtime controller cloudProvider := registry.NewCloudProvider(ctx, cloudprovider.Options{ClientSet: clientSet}) - manager := controllers.NewManagerOrDie(config, controllerruntime.Options{ + manager := controllers.NewManagerOrDie(ctx, config, controllerruntime.Options{ Logger: zapr.NewLogger(logging.FromContext(ctx).Desugar()), LeaderElection: true, LeaderElectionID: "karpenter-leader-election", diff --git a/pkg/controllers/manager.go b/pkg/controllers/manager.go index 9b2bf36cd4ce..ffa0d1ad2a77 100644 --- a/pkg/controllers/manager.go +++ b/pkg/controllers/manager.go @@ -31,12 +31,12 @@ type GenericControllerManager struct { } // NewManagerOrDie instantiates a controller manager or panics -func NewManagerOrDie(config *rest.Config, options controllerruntime.Options) Manager { +func NewManagerOrDie(ctx context.Context, config *rest.Config, options controllerruntime.Options) Manager { newManager, err := controllerruntime.NewManager(config, options) if err != nil { panic(fmt.Sprintf("Failed to create controller newManager, %s", err.Error())) } - if err := newManager.GetFieldIndexer().IndexField(context.Background(), &v1.Pod{}, "spec.nodeName", podSchedulingIndex); err != nil { + if err := newManager.GetFieldIndexer().IndexField(ctx, &v1.Pod{}, "spec.nodeName", podSchedulingIndex); err != nil { panic(fmt.Sprintf("Failed to setup pod indexer, %s", err.Error())) } return &GenericControllerManager{Manager: newManager} diff --git a/pkg/test/expectations/expectations.go b/pkg/test/expectations/expectations.go index 6023526be53d..975df8b870ae 100644 --- a/pkg/test/expectations/expectations.go +++ b/pkg/test/expectations/expectations.go @@ -43,20 +43,20 @@ const ( func ExpectPodExists(ctx context.Context, c client.Client, name string, namespace string) *v1.Pod { pod := &v1.Pod{} - Expect(c.Get(context.Background(), client.ObjectKey{Name: name, Namespace: namespace}, pod)).To(Succeed()) + Expect(c.Get(ctx, client.ObjectKey{Name: name, Namespace: namespace}, pod)).To(Succeed()) return pod } func ExpectNodeExists(ctx context.Context, c client.Client, name string) *v1.Node { node := &v1.Node{} - Expect(c.Get(context.Background(), client.ObjectKey{Name: name}, node)).To(Succeed()) + Expect(c.Get(ctx, client.ObjectKey{Name: name}, node)).To(Succeed()) return node } func ExpectNotFound(ctx context.Context, c client.Client, objects ...client.Object) { for _, object := range objects { Eventually(func() bool { - return errors.IsNotFound(c.Get(context.Background(), types.NamespacedName{Name: object.GetName(), Namespace: object.GetNamespace()}, object)) + return errors.IsNotFound(c.Get(ctx, types.NamespacedName{Name: object.GetName(), Namespace: object.GetNamespace()}, object)) }, ReconcilerPropagationTime, RequestInterval).Should(BeTrue(), func() string { return fmt.Sprintf("expected %s to be deleted, but it still exists", object.GetSelfLink()) }) @@ -77,22 +77,22 @@ func ExpectNotScheduled(ctx context.Context, c client.Client, pod *v1.Pod) { func ExpectApplied(ctx context.Context, c client.Client, objects ...client.Object) { for _, object := range objects { if object.GetResourceVersion() == "" { - Expect(c.Create(context.Background(), object)).To(Succeed()) + Expect(c.Create(ctx, object)).To(Succeed()) } else { - Expect(c.Update(context.Background(), object)).To(Succeed()) + Expect(c.Update(ctx, object)).To(Succeed()) } } } func ExpectStatusUpdated(ctx context.Context, c client.Client, objects ...client.Object) { for _, object := range objects { - Expect(c.Status().Update(context.Background(), object)).To(Succeed()) + Expect(c.Status().Update(ctx, object)).To(Succeed()) } } func ExpectCreated(ctx context.Context, c client.Client, objects ...client.Object) { for _, object := range objects { - Expect(c.Create(context.Background(), object)).To(Succeed()) + Expect(c.Create(ctx, object)).To(Succeed()) } } @@ -101,7 +101,7 @@ func ExpectCreatedWithStatus(ctx context.Context, c client.Client, objects ...cl // Preserve a copy of the status, which is overriden by create status := object.DeepCopyObject().(client.Object) ExpectApplied(ctx, c, object) - Expect(c.Status().Update(context.Background(), status)).To(Succeed()) + Expect(c.Status().Update(ctx, status)).To(Succeed()) } }