From 81d59752dd282e57c129418acf9e836888482e96 Mon Sep 17 00:00:00 2001 From: Amanuel Engeda Date: Mon, 12 Aug 2024 09:59:07 -0700 Subject: [PATCH] Update nilableDuration --- test/pkg/environment/common/environment.go | 4 ++-- test/suites/chaos/suite_test.go | 2 +- test/suites/consolidation/suite_test.go | 10 ++++----- test/suites/expiration/suite_test.go | 24 +++++++++++----------- test/suites/integration/emptiness_test.go | 6 +++--- test/suites/integration/validation_test.go | 5 ++--- test/suites/scale/deprovisioning_test.go | 12 +++++------ 7 files changed, 31 insertions(+), 32 deletions(-) diff --git a/test/pkg/environment/common/environment.go b/test/pkg/environment/common/environment.go index ef677cbbd8a7..59767917aacf 100644 --- a/test/pkg/environment/common/environment.go +++ b/test/pkg/environment/common/environment.go @@ -182,8 +182,8 @@ func (env *Environment) DefaultNodePool(nodeClass *v1beta1.EC2NodeClass) *corev1 }, }, } - nodePool.Spec.Disruption.ConsolidateAfter = &corev1beta1.NillableDuration{} - nodePool.Spec.Disruption.ExpireAfter.Duration = nil + nodePool.Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("Never")) + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("Never") nodePool.Spec.Limits = corev1beta1.Limits(v1.ResourceList{ v1.ResourceCPU: resource.MustParse("1000"), v1.ResourceMemory: resource.MustParse("1000Gi"), diff --git a/test/suites/chaos/suite_test.go b/test/suites/chaos/suite_test.go index 9011876d9a36..5d51e0641f7c 100644 --- a/test/suites/chaos/suite_test.go +++ b/test/suites/chaos/suite_test.go @@ -113,7 +113,7 @@ var _ = Describe("Chaos", func() { defer cancel() nodePool.Spec.Disruption.ConsolidationPolicy = corev1beta1.ConsolidationPolicyWhenEmpty - nodePool.Spec.Disruption.ConsolidateAfter = &corev1beta1.NillableDuration{Duration: lo.ToPtr(30 * time.Second)} + nodePool.Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("30s")) numPods := 1 dep := coretest.Deployment(coretest.DeploymentOptions{ Replicas: int32(numPods), diff --git a/test/suites/consolidation/suite_test.go b/test/suites/consolidation/suite_test.go index 7aeb3cdaa972..e455e55b9609 100644 --- a/test/suites/consolidation/suite_test.go +++ b/test/suites/consolidation/suite_test.go @@ -151,7 +151,7 @@ var _ = Describe("Consolidation", func() { }) It("should respect budgets for non-empty delete consolidation", func() { // This test will hold consolidation until we are ready to execute it - nodePool.Spec.Disruption.ConsolidateAfter = &corev1beta1.NillableDuration{} + nodePool.Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("Never")) nodePool = test.ReplaceRequirements(nodePool, corev1beta1.NodeSelectorRequirementWithMinValues{ @@ -220,7 +220,7 @@ var _ = Describe("Consolidation", func() { It("should respect budgets for non-empty replace consolidation", func() { appLabels := map[string]string{"app": "large-app"} // This test will hold consolidation until we are ready to execute it - nodePool.Spec.Disruption.ConsolidateAfter = &corev1beta1.NillableDuration{} + nodePool.Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("Never")) nodePool = test.ReplaceRequirements(nodePool, corev1beta1.NodeSelectorRequirementWithMinValues{ @@ -403,7 +403,7 @@ var _ = Describe("Consolidation", func() { Disruption: corev1beta1.Disruption{ ConsolidationPolicy: corev1beta1.ConsolidationPolicyWhenUnderutilized, // Disable Consolidation until we're ready - ConsolidateAfter: &corev1beta1.NillableDuration{}, + ConsolidateAfter: lo.ToPtr(corev1beta1.MustParseNillableDuration("Never")), }, Template: corev1beta1.NodeClaimTemplate{ Spec: corev1beta1.NodeClaimSpec{ @@ -482,7 +482,7 @@ var _ = Describe("Consolidation", func() { Disruption: corev1beta1.Disruption{ ConsolidationPolicy: corev1beta1.ConsolidationPolicyWhenUnderutilized, // Disable Consolidation until we're ready - ConsolidateAfter: &corev1beta1.NillableDuration{}, + ConsolidateAfter: lo.ToPtr(corev1beta1.MustParseNillableDuration("Never")), }, Template: corev1beta1.NodeClaimTemplate{ Spec: corev1beta1.NodeClaimSpec{ @@ -633,7 +633,7 @@ var _ = Describe("Consolidation", func() { Disruption: corev1beta1.Disruption{ ConsolidationPolicy: corev1beta1.ConsolidationPolicyWhenUnderutilized, // Disable Consolidation until we're ready - ConsolidateAfter: &corev1beta1.NillableDuration{}, + ConsolidateAfter: lo.ToPtr(corev1beta1.MustParseNillableDuration("Never")), }, Template: corev1beta1.NodeClaimTemplate{ Spec: corev1beta1.NodeClaimSpec{ diff --git a/test/suites/expiration/suite_test.go b/test/suites/expiration/suite_test.go index ed6e884e4dcd..34ed96fa3c2d 100644 --- a/test/suites/expiration/suite_test.go +++ b/test/suites/expiration/suite_test.go @@ -61,7 +61,7 @@ var _ = BeforeEach(func() { env.BeforeEach() nodeClass = env.DefaultEC2NodeClass() nodePool = env.DefaultNodePool(nodeClass) - nodePool.Spec.Disruption.ExpireAfter = corev1beta1.NillableDuration{Duration: lo.ToPtr(time.Second * 30)} + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("30s") }) var _ = AfterEach(func() { env.Cleanup() }) @@ -106,7 +106,7 @@ var _ = Describe("Expiration", func() { nodePool.Spec.Disruption.Budgets = []corev1beta1.Budget{{ Nodes: "100%", }} - nodePool.Spec.Disruption.ExpireAfter = corev1beta1.NillableDuration{} + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("Never") // Create a deployment with one pod to create one node. dep = coretest.Deployment(coretest.DeploymentOptions{ @@ -155,7 +155,7 @@ var _ = Describe("Expiration", func() { env.ExpectUpdated(node) By("enabling expiration") - nodePool.Spec.Disruption.ExpireAfter = corev1beta1.NillableDuration{Duration: lo.ToPtr(time.Second * 30)} + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("30s") env.ExpectUpdated(nodePool) // Expect that both of the nodes are expired, but not being disrupted @@ -189,7 +189,7 @@ var _ = Describe("Expiration", func() { nodePool.Spec.Disruption.Budgets = []corev1beta1.Budget{{ Nodes: "50%", }} - nodePool.Spec.Disruption.ExpireAfter = corev1beta1.NillableDuration{} + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("Never") numPods = 6 dep = coretest.Deployment(coretest.DeploymentOptions{ @@ -230,7 +230,7 @@ var _ = Describe("Expiration", func() { env.ExpectDeleted(dep) By("enabling expiration") - nodePool.Spec.Disruption.ExpireAfter = corev1beta1.NillableDuration{Duration: lo.ToPtr(time.Second * 30)} + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("30s") env.ExpectUpdated(nodePool) env.EventuallyExpectExpired(nodeClaims...) @@ -270,7 +270,7 @@ var _ = Describe("Expiration", func() { Nodes: "50%", }} // disable expiration so that we can enable it later when we want. - nodePool.Spec.Disruption.ExpireAfter = corev1beta1.NillableDuration{} + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("Never") numPods = 9 dep = coretest.Deployment(coretest.DeploymentOptions{ Replicas: int32(numPods), @@ -316,7 +316,7 @@ var _ = Describe("Expiration", func() { By("expiring the nodes") // expire the nodeclaims - nodePool.Spec.Disruption.ExpireAfter = corev1beta1.NillableDuration{Duration: lo.ToPtr(time.Second * 30)} + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("30s") env.ExpectUpdated(nodePool) env.EventuallyExpectExpired(nodeClaims...) @@ -384,7 +384,7 @@ var _ = Describe("Expiration", func() { } By("enabling expiration") - nodePool.Spec.Disruption.ExpireAfter = corev1beta1.NillableDuration{Duration: lo.ToPtr(30 * time.Second)} + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("30s") env.ExpectUpdated(nodePool) // Ensure that we get two nodes tainted, and they have overlap during the expiration @@ -396,7 +396,7 @@ var _ = Describe("Expiration", func() { // 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.Disruption.ExpireAfter.Duration = nil + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("Never") env.ExpectUpdated(nodePool) for _, node := range nodes { @@ -473,7 +473,7 @@ var _ = Describe("Expiration", func() { // 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.Disruption.ExpireAfter.Duration = nil + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("Never") env.ExpectUpdated(nodePool) // After the deletion timestamp is set and all pods are drained @@ -514,7 +514,7 @@ var _ = Describe("Expiration", func() { 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.Disruption.ExpireAfter.Duration = lo.ToPtr(time.Minute) + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("1m") env.ExpectUpdated(nodePool) env.EventuallyExpectExpired(nodeClaim) @@ -537,7 +537,7 @@ var _ = Describe("Expiration", func() { // 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.Disruption.ExpireAfter.Duration = nil + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("Never") env.ExpectUpdated(nodePool) // After the deletion timestamp is set and all pods are drained diff --git a/test/suites/integration/emptiness_test.go b/test/suites/integration/emptiness_test.go index fc63b3b401b1..b147bee0bbab 100644 --- a/test/suites/integration/emptiness_test.go +++ b/test/suites/integration/emptiness_test.go @@ -38,7 +38,7 @@ var _ = Describe("Emptiness", func() { var numPods int BeforeEach(func() { nodePool.Spec.Disruption.ConsolidationPolicy = corev1beta1.ConsolidationPolicyWhenEmpty - nodePool.Spec.Disruption.ConsolidateAfter = &corev1beta1.NillableDuration{Duration: lo.ToPtr(time.Duration(0))} + nodePool.Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("0s")) numPods = 1 dep = test.Deployment(test.DeploymentOptions{ @@ -96,7 +96,7 @@ var _ = Describe("Emptiness", func() { }) }) It("should terminate an empty node", func() { - nodePool.Spec.Disruption.ConsolidateAfter = &corev1beta1.NillableDuration{Duration: lo.ToPtr(time.Hour * 300)} + nodePool.Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("300h")) const numPods = 1 deployment := test.Deployment(test.DeploymentOptions{Replicas: numPods}) @@ -115,7 +115,7 @@ var _ = Describe("Emptiness", func() { env.EventuallyExpectEmpty(nodeClaim) By("waiting for the nodeclaim to deprovision when past its ConsolidateAfter timeout of 0") - nodePool.Spec.Disruption.ConsolidateAfter = &corev1beta1.NillableDuration{Duration: lo.ToPtr(time.Duration(0))} + nodePool.Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("0s")) env.ExpectUpdated(nodePool) env.EventuallyExpectNotFound(nodeClaim, node) diff --git a/test/suites/integration/validation_test.go b/test/suites/integration/validation_test.go index 522815d151ca..e7c23bd3bc5a 100644 --- a/test/suites/integration/validation_test.go +++ b/test/suites/integration/validation_test.go @@ -16,7 +16,6 @@ package integration_test import ( "fmt" - "time" "github.com/samber/lo" v1 "k8s.io/api/core/v1" @@ -103,12 +102,12 @@ var _ = Describe("Validation", func() { }) It("should error when ttlSecondAfterEmpty is negative", func() { nodePool.Spec.Disruption.ConsolidationPolicy = corev1beta1.ConsolidationPolicyWhenEmpty - nodePool.Spec.Disruption.ConsolidateAfter = &corev1beta1.NillableDuration{Duration: lo.ToPtr(-time.Second)} + nodePool.Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("-1s")) Expect(env.Client.Create(env.Context, nodePool)).ToNot(Succeed()) }) It("should error when ConsolidationPolicy=WhenUnderutilized is used with consolidateAfter", func() { nodePool.Spec.Disruption.ConsolidationPolicy = corev1beta1.ConsolidationPolicyWhenUnderutilized - nodePool.Spec.Disruption.ConsolidateAfter = &corev1beta1.NillableDuration{Duration: lo.ToPtr(time.Minute)} + nodePool.Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("1m")) Expect(env.Client.Create(env.Context, nodePool)).ToNot(Succeed()) }) It("should error if imageGCHighThresholdPercent is less than imageGCLowThresholdPercent", func() { diff --git a/test/suites/scale/deprovisioning_test.go b/test/suites/scale/deprovisioning_test.go index cf7eaa8b9b98..73aba8cb90a4 100644 --- a/test/suites/scale/deprovisioning_test.go +++ b/test/suites/scale/deprovisioning_test.go @@ -246,8 +246,8 @@ var _ = Describe("Deprovisioning", Label(debug.NoWatch), Label(debug.NoEvents), // Enable consolidation, emptiness, and expiration nodePoolMap[consolidationValue].Spec.Disruption.ConsolidateAfter = nil nodePoolMap[emptinessValue].Spec.Disruption.ConsolidationPolicy = corev1beta1.ConsolidationPolicyWhenEmpty - nodePoolMap[emptinessValue].Spec.Disruption.ConsolidateAfter.Duration = lo.ToPtr(time.Duration(0)) - nodePoolMap[expirationValue].Spec.Disruption.ExpireAfter.Duration = lo.ToPtr(time.Duration(0)) + nodePoolMap[emptinessValue].Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("0s")) + nodePoolMap[expirationValue].Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("0s") nodePoolMap[expirationValue].Spec.Limits = disableProvisioningLimits // Update the drift NodeClass to start drift on Nodes assigned to this NodeClass driftNodeClass.Spec.AMIFamily = &v1beta1.AMIFamilyBottlerocket @@ -555,7 +555,7 @@ var _ = Describe("Deprovisioning", Label(debug.NoWatch), Label(debug.NoEvents), env.MeasureDeprovisioningDurationFor(func() { By("kicking off deprovisioning emptiness by setting the ttlSecondsAfterEmpty value on the nodePool") nodePool.Spec.Disruption.ConsolidationPolicy = corev1beta1.ConsolidationPolicyWhenEmpty - nodePool.Spec.Disruption.ConsolidateAfter.Duration = lo.ToPtr(time.Duration(0)) + nodePool.Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("0s")) env.ExpectCreatedOrUpdated(nodePool) env.EventuallyExpectDeletedNodeCount("==", expectedNodeCount) @@ -608,13 +608,13 @@ var _ = Describe("Deprovisioning", Label(debug.NoWatch), Label(debug.NoEvents), // Change limits so that replacement nodes will use another nodePool. nodePool.Spec.Limits = disableProvisioningLimits // Enable Expiration - nodePool.Spec.Disruption.ExpireAfter.Duration = lo.ToPtr(time.Duration(0)) + nodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("0s") noExpireNodePool := test.NodePool(*nodePool.DeepCopy()) // Disable Expiration - noExpireNodePool.Spec.Disruption.ConsolidateAfter = &corev1beta1.NillableDuration{} - noExpireNodePool.Spec.Disruption.ExpireAfter.Duration = nil + noExpireNodePool.Spec.Disruption.ConsolidateAfter = lo.ToPtr(corev1beta1.MustParseNillableDuration("Never")) + noExpireNodePool.Spec.Disruption.ExpireAfter = corev1beta1.MustParseNillableDuration("Never") noExpireNodePool.ObjectMeta = metav1.ObjectMeta{Name: test.RandomName()} noExpireNodePool.Spec.Template.Spec.Kubelet = &corev1beta1.KubeletConfiguration{