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

Resolve flakiness in IPAMD warm target tests; update test go.sum #2112

Merged
merged 2 commits into from
Oct 20, 2022
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 test/framework/resources/k8s/utils/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func updateDaemonsetEnvVarsAndWait(f *framework.Framework, dsName string, dsName
}

func getDaemonSet(f *framework.Framework, dsName string, dsNamespace string) *v1.DaemonSet {
By(fmt.Sprintf("getting the %s daemon set in namesapce %s", dsName, dsNamespace))
By(fmt.Sprintf("getting the %s daemon set in namespace %s", dsName, dsNamespace))
ds, err := f.K8sResourceManagers.
DaemonSetManager().
GetDaemonSet(dsNamespace, dsName)
Expand Down
2 changes: 2 additions & 0 deletions test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ github.com/go-openapi/validate v0.19.5/go.mod h1:8DJv2CVJQ6kGNpFW6eV9N3JviE1C85n
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/gobuffalo/logger v1.0.3 h1:YaXOTHNPCvkqqA7w05A4v0k2tCdpr+sgFlgINbQ6gqc=
github.com/gobuffalo/logger v1.0.3/go.mod h1:SoeejUwldiS7ZsyCBphOGURmWdwUFXs0J7TCjEhjKxM=
Expand Down Expand Up @@ -672,6 +673,7 @@ github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec=
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
Expand Down
48 changes: 41 additions & 7 deletions test/integration/ipamd/ipamd_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@
package ipamd

import (
"fmt"
"testing"
"time"

"github.com/aws/amazon-vpc-cni-k8s/test/framework"
k8sUtils "github.com/aws/amazon-vpc-cni-k8s/test/framework/resources/k8s/utils"
"github.com/aws/amazon-vpc-cni-k8s/test/framework/utils"
"github.com/aws/aws-sdk-go/service/ec2"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "k8s.io/api/apps/v1"
)

var primaryInstance *ec2.Instance
var f *framework.Framework
var err error

const (
CoreDNSDeploymentName = "coredns"
CoreDNSDeploymentNameSpace = "kube-system"
Expand All @@ -51,13 +57,14 @@ var _ = BeforeSuite(func() {
numOfNodes = len(nodeList.Items)
Expect(numOfNodes).Should(BeNumerically(">", 1))

// Nominate the first node as the 'primary' node and force coredns deployment on this
// Nominate the first node as the one to run coredns deployment against
By("adding nodeSelector in coredns deployment to be scheduled on single node")
instanceID := k8sUtils.GetInstanceIDFromNode(nodeList.Items[0])
primaryNode := nodeList.Items[0]
jdn5126 marked this conversation as resolved.
Show resolved Hide resolved
fmt.Fprintf(GinkgoWriter, "coredns node is %s\n", primaryNode.Name)
instanceID := k8sUtils.GetInstanceIDFromNode(primaryNode)
primaryInstance, err = f.CloudServices.EC2().DescribeInstance(instanceID)
Expect(err).ToNot(HaveOccurred())

// Add nodeSelector label to coredns deployment so coredns pods are scheduled on 'primary' node
By("getting node with no pods scheduled to run tests")
coreDNSDeployment, err := f.K8sResourceManagers.DeploymentManager().GetDeployment(CoreDNSDeploymentName,
CoreDNSDeploymentNameSpace)
Expand All @@ -66,16 +73,18 @@ var _ = BeforeSuite(func() {
// Copy the deployment to restore later
coreDNSDeploymentCopy = coreDNSDeployment.DeepCopy()

// Add nodeSelector label to coredns deployment so coredns pods are scheduled on 'primary' node
coreDNSDeployment.Spec.Template.Spec.NodeSelector = map[string]string{
"kubernetes.io/hostname": *primaryInstance.PrivateDnsName,
}

err = f.K8sResourceManagers.DeploymentManager().UpdateAndWaitTillDeploymentIsReady(coreDNSDeployment,
utils.DefaultDeploymentReadyTimeout)
Expect(err).ToNot(HaveOccurred())

// Nominate primaryInstance to node without coredns pods
instanceID = k8sUtils.GetInstanceIDFromNode(nodeList.Items[1])
// Redefine primary node as node without coredns pods. Note that this node may have previously had coredns pods.
primaryNode = nodeList.Items[1]
fmt.Fprintf(GinkgoWriter, "primary node is %s\n", primaryNode.Name)
instanceID = k8sUtils.GetInstanceIDFromNode(primaryNode)
primaryInstance, err = f.CloudServices.EC2().DescribeInstance(instanceID)
Expect(err).ToNot(HaveOccurred())

Expand All @@ -90,7 +99,7 @@ var _ = BeforeSuite(func() {
})

// Allow reconciler to free up ENIs if any
time.Sleep(utils.PollIntervalLong)
time.Sleep(utils.PollIntervalLong * 2)
})

var _ = AfterSuite(func() {
Expand All @@ -103,3 +112,28 @@ var _ = AfterSuite(func() {
f.K8sResourceManagers.NamespaceManager().
DeleteAndWaitTillNamespaceDeleted(utils.DefaultTestNamespace)
})

func ceil(x, y int) int {
return (x + y - 1) / y
}

func Max(x, y int) int {
if x < y {
return y
}
return x
}

// MinIgnoreZero returns smaller of two number, if any number is zero returns the other number
func MinIgnoreZero(x, y int) int {
if x == 0 {
return y
}
if y == 0 {
return x
}
if x < y {
return x
}
return y
}
17 changes: 9 additions & 8 deletions test/integration/ipamd/warm_target_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ var _ = Describe("test warm target variables", func() {
"MAX_ENI": strconv.Itoa(maxENI),
})

// Allow for IPAMD to reconcile it's state
// Allow for IPAMD to reconcile its state
time.Sleep(utils.PollIntervalLong * 5)

primaryInstance, err = f.CloudServices.
EC2().DescribeInstance(*primaryInstance.InstanceId)
Expect(err).ToNot(HaveOccurred())

// Validate number of allocated ENIs
Expect(len(primaryInstance.NetworkInterfaces)).
Should(Equal(MinIgnoreZero(warmENITarget, maxENI)))
})
Expand All @@ -58,13 +59,13 @@ var _ = Describe("test warm target variables", func() {
map[string]struct{}{"WARM_ENI_TARGET": {}, "MAX_ENI": {}})
})

Context("when WARM_ENI_TARGET = 2 and MAX_ENI = 1", func() {
Context("when WARM_ENI_TARGET = 3 and MAX_ENI = 2", func() {
BeforeEach(func() {
warmENITarget = 2
maxENI = 1
warmENITarget = 3
maxENI = 2
})

It("instance should have only 1 ENI", func() {})
It("instance should have only 2 ENIs", func() {})
})

Context("when WARM_ENI_TARGET = 3", func() {
Expand All @@ -76,13 +77,13 @@ var _ = Describe("test warm target variables", func() {
It("instance should have only 3 ENIs", func() {})
})

Context("when WARM_ENI_TARGET = 1", func() {
Context("when WARM_ENI_TARGET = 2", func() {
BeforeEach(func() {
warmENITarget = 1
warmENITarget = 2
maxENI = 0
})

It("instance should have only 1 ENI", func() {})
It("instance should have only 2 ENIs", func() {})
})

})
Expand Down
36 changes: 2 additions & 34 deletions test/integration/ipamd/warm_target_test_PD_enabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,13 @@ import (
"strconv"
"time"

"github.com/aws/amazon-vpc-cni-k8s/test/framework"
"github.com/aws/aws-sdk-go/service/ec2"

k8sUtils "github.com/aws/amazon-vpc-cni-k8s/test/framework/resources/k8s/utils"
"github.com/aws/amazon-vpc-cni-k8s/test/framework/utils"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var primaryInstance *ec2.Instance
var f *framework.Framework
var err error

// IMPORTANT: THE NODEGROUP TO RUN THE TEST MUST NOT HAVE ANY POD
// Ideally we should drain the node, but drain from go client is non trivial
// IMPORTANT: Only support nodes that can have 16+ Secondary IPV4s across at least 3 ENI
Expand Down Expand Up @@ -113,7 +106,7 @@ var _ = Describe("test warm target variables", func() {
minIPTarget = 16
})

It("should have 1 prefixe", func() {})
It("should have 1 prefix", func() {})
})

Context("when MINIMUM_IP_TARGET = 6 and WARM_IP_TARGET = 10", func() {
Expand Down Expand Up @@ -258,7 +251,7 @@ var _ = Describe("test warm target variables", func() {
warmPrefixTarget = 0
})

It("should have 1 prefixe", func() {})
It("should have 1 prefix", func() {})
})

Context("when MINIMUM_IP_TARGET = 6, WARM_IP_TARGET = 10 and WARM_PREFIX_TARGET = 1", func() {
Expand All @@ -272,28 +265,3 @@ var _ = Describe("test warm target variables", func() {
})
})
})

func ceil(x, y int) int {
return (x + y - 1) / y
}

func Max(x, y int) int {
if x < y {
return y
}
return x
}

// MinIgnoreZero returns smaller of two number, if any number is zero returns the other number
func MinIgnoreZero(x, y int) int {
if x == 0 {
return y
}
if y == 0 {
return x
}
if x < y {
return x
}
return y
}