Skip to content

Commit

Permalink
test: remove legacy helpers and comments (#5082)
Browse files Browse the repository at this point in the history
  • Loading branch information
njtran authored Nov 13, 2023
1 parent c70e103 commit c54ce76
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 46 deletions.
37 changes: 7 additions & 30 deletions test/pkg/environment/common/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,49 +482,26 @@ func (env *Environment) ConsistentlyExpectMachineCount(comparator string, count
return lo.ToSlicePtr(machineList.Items)
}

func (env *Environment) EventuallyExpectCordonedNodeCountLegacy(comparator string, count int) []*v1.Node {
func (env *Environment) EventuallyExpectTaintedNodeCount(comparator string, count int) []*v1.Node {
GinkgoHelper()
By(fmt.Sprintf("waiting for cordoned nodes to be %s to %d", comparator, count))
nodeList := &v1.NodeList{}
Eventually(func(g Gomega) {
g.Expect(env.Client.List(env, nodeList, client.MatchingFields{"spec.unschedulable": "true"})).To(Succeed())
g.Expect(len(nodeList.Items)).To(BeNumerically(comparator, count),
fmt.Sprintf("expected %d cordoned nodes, had %d (%v)", count, len(nodeList.Items), NodeNames(lo.ToSlicePtr(nodeList.Items))))
}).Should(Succeed())
return lo.ToSlicePtr(nodeList.Items)
}

func (env *Environment) EventuallyExpectNodesUncordonedLegacyWithTimeout(timeout time.Duration, nodes ...*v1.Node) {
GinkgoHelper()
By(fmt.Sprintf("waiting for %d nodes to be uncordoned", len(nodes)))
nodeList := &v1.NodeList{}
Eventually(func(g Gomega) {
g.Expect(env.Client.List(env, nodeList, client.MatchingFields{"spec.unschedulable": "true"})).To(Succeed())
cordonedNodeNames := lo.Map(nodeList.Items, func(n v1.Node, _ int) string { return n.Name })
g.Expect(cordonedNodeNames).ToNot(ContainElements(lo.Map(nodes, func(n *v1.Node, _ int) interface{} { return n.Name })...))
}).WithTimeout(timeout).Should(Succeed())
}

func (env *Environment) EventuallyExpectCordonedNodeCount(comparator string, count int) []*v1.Node {
GinkgoHelper()
By(fmt.Sprintf("waiting for cordoned nodes to be %s to %d", comparator, count))
By(fmt.Sprintf("waiting for tainted nodes to be %s to %d", comparator, count))
nodeList := &v1.NodeList{}
Eventually(func(g Gomega) {
g.Expect(env.Client.List(env, nodeList, client.MatchingFields{"spec.taints[*].karpenter.sh/disruption": "disrupting"})).To(Succeed())
g.Expect(len(nodeList.Items)).To(BeNumerically(comparator, count),
fmt.Sprintf("expected %d cordoned nodes, had %d (%v)", count, len(nodeList.Items), NodeNames(lo.ToSlicePtr(nodeList.Items))))
fmt.Sprintf("expected %d tainted nodes, had %d (%v)", count, len(nodeList.Items), NodeNames(lo.ToSlicePtr(nodeList.Items))))
}).Should(Succeed())
return lo.ToSlicePtr(nodeList.Items)
}

func (env *Environment) EventuallyExpectNodesUncordonedWithTimeout(timeout time.Duration, nodes ...*v1.Node) {
func (env *Environment) EventuallyExpectNodesUntaintedWithTimeout(timeout time.Duration, nodes ...*v1.Node) {
GinkgoHelper()
By(fmt.Sprintf("waiting for %d nodes to be uncordoned", len(nodes)))
By(fmt.Sprintf("waiting for %d nodes to be untainted", len(nodes)))
nodeList := &v1.NodeList{}
Eventually(func(g Gomega) {
g.Expect(env.Client.List(env, nodeList, client.MatchingFields{"spec.taints[*].karpenter.sh/disruption": "disrupting"})).To(Succeed())
cordonedNodeNames := lo.Map(nodeList.Items, func(n v1.Node, _ int) string { return n.Name })
g.Expect(cordonedNodeNames).ToNot(ContainElements(lo.Map(nodes, func(n *v1.Node, _ int) interface{} { return n.Name })...))
taintedNodeNames := lo.Map(nodeList.Items, func(n v1.Node, _ int) string { return n.Name })
g.Expect(taintedNodeNames).ToNot(ContainElements(lo.Map(nodes, func(n *v1.Node, _ int) interface{} { return n.Name })...))
}).WithTimeout(timeout).Should(Succeed())
}

Expand Down
16 changes: 8 additions & 8 deletions test/suites/drift/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,12 @@ var _ = Describe("Beta/Drift", Label("AWS"), func() {
}
}).Should(Succeed())

// Expect nodes To get cordoned
cordonedNodes := env.EventuallyExpectCordonedNodeCount("==", 1)
// Expect nodes To get tainted
taintedNodes := env.EventuallyExpectTaintedNodeCount("==", 1)

// Drift should fail and the original node should be uncordoned
// Drift should fail and the original node should be untainted
// TODO: reduce timeouts when disruption waits are factored out
env.EventuallyExpectNodesUncordonedWithTimeout(11*time.Minute, cordonedNodes...)
env.EventuallyExpectNodesUntaintedWithTimeout(11*time.Minute, taintedNodes...)

// We give another 6 minutes here to handle the deletion at the 15m registration timeout
Eventually(func(g Gomega) {
Expand Down Expand Up @@ -487,12 +487,12 @@ var _ = Describe("Beta/Drift", Label("AWS"), func() {
}
}).Should(Succeed())

// Expect nodes To be cordoned
cordonedNodes := env.EventuallyExpectCordonedNodeCount("==", 1)
// Expect nodes to be tainted
taintedNodes := env.EventuallyExpectTaintedNodeCount("==", 1)

// Drift should fail and original node should be uncordoned
// Drift should fail and original node should be untainted
// TODO: reduce timeouts when disruption waits are factored out
env.EventuallyExpectNodesUncordonedWithTimeout(11*time.Minute, cordonedNodes...)
env.EventuallyExpectNodesUntaintedWithTimeout(11*time.Minute, taintedNodes...)

// Expect that the new nodeClaim/node is kept around after the un-cordon
nodeList := &v1.NodeList{}
Expand Down
16 changes: 8 additions & 8 deletions test/suites/expiration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,12 @@ var _ = Describe("Expiration", func() {
}
}).Should(Succeed())

// Expect nodes To get cordoned
cordonedNodes := env.EventuallyExpectCordonedNodeCount("==", 1)
// Expect nodes To get tainted
taintedNodes := env.EventuallyExpectTaintedNodeCount("==", 1)

// Expire should fail and the original node should be uncordoned
// Expire should fail and the original node should be untainted
// TODO: reduce timeouts when deprovisioning waits are factored out
env.EventuallyExpectNodesUncordonedWithTimeout(11*time.Minute, cordonedNodes...)
env.EventuallyExpectNodesUntaintedWithTimeout(11*time.Minute, taintedNodes...)

// The nodeclaims that never registers will be removed
Eventually(func(g Gomega) {
Expand Down Expand Up @@ -294,12 +294,12 @@ var _ = Describe("Expiration", func() {
}
}).Should(Succeed())

// Expect nodes To be cordoned
cordonedNodes := env.EventuallyExpectCordonedNodeCount("==", 1)
// Expect nodes To be tainted
taintedNodes := env.EventuallyExpectTaintedNodeCount("==", 1)

// Expire should fail and original node should be uncordoned and no NodeClaims should be removed
// Expire should fail and original node should be untainted and no NodeClaims should be removed
// TODO: reduce timeouts when deprovisioning waits are factored out
env.EventuallyExpectNodesUncordonedWithTimeout(11*time.Minute, cordonedNodes...)
env.EventuallyExpectNodesUntaintedWithTimeout(11*time.Minute, taintedNodes...)

// Expect that the new NodeClaim/Node is kept around after the un-cordon
nodeList := &v1.NodeList{}
Expand Down

0 comments on commit c54ce76

Please sign in to comment.