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

CNI IT to test for version upgrade/downgrade #1795

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 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
18 changes: 11 additions & 7 deletions test/framework/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ func init() {
}

type Options struct {
KubeConfig string
ClusterName string
AWSRegion string
AWSVPCID string
NgNameLabelKey string
NgNameLabelVal string
EKSEndpoint string
KubeConfig string
ClusterName string
AWSRegion string
AWSVPCID string
NgNameLabelKey string
NgNameLabelVal string
EKSEndpoint string
InitialCNIVersion string
FinalCNIVersion string
}

func (options *Options) BindFlags() {
Expand All @@ -44,6 +46,8 @@ func (options *Options) BindFlags() {
flag.StringVar(&options.NgNameLabelKey, "ng-name-label-key", "eks.amazonaws.com/nodegroup", "label key used to identify nodegroup name")
flag.StringVar(&options.NgNameLabelVal, "ng-name-label-val", "", "label value with the nodegroup name")
flag.StringVar(&options.EKSEndpoint, "eks-endpoint", "", "optional eks api server endpoint")
flag.StringVar(&options.InitialCNIVersion, "initial-version", "", "Initial CNI version before upgrade applied")
flag.StringVar(&options.FinalCNIVersion, "final-version", "", "Final CNI version after upgrade applied")
}

func (options *Options) Validate() error {
Expand Down
39 changes: 35 additions & 4 deletions test/framework/resources/aws/services/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,25 @@ import (

type EKS interface {
DescribeCluster(clusterName string) (*eks.DescribeClusterOutput, error)
CreateAddon(addon string, clusterName string) (*eks.CreateAddonOutput, error)
CreateAddon(createAddOnParams AddOnInput) (*eks.CreateAddonOutput, error)
DeleteAddon(addon string, clusterName string) (*eks.DeleteAddonOutput, error)
DescribeAddonVersions(addon string, k8sVersion string) (*eks.DescribeAddonVersionsOutput, error)
DescribeAddon(addon string, clusterName string) (*eks.DescribeAddonOutput, error)
}

type defaultEKS struct {
eksiface.EKSAPI
}

// struct added to make params passing extensible
type AddOnInput struct {
_ struct{} `type:"structure"`

AddonName string `locationName:"addonName" type:"string" required:"true"`
ClusterName string `location:"uri" locationName:"name" min:"1" type:"string" required:"true"`
AddonVersion string `locationName:"addonVersion" type:"string"` // eg format: v1.9.3-eksbuild.1
}

func NewEKS(session *session.Session, endpoint string) EKS {
return &defaultEKS{
EKSAPI: eks.New(session, &aws.Config{
Expand All @@ -39,10 +50,14 @@ func NewEKS(session *session.Session, endpoint string) EKS {
}
}

func (d defaultEKS) CreateAddon(addon string, clusterName string) (*eks.CreateAddonOutput, error) {
func (d defaultEKS) CreateAddon(addOnInput AddOnInput) (*eks.CreateAddonOutput, error) {
createAddonInput := &eks.CreateAddonInput{
AddonName: aws.String(addon),
ClusterName: aws.String(clusterName),
AddonName: aws.String(addOnInput.AddonName),
ClusterName: aws.String(addOnInput.ClusterName),
}
if addOnInput.AddonVersion != "" {
createAddonInput.SetAddonVersion(addOnInput.AddonVersion)
createAddonInput.SetResolveConflicts("OVERWRITE")
}
return d.EKSAPI.CreateAddon(createAddonInput)
}
Expand All @@ -55,6 +70,22 @@ func (d defaultEKS) DeleteAddon(addon string, clusterName string) (*eks.DeleteAd
return d.EKSAPI.DeleteAddon(deleteAddonInput)
}

func (d defaultEKS) DescribeAddonVersions(addon string, k8sVersion string) (*eks.DescribeAddonVersionsOutput, error) {
describeAddonVersionsInput := &eks.DescribeAddonVersionsInput{
AddonName: aws.String(addon),
KubernetesVersion: aws.String(k8sVersion),
}
return d.EKSAPI.DescribeAddonVersions(describeAddonVersionsInput)
}

func (d defaultEKS) DescribeAddon(addon string, clusterName string) (*eks.DescribeAddonOutput, error) {
describeAddonInput := &eks.DescribeAddonInput{
AddonName: aws.String(addon),
ClusterName: aws.String(clusterName),
}
return d.EKSAPI.DescribeAddon(describeAddonInput)
}

func (d defaultEKS) DescribeCluster(clusterName string) (*eks.DescribeClusterOutput, error) {
describeClusterInput := &eks.DescribeClusterInput{
Name: aws.String(clusterName),
Expand Down
104 changes: 104 additions & 0 deletions test/integration-new/cni/cni_version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package cni

import (
"fmt"
"time"

"github.com/aws/amazon-vpc-cni-k8s/test/framework/resources/aws/services"
"github.com/pkg/errors"

k8sUtils "github.com/aws/amazon-vpc-cni-k8s/test/framework/resources/k8s/utils"
"github.com/aws/aws-sdk-go/service/eks"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var (
describeAddonOutput *eks.DescribeAddonOutput
err error
initialCNIVersion string
finalCNIVersion string
)

var _ = Describe("test cluster upgrade/downgrade", func() {

It("should apply initial addon version successfully", func() {
By("getting initial cni version")
if len(f.Options.InitialCNIVersion) == 0 {
err = errors.Errorf("%s must be set!", "initial-version")
}
Expect(err).ToNot(HaveOccurred())
initialCNIVersion = f.Options.InitialCNIVersion
ApplyAddOn(initialCNIVersion)
cgchinmay marked this conversation as resolved.
Show resolved Hide resolved

})

Context("when testing host networking on initial version", func() {
HostNetworkingTest()
PodTrafficTest()
ServiceConnectivityTest()
})

It("should apply final addon version successfully", func() {
By("getting final cni version")
if len(f.Options.FinalCNIVersion) == 0 {
err = errors.Errorf("%s must be set!", "final-version")
}
Expect(err).ToNot(HaveOccurred())
finalCNIVersion = f.Options.FinalCNIVersion
ApplyAddOn(finalCNIVersion)

})

Context("when testing host networking on final version", func() {
HostNetworkingTest()
PodTrafficTest()
ServiceConnectivityTest()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these 3 functions are 3 different kinds of tests, so should be separated out in 3 Contexts ? would like to know your thoughts

})

})

func ApplyAddOn(versionName string) {

By("getting the current addon")
describeAddonOutput, err = f.CloudServices.EKS().DescribeAddon("vpc-cni", f.Options.ClusterName)
if err == nil {
By("checking if the current addon is same as addon to be applied")
if *describeAddonOutput.Addon.AddonVersion != versionName {

By("deleting the current vpc cni addon ")
_, err = f.CloudServices.EKS().DeleteAddon("vpc-cni", f.Options.ClusterName)
Expect(err).ToNot(HaveOccurred())

_, err = f.CloudServices.EKS().DescribeAddon("vpc-cni", f.Options.ClusterName)
for err == nil {
Copy link
Contributor

@cgchinmay cgchinmay Feb 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could lead to an infinite loop. I think we should refactor this logic. We should have some timeout

time.Sleep(5 * time.Second)
_, err = f.CloudServices.EKS().DescribeAddon("vpc-cni", f.Options.ClusterName)

}

By(fmt.Sprintf("By applying addon %s\n", versionName))
_, err = f.CloudServices.EKS().CreateAddon(services.AddOnInput{AddonName: "vpc-cni", ClusterName: f.Options.ClusterName, AddonVersion: versionName})
Expect(err).ToNot(HaveOccurred())

}
} else {
By(fmt.Sprintf("By applying addon %s\n", versionName))
_, err = f.CloudServices.EKS().CreateAddon(services.AddOnInput{AddonName: "vpc-cni", ClusterName: f.Options.ClusterName, AddonVersion: versionName})
Expect(err).ToNot(HaveOccurred())
}

var status = ""

By("waiting for addon to be ACTIVE")
for status != "ACTIVE" {
Copy link
Contributor

@cgchinmay cgchinmay Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be extracted to a utility function similar to daemonset.go. So this logic can be extended.

describeAddonOutput, err = f.CloudServices.EKS().DescribeAddon("vpc-cni", f.Options.ClusterName)
Expect(err).ToNot(HaveOccurred())
status = *describeAddonOutput.Addon.Status
time.Sleep(5 * time.Second)
}

//Set the WARM_ENI_TARGET to 0 to prevent all pods being scheduled on secondary ENI
k8sUtils.AddEnvVarToDaemonSetAndWaitTillUpdated(f, "aws-node", "kube-system",
Copy link
Contributor

@cgchinmay cgchinmay Feb 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the default settings when you apply an addon ?Just want to know why we need to ensure these env settings ?

"aws-node", map[string]string{"WARM_IP_TARGET": "3", "WARM_ENI_TARGET": "0"})
}
7 changes: 5 additions & 2 deletions test/integration-new/cni/host_networking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ const (
DEFAULT_VETH_PREFIX = "eni"
)

var _ = Describe("test host networking", func() {
var _ = Describe("test host networking", HostNetworkingTest)

func HostNetworkingTest() {

var err error
var podLabelKey = "app"
var podLabelVal = "host-networking-test"
Expand Down Expand Up @@ -205,7 +208,7 @@ var _ = Describe("test host networking", func() {
Expect(err).ToNot(HaveOccurred())
})
})
})
}

// Validate host networking for the list of pods supplied
func ValidateHostNetworking(testType TestType, podValidationInputString string) {
Expand Down
6 changes: 4 additions & 2 deletions test/integration-new/cni/pod_traffic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import (
// Verifies network connectivity across Pods placed on different combination of
// primary and second Elastic Networking Interface on two nodes. The test verifies
// different traffic type for instance TCP, UDP, ICMP
var _ = Describe("test pod networking", func() {
var _ = Describe("test pod networking", PodTrafficTest)

func PodTrafficTest() {

var (
err error
Expand Down Expand Up @@ -263,7 +265,7 @@ var _ = Describe("test pod networking", func() {
testFailedConnectionCommandFunc)
})
})
})
}

func VerifyConnectivityFailsForNegativeCase(senderPod coreV1.Pod, receiverPod coreV1.Pod, port int,
getTestCommandFunc func(receiverPod coreV1.Pod, port int) []string) {
Expand Down
6 changes: 4 additions & 2 deletions test/integration-new/cni/service_connectivity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const (
)

// Verifies connectivity to deployment behind different service types
var _ = Describe("[CANARY] test service connectivity", func() {
var _ = Describe("[CANARY] test service connectivity", ServiceConnectivityTest)

func ServiceConnectivityTest() {
var err error

// Deployment running the http server
Expand Down Expand Up @@ -177,4 +179,4 @@ var _ = Describe("[CANARY] test service connectivity", func() {
})

//TODO: Add test case to install lb controller and test with nlb-ip mode
})
}
4 changes: 3 additions & 1 deletion test/integration-new/ipamd/ipamd_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package ipamd
import (
"testing"

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

"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/aws-sdk-go/service/ec2"
Expand Down Expand Up @@ -61,7 +63,7 @@ var _ = BeforeSuite(func() {
var _ = AfterSuite(func() {
if addonDeleteError == nil {
By("Restore coredns addon")
_, err := f.CloudServices.EKS().CreateAddon("coredns", f.Options.ClusterName)
_, err := f.CloudServices.EKS().CreateAddon(services.AddOnInput{AddonName: "coredns", ClusterName: f.Options.ClusterName})
Expect(err).NotTo(HaveOccurred())
}
})