Skip to content

Commit

Permalink
tests: fix expiration test
Browse files Browse the repository at this point in the history
  • Loading branch information
jigisha620 committed Jul 19, 2024
1 parent c87c2ee commit e3ad0b5
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions test/suites/expiration/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ var _ = Describe("Expiration", func() {
var numPods int
BeforeEach(func() {
numPods = 1
// Add pods with a do-not-disrupt annotation so that we can check node metadata before we disrupt
dep = coretest.Deployment(coretest.DeploymentOptions{
Replicas: int32(numPods),
PodOptions: coretest.PodOptions{
Expand All @@ -82,17 +81,14 @@ var _ = Describe("Expiration", func() {
selector = labels.SelectorFromSet(dep.Spec.Selector.MatchLabels)
})
It("should expire the node after the expiration is reached", func() {
nodePool.Spec.Template.Spec.ExpireAfter = karpv1.NillableDuration{Duration: lo.ToPtr(time.Minute * 2)}
env.ExpectCreated(nodeClass, nodePool, dep)

nodeClaim := env.EventuallyExpectCreatedNodeClaimCount("==", 1)[0]
node := env.EventuallyExpectCreatedNodeCount("==", 1)[0]
env.EventuallyExpectHealthyPodCount(selector, numPods)
env.Monitor.Reset() // Reset the monitor so that we can expect a single node to be spun up after expiration

// Set the expireAfter value to get the node deleted
nodePool.Spec.Template.Spec.ExpireAfter = karpv1.NillableDuration{Duration: lo.ToPtr(time.Second * 15)}
env.ExpectUpdated(nodePool)

// Eventually the node will be tainted, which means its actively being disrupted
Eventually(func(g Gomega) {
g.Expect(env.Client.Get(env.Context, client.ObjectKeyFromObject(node), node)).Should(Succeed())
Expand All @@ -102,10 +98,9 @@ var _ = Describe("Expiration", func() {
g.Expect(ok).To(BeTrue())
}).Should(Succeed())

// Set the expireAfter to "Never" to make sure new node isn't deleted
// This is CRITICAL since it prevents nodes that are immediately spun up from immediately being expired and
// racing at the end of the E2E test, leaking node resources into subsequent tests
nodePool.Spec.Template.Spec.ExpireAfter.Duration = nil
// Set the limit to 0 to make sure we don't continue to create nodeClaims.
// This is CRITICAL since it prevents leaking node resources into subsequent tests
nodePool.Spec.Limits = nil
env.ExpectUpdated(nodePool)

// After the deletion timestamp is set and all pods are drained
Expand All @@ -117,6 +112,9 @@ var _ = Describe("Expiration", func() {
env.EventuallyExpectHealthyPodCount(selector, numPods)
})
It("should replace expired node with a single node and schedule all pods", func() {
// Set expire after to 5 minutes since we have to respect PDB and move over pods one at a time from one node to another.
// The new nodes should not expire before all the pods are moved over.
nodePool.Spec.Template.Spec.ExpireAfter = karpv1.NillableDuration{Duration: lo.ToPtr(time.Minute * 5)}
var numPods int32 = 5
// We should setup a PDB that will only allow a minimum of 1 pod to be pending at a time
minAvailable := intstr.FromInt32(numPods - 1)
Expand All @@ -135,10 +133,6 @@ var _ = Describe("Expiration", func() {
env.EventuallyExpectHealthyPodCount(selector, int(numPods))
env.Monitor.Reset() // Reset the monitor so that we can expect a single node to be spun up after expiration

// Set the expireAfter value to get the node deleted
nodePool.Spec.Template.Spec.ExpireAfter.Duration = lo.ToPtr(time.Second * 15)
env.ExpectUpdated(nodePool)

// Eventually the node will be tainted, which means its actively being disrupted
Eventually(func(g Gomega) {
g.Expect(env.Client.Get(env.Context, client.ObjectKeyFromObject(node), node)).Should(Succeed())
Expand All @@ -148,10 +142,9 @@ var _ = Describe("Expiration", func() {
g.Expect(ok).To(BeTrue())
}).Should(Succeed())

// Set the expireAfter to "Never" to make sure new node isn't deleted
// This is CRITICAL since it prevents nodes that are immediately spun up from immediately being expired and
// racing at the end of the E2E test, leaking node resources into subsequent tests
nodePool.Spec.Template.Spec.ExpireAfter.Duration = nil
// Set the limit to 0 to make sure we don't continue to create nodeClaims.
// This is CRITICAL since it prevents leaking node resources into subsequent tests
nodePool.Spec.Limits = nil
env.ExpectUpdated(nodePool)

// After the deletion timestamp is set and all pods are drained
Expand Down

0 comments on commit e3ad0b5

Please sign in to comment.