Skip to content

Commit

Permalink
Merge pull request #3229 from pydctw/eks-upgrade-test
Browse files Browse the repository at this point in the history
Enable EKS upgrade test
  • Loading branch information
k8s-ci-robot committed Mar 2, 2022
2 parents 2d5075c + 42918e2 commit 9a74bcc
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ USE_EXISTING_CLUSTER ?= "false"

# Set E2E_SKIP_EKS_UPGRADE to false to test EKS upgrades.
# Warning, this takes a long time
E2E_SKIP_EKS_UPGRADE ?= "true"
E2E_SKIP_EKS_UPGRADE ?= "false"

# Set EKS_SOURCE_TEMPLATE to override the source template
EKS_SOURCE_TEMPLATE ?= eks/cluster-template-eks-control-plane-only.yaml
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/data/e2e_eks_conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# E2E test scenario using local dev images and manifests built from the source tree for following providers:
# - cluster-api
# - infrastructure aws
# - boostrap aws-eks
# - control-plane aws-eks

# To run tests, run the following from the root of this repository.
# `AWS_REGION=eu-west-1 make e2e GINKGO_ARGS=-stream E2E_ARGS=-skip-cloudformation-deletion`
Expand Down
22 changes: 8 additions & 14 deletions test/e2e/shared/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ const (
idName = "e2e-account"
)

func SetupStaticCredentials(ctx context.Context, namespace *corev1.Namespace, e2eCtx *E2EContext) {
Expect(ctx).NotTo(BeNil(), "ctx is required for SetupStaticCredentials")
Expect(namespace).NotTo(BeNil(), "namespace is required for SetupStaticCredentials")
func SetupStaticCredentials(e2eCtx *E2EContext) {
Expect(e2eCtx).NotTo(BeNil(), "e2eCtx is required for SetupStaticCredentials")
Expect(e2eCtx.Environment.BootstrapAccessKey).NotTo(BeNil(), "e2eCtx.Environment.BootstrapAccessKey is required for SetupStaticCredentials")

ctx := context.TODO()
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: credsSecretName,
Expand All @@ -60,38 +59,33 @@ func SetupStaticCredentials(ctx context.Context, namespace *corev1.Namespace, e2

id := &infrav1.AWSClusterStaticIdentity{
ObjectMeta: metav1.ObjectMeta{
Name: idName,
Namespace: namespace.Name,
Name: idName,
},
Spec: infrav1.AWSClusterStaticIdentitySpec{
SecretRef: credsSecretName,
AWSClusterIdentitySpec: infrav1.AWSClusterIdentitySpec{
AllowedNamespaces: &infrav1.AllowedNamespaces{
NamespaceList: []string{namespace.Name},
},
AllowedNamespaces: &infrav1.AllowedNamespaces{},
},
},
}

Byf("Creating AWSClusterStaticIdentity %s in namespace %s", id.Name, namespace.Name)
Byf("Creating AWSClusterStaticIdentity %s", id.Name)
Eventually(func() error {
return client.Create(ctx, id)
}, e2eCtx.E2EConfig.GetIntervals("", "wait-create-identity")...).Should(Succeed())
}

func CleanupStaticCredentials(ctx context.Context, namespace *corev1.Namespace, e2eCtx *E2EContext) {
func CleanupStaticCredentials(ctx context.Context, e2eCtx *E2EContext) {
Expect(ctx).NotTo(BeNil(), "ctx is required for SetupStaticCredentials")
Expect(namespace).NotTo(BeNil(), "namespace is required for SetupStaticCredentials")
Expect(e2eCtx).NotTo(BeNil(), "e2eCtx is required for SetupStaticCredentials")

id := &infrav1.AWSClusterStaticIdentity{
ObjectMeta: metav1.ObjectMeta{
Name: idName,
Namespace: namespace.Name,
Name: idName,
},
}

Byf("Deleting AWSClusterStaticIdentity %s in namespace %s", idName, namespace.Name)
Byf("Deleting AWSClusterStaticIdentity %s", idName)
client := e2eCtx.Environment.BootstrapClusterProxy.GetClient()
Eventually(func() error {
return client.Delete(ctx, id)
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/shared/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ func Node1BeforeSuite(e2eCtx *E2EContext) []byte {

CreateAWSClusterControllerIdentity(e2eCtx.Environment.BootstrapClusterProxy.GetClient())

if e2eCtx.IsManaged {
By("Setting up AWS static credentials")
SetupStaticCredentials(e2eCtx)
}

conf := synchronizedBeforeTestSuiteConfig{
ArtifactFolder: e2eCtx.Settings.ArtifactFolder,
ConfigPath: e2eCtx.Settings.ConfigPath,
Expand Down Expand Up @@ -257,6 +262,12 @@ func Node1AfterSuite(e2eCtx *E2EContext) {
ctx, cancel := context.WithTimeout(context.TODO(), 15*time.Minute)
DumpEKSClusters(ctx, e2eCtx)
DumpCloudTrailEvents(e2eCtx)

if e2eCtx.IsManaged {
By("Deleting AWS static credentials")
CleanupStaticCredentials(ctx, e2eCtx)
}

defer cancel()
By("Tearing down the management cluster")
if !e2eCtx.Settings.SkipCleanup {
Expand Down
24 changes: 0 additions & 24 deletions test/e2e/suites/managed/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,3 @@ type DeleteClusterSpecInput struct {
Namespace *corev1.Namespace
ClusterName string
}

// DeleteClusterSpec implements a test for deleting a Cluster.
func DeleteClusterSpec(ctx context.Context, inputGetter func() DeleteClusterSpecInput) {
input := inputGetter()
Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil")
Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil")
Expect(input.Namespace).NotTo(BeNil(), "Invalid argument. input.Namespace can't be nil")
Expect(input.ClusterName).ShouldNot(HaveLen(0), "Invalid argument. input.ClusterName can't be empty")

shared.Byf("getting cluster with name %s", input.ClusterName)
cluster := framework.GetClusterByName(ctx, framework.GetClusterByNameInput{
Getter: input.BootstrapClusterProxy.GetClient(),
Namespace: input.Namespace.Name,
Name: input.ClusterName,
})
Expect(cluster).NotTo(BeNil(), "couldn't find cluster")

shared.Byf("Deleting cluster %s/%s", input.Namespace, input.ClusterName)

framework.DeleteCluster(ctx, framework.DeleteClusterInput{
Deleter: input.BootstrapClusterProxy.GetClient(),
Cluster: cluster,
})
}
6 changes: 0 additions & 6 deletions test/e2e/suites/managed/eks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ var _ = ginkgo.Describe("[managed] [general] EKS cluster tests", func() {
namespace = shared.SetupSpecNamespace(ctx, specName, e2eCtx)
clusterName = fmt.Sprintf("cluster-%s", util.RandomString(6))

ginkgo.By("setting up AWS static credentials")
shared.SetupStaticCredentials(ctx, namespace, e2eCtx)

ginkgo.By("default iam role should exist")
verifyRoleExistsAndOwned(ekscontrolplanev1.DefaultEKSControlPlaneRole, clusterName, false, e2eCtx.BootstrapUserAWSSession)

Expand Down Expand Up @@ -148,8 +145,5 @@ var _ = ginkgo.Describe("[managed] [general] EKS cluster tests", func() {
Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
Cluster: cluster,
}, e2eCtx.E2EConfig.GetIntervals("", "wait-delete-cluster")...)

ginkgo.By("Deleting AWS static credentials")
shared.CleanupStaticCredentials(ctx, namespace, e2eCtx)
})
})
33 changes: 17 additions & 16 deletions test/e2e/suites/managed/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ import (
"context"
"fmt"

. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"

ekscontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/controlplane/eks/api/v1beta1"
"sigs.k8s.io/cluster-api-provider-aws/test/e2e/shared"
"sigs.k8s.io/cluster-api/test/framework"
"sigs.k8s.io/cluster-api/util"
)

// EKS cluster upgrade tests.
var _ = Describe("EKS Cluster upgrade test", func() {
var _ = ginkgo.Describe("EKS Cluster upgrade test", func() {
const (
initialVersion = "v1.17.0"
upgradeToversion = "v1.18.0"
initialVersion = "v1.20.0"
upgradeToversion = "v1.21.0"
)
var (
namespace *corev1.Namespace
Expand All @@ -46,7 +47,7 @@ var _ = Describe("EKS Cluster upgrade test", func() {
)

shared.ConditionalIt(runUpgradeTests, "[managed] [upgrade] should create a cluster and upgrade the kubernetes version", func() {
By("should have a valid test configuration")
ginkgo.By("should have a valid test configuration")
Expect(e2eCtx.Environment.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. BootstrapClusterProxy can't be nil")
Expect(e2eCtx.E2EConfig).ToNot(BeNil(), "Invalid argument. e2eConfig can't be nil when calling %s spec", specName)
Expect(e2eCtx.E2EConfig.Variables).To(HaveKey(shared.KubernetesVersion))
Expand All @@ -55,7 +56,10 @@ var _ = Describe("EKS Cluster upgrade test", func() {
namespace = shared.SetupSpecNamespace(ctx, specName, e2eCtx)
clusterName = fmt.Sprintf("cluster-%s", util.RandomString(6))

By("should create an EKS control plane")
ginkgo.By("default iam role should exist")
verifyRoleExistsAndOwned(ekscontrolplanev1.DefaultEKSControlPlaneRole, clusterName, false, e2eCtx.BootstrapUserAWSSession)

ginkgo.By("should create an EKS control plane")
ManagedClusterSpec(ctx, func() ManagedClusterSpecInput {
return ManagedClusterSpecInput{
E2EConfig: e2eCtx.E2EConfig,
Expand Down Expand Up @@ -104,16 +108,13 @@ var _ = Describe("EKS Cluster upgrade test", func() {

// TODO (richardcase): add test for the node group upgrade

shared.Byf("should delete cluster %s", clusterName)
DeleteClusterSpec(ctx, func() DeleteClusterSpecInput {
return DeleteClusterSpecInput{
E2EConfig: e2eCtx.E2EConfig,
BootstrapClusterProxy: e2eCtx.Environment.BootstrapClusterProxy,
ClusterName: clusterName,
Namespace: namespace,
}
framework.DeleteCluster(ctx, framework.DeleteClusterInput{
Deleter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
Cluster: cluster,
})

framework.WaitForClusterDeleted(ctx, framework.WaitForClusterDeletedInput{
Getter: e2eCtx.Environment.BootstrapClusterProxy.GetClient(),
Cluster: cluster,
}, e2eCtx.E2EConfig.GetIntervals("", "wait-delete-cluster")...)
})

})

0 comments on commit 9a74bcc

Please sign in to comment.