Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned up stray contexts in test expectations #910

Merged
merged 2 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
16 changes: 8 additions & 8 deletions pkg/test/expectations/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
Expand All @@ -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())
}
}

Expand All @@ -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())
}
}

Expand Down