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

Updated expectations to wire through contexts #902

Merged
merged 1 commit into from
Dec 2, 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
108 changes: 54 additions & 54 deletions pkg/controllers/node/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ var _ = Describe("Controller", func() {
v1alpha5.ProvisionerNameLabelKey: provisioner.Name,
},
})
ExpectCreated(env.Client, provisioner, n)
ExpectCreated(ctx, env.Client, provisioner, n)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.DeletionTimestamp.IsZero()).To(BeTrue())
})
It("should ignore nodes without a provisioner", func() {
n := test.Node(test.NodeOptions{Finalizers: []string{v1alpha5.TerminationFinalizer}})
ExpectCreated(env.Client, provisioner, n)
ExpectCreated(ctx, env.Client, provisioner, n)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.DeletionTimestamp.IsZero()).To(BeTrue())
})
It("should delete nodes after expiry", func() {
Expand All @@ -101,19 +101,19 @@ var _ = Describe("Controller", func() {
v1alpha5.ProvisionerNameLabelKey: provisioner.Name,
},
})
ExpectCreated(env.Client, provisioner, n)
ExpectCreated(ctx, env.Client, provisioner, n)

// Should still exist
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))
n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.DeletionTimestamp.IsZero()).To(BeTrue())

// Simulate time passing
injectabletime.Now = func() time.Time {
return time.Now().Add(time.Duration(*provisioner.Spec.TTLSecondsUntilExpired) * time.Second)
}
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))
n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.DeletionTimestamp.IsZero()).To(BeFalse())
})
})
Expand All @@ -128,11 +128,11 @@ var _ = Describe("Controller", func() {
{Key: randomdata.SillyName(), Effect: v1.TaintEffectNoSchedule},
},
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, n)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, n)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.Spec.Taints).To(Equal(n.Spec.Taints))
})
It("should remove the readiness taint if ready", func() {
Expand All @@ -144,11 +144,11 @@ var _ = Describe("Controller", func() {
{Key: randomdata.SillyName(), Effect: v1.TaintEffectNoSchedule},
},
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, n)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, n)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.Spec.Taints).ToNot(Equal([]v1.Taint{n.Spec.Taints[1]}))
})
It("should do nothing if ready and the readiness taint does not exist", func() {
Expand All @@ -157,11 +157,11 @@ var _ = Describe("Controller", func() {
Labels: map[string]string{v1alpha5.ProvisionerNameLabelKey: provisioner.Name},
Taints: []v1.Taint{{Key: randomdata.SillyName(), Effect: v1.TaintEffectNoSchedule}},
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, n)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, n)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.Spec.Taints).To(Equal(n.Spec.Taints))
})
It("should do nothing if not owned by a provisioner", func() {
Expand All @@ -172,11 +172,11 @@ var _ = Describe("Controller", func() {
{Key: randomdata.SillyName(), Effect: v1.TaintEffectNoSchedule},
},
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, n)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, n)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.Spec.Taints).To(Equal(n.Spec.Taints))
})
})
Expand All @@ -188,20 +188,20 @@ var _ = Describe("Controller", func() {
ReadyStatus: v1.ConditionUnknown,
ReadyReason: "NodeStatusNeverUpdated",
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, n)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, n)

ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(provisioner))

// Expect node not be deleted
n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.DeletionTimestamp.IsZero()).To(BeTrue())

// Simulate time passing and a n failing to join
injectabletime.Now = func() time.Time { return time.Now().Add(node.LivenessTimeout) }
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.DeletionTimestamp.IsZero()).To(BeFalse())
})
It("should delete nodes if we never hear anything after 5 minutes", func() {
Expand All @@ -211,19 +211,19 @@ var _ = Describe("Controller", func() {
ReadyStatus: v1.ConditionUnknown,
ReadyReason: "",
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, n)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, n)

ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(provisioner))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.DeletionTimestamp.IsZero()).To(BeTrue())

// Simulate time passing and a n failing to join
injectabletime.Now = func() time.Time { return time.Now().Add(node.LivenessTimeout) }
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.DeletionTimestamp.IsZero()).To(BeFalse())
})
})
Expand All @@ -235,11 +235,11 @@ var _ = Describe("Controller", func() {
ReadyStatus: v1.ConditionUnknown,
})

ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, node)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, node)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node))

node = ExpectNodeExists(env.Client, node.Name)
node = ExpectNodeExists(ctx, env.Client, node.Name)
Expect(node.Annotations).ToNot(HaveKey(v1alpha5.EmptinessTimestampAnnotationKey))
})
It("should not TTL nodes that have ready status false", func() {
Expand All @@ -249,23 +249,23 @@ var _ = Describe("Controller", func() {
ReadyStatus: v1.ConditionFalse,
})

ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, node)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, node)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node))

node = ExpectNodeExists(env.Client, node.Name)
node = ExpectNodeExists(ctx, env.Client, node.Name)
Expect(node.Annotations).ToNot(HaveKey(v1alpha5.EmptinessTimestampAnnotationKey))
})
It("should label nodes as underutilized and add TTL", func() {
provisioner.Spec.TTLSecondsAfterEmpty = ptr.Int64(30)
node := test.Node(test.NodeOptions{
Labels: map[string]string{v1alpha5.ProvisionerNameLabelKey: provisioner.Name},
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, node)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, node)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node))

node = ExpectNodeExists(env.Client, node.Name)
node = ExpectNodeExists(ctx, env.Client, node.Name)
Expect(node.Annotations).To(HaveKey(v1alpha5.EmptinessTimestampAnnotationKey))
})
It("should remove labels from non-empty nodes", func() {
Expand All @@ -276,17 +276,17 @@ var _ = Describe("Controller", func() {
v1alpha5.EmptinessTimestampAnnotationKey: time.Now().Add(100 * time.Second).Format(time.RFC3339),
},
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, node)
ExpectCreatedWithStatus(env.Client, test.Pod(test.PodOptions{
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, node)
ExpectCreatedWithStatus(ctx, env.Client, test.Pod(test.PodOptions{
Name: strings.ToLower(randomdata.SillyName()),
Namespace: provisioner.Namespace,
NodeName: node.Name,
Conditions: []v1.PodCondition{{Type: v1.PodReady, Status: v1.ConditionTrue}},
}))
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node))

node = ExpectNodeExists(env.Client, node.Name)
node = ExpectNodeExists(ctx, env.Client, node.Name)
Expect(node.Annotations).ToNot(HaveKey(v1alpha5.EmptinessTimestampAnnotationKey))
})
It("should delete empty nodes past their TTL", func() {
Expand All @@ -298,10 +298,10 @@ var _ = Describe("Controller", func() {
v1alpha5.EmptinessTimestampAnnotationKey: time.Now().Add(-100 * time.Second).Format(time.RFC3339),
},
})
ExpectCreated(env.Client, provisioner, node)
ExpectCreated(ctx, env.Client, provisioner, node)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node))

node = ExpectNodeExists(env.Client, node.Name)
node = ExpectNodeExists(ctx, env.Client, node.Name)
Expect(node.DeletionTimestamp.IsZero()).To(BeFalse())
})
})
Expand All @@ -311,47 +311,47 @@ var _ = Describe("Controller", func() {
Labels: map[string]string{v1alpha5.ProvisionerNameLabelKey: provisioner.Name},
Finalizers: []string{"fake.com/finalizer"},
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, n)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, n)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.Finalizers).To(ConsistOf(n.Finalizers[0], v1alpha5.TerminationFinalizer))
})
It("should do nothing if terminating", func() {
n := test.Node(test.NodeOptions{
Labels: map[string]string{v1alpha5.ProvisionerNameLabelKey: provisioner.Name},
Finalizers: []string{"fake.com/finalizer"},
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, n)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, n)
Expect(env.Client.Delete(ctx, n)).To(Succeed())
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.Finalizers).To(Equal(n.Finalizers))
})
It("should do nothing if the termination finalizer already exists", func() {
n := test.Node(test.NodeOptions{
Labels: map[string]string{v1alpha5.ProvisionerNameLabelKey: provisioner.Name},
Finalizers: []string{v1alpha5.TerminationFinalizer, "fake.com/finalizer"},
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, n)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, n)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.Finalizers).To(Equal(n.Finalizers))
})
It("should do nothing if the not owned by a provisioner", func() {
n := test.Node(test.NodeOptions{
Finalizers: []string{"fake.com/finalizer"},
})
ExpectCreated(env.Client, provisioner)
ExpectCreatedWithStatus(env.Client, n)
ExpectCreated(ctx, env.Client, provisioner)
ExpectCreatedWithStatus(ctx, env.Client, n)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(n))

n = ExpectNodeExists(env.Client, n.Name)
n = ExpectNodeExists(ctx, env.Client, n.Name)
Expect(n.Finalizers).To(Equal(n.Finalizers))
})
})
Expand Down
12 changes: 6 additions & 6 deletions pkg/controllers/provisioning/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ var _ = Describe("Provisioning", func() {
})
Context("Daemonsets and Node Overhead", func() {
It("should account for overhead", func() {
ExpectCreated(env.Client, test.DaemonSet(
ExpectCreated(ctx, env.Client, test.DaemonSet(
test.DaemonSetOptions{PodOptions: test.PodOptions{
ResourceRequirements: v1.ResourceRequirements{Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("1"), v1.ResourceMemory: resource.MustParse("1Gi")}},
}},
Expand All @@ -170,7 +170,7 @@ var _ = Describe("Provisioning", func() {
Expect(*node.Status.Allocatable.Memory()).To(Equal(resource.MustParse("4Gi")))
})
It("should not schedule if overhead is too large", func() {
ExpectCreated(env.Client, test.DaemonSet(
ExpectCreated(ctx, env.Client, test.DaemonSet(
test.DaemonSetOptions{PodOptions: test.PodOptions{
ResourceRequirements: v1.ResourceRequirements{Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("10000"), v1.ResourceMemory: resource.MustParse("10000Gi")}},
}},
Expand All @@ -180,7 +180,7 @@ var _ = Describe("Provisioning", func() {
})
It("should ignore daemonsets without matching tolerations", func() {
provisioner.Spec.Taints = v1alpha5.Taints{{Key: "foo", Value: "bar", Effect: v1.TaintEffectNoSchedule}}
ExpectCreated(env.Client, test.DaemonSet(
ExpectCreated(ctx, env.Client, test.DaemonSet(
test.DaemonSetOptions{PodOptions: test.PodOptions{
ResourceRequirements: v1.ResourceRequirements{Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("1"), v1.ResourceMemory: resource.MustParse("1Gi")}},
}},
Expand All @@ -196,7 +196,7 @@ var _ = Describe("Provisioning", func() {
Expect(*node.Status.Allocatable.Memory()).To(Equal(resource.MustParse("2Gi")))
})
It("should ignore daemonsets with an invalid selector", func() {
ExpectCreated(env.Client, test.DaemonSet(
ExpectCreated(ctx, env.Client, test.DaemonSet(
test.DaemonSetOptions{PodOptions: test.PodOptions{
NodeSelector: map[string]string{"node": "invalid"},
ResourceRequirements: v1.ResourceRequirements{Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("1"), v1.ResourceMemory: resource.MustParse("1Gi")}},
Expand All @@ -212,7 +212,7 @@ var _ = Describe("Provisioning", func() {
Expect(*node.Status.Allocatable.Memory()).To(Equal(resource.MustParse("2Gi")))
})
It("should ignore daemonsets that don't match pod constraints", func() {
ExpectCreated(env.Client, test.DaemonSet(
ExpectCreated(ctx, env.Client, test.DaemonSet(
test.DaemonSetOptions{PodOptions: test.PodOptions{
NodeRequirements: []v1.NodeSelectorRequirement{{Key: v1.LabelTopologyZone, Operator: v1.NodeSelectorOpIn, Values: []string{"test-zone-1"}}},
ResourceRequirements: v1.ResourceRequirements{Requests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("1"), v1.ResourceMemory: resource.MustParse("1Gi")}},
Expand Down Expand Up @@ -244,7 +244,7 @@ var _ = Describe("Provisioning", func() {
})
Context("Taints", func() {
It("should apply unready taints", func() {
ExpectCreated(env.Client, provisioner)
ExpectCreated(ctx, env.Client, provisioner)
for _, pod := range ExpectProvisioned(ctx, env.Client, scheduler, provisioners, provisioner, test.UnschedulablePod()) {
node := ExpectScheduled(ctx, env.Client, pod)
Expect(node.Spec.Taints).To(ContainElement(v1.Taint{Key: v1alpha5.NotReadyTaintKey, Effect: v1.TaintEffectNoSchedule}))
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/scheduling/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ var _ = Describe("Topology", func() {
firstNode := test.Node(test.NodeOptions{Labels: map[string]string{v1.LabelTopologyZone: "test-zone-1"}})
secondNode := test.Node(test.NodeOptions{Labels: map[string]string{v1.LabelTopologyZone: "test-zone-2"}})
thirdNode := test.Node(test.NodeOptions{}) // missing topology domain
ExpectCreated(env.Client, provisioner, firstNode, secondNode, thirdNode)
ExpectCreated(ctx, env.Client, provisioner, firstNode, secondNode, thirdNode)
topology := []v1.TopologySpreadConstraint{{
TopologyKey: v1.LabelTopologyZone,
WhenUnsatisfiable: v1.DoNotSchedule,
Expand Down
Loading