|
| 1 | +//go:build integration |
| 2 | + |
| 3 | +//revive:disable Not changing package name |
| 4 | +package cluster_config |
| 5 | + |
| 6 | +import ( |
| 7 | + "context" |
| 8 | + "testing" |
| 9 | + |
| 10 | + "github.com/aws/aws-sdk-go-v2/aws" |
| 11 | + awseks "github.com/aws/aws-sdk-go-v2/service/eks" |
| 12 | + . "github.com/onsi/ginkgo/v2" |
| 13 | + . "github.com/onsi/gomega" |
| 14 | + |
| 15 | + . "github.com/weaveworks/eksctl/integration/runner" |
| 16 | + "github.com/weaveworks/eksctl/integration/tests" |
| 17 | + clusterutils "github.com/weaveworks/eksctl/integration/utilities/cluster" |
| 18 | + api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5" |
| 19 | + "github.com/weaveworks/eksctl/pkg/awsapi" |
| 20 | + "github.com/weaveworks/eksctl/pkg/eks" |
| 21 | + "github.com/weaveworks/eksctl/pkg/testutils" |
| 22 | +) |
| 23 | + |
| 24 | +var params *tests.Params |
| 25 | + |
| 26 | +func init() { |
| 27 | + // Call testing.Init() prior to tests.NewParams(), as otherwise -test.* will not be recognised. See also: https://golang.org/doc/go1.13#testing |
| 28 | + testing.Init() |
| 29 | + params = tests.NewParams("cluster-config") |
| 30 | +} |
| 31 | + |
| 32 | +func TestClusterConfig(t *testing.T) { |
| 33 | + testutils.RegisterAndRun(t) |
| 34 | +} |
| 35 | + |
| 36 | +const ( |
| 37 | + expectedControlPlaneTier = "tier-xl" |
| 38 | + expectedSupportType = api.SupportTypeStandard |
| 39 | +) |
| 40 | + |
| 41 | +var eksAPI awsapi.EKS |
| 42 | + |
| 43 | +var _ = BeforeSuite(func() { |
| 44 | + if params.SkipCreate { |
| 45 | + return |
| 46 | + } |
| 47 | + clusterConfig := api.NewClusterConfig() |
| 48 | + clusterConfig.Metadata.Name = params.ClusterName |
| 49 | + clusterConfig.Metadata.Region = params.Region |
| 50 | + clusterConfig.Metadata.Version = params.Version |
| 51 | + clusterConfig.ManagedNodeGroups = []*api.ManagedNodeGroup{} |
| 52 | + clusterConfig.UpgradePolicy = &api.UpgradePolicy{ |
| 53 | + SupportType: expectedSupportType, |
| 54 | + } |
| 55 | + clusterConfig.ControlPlaneScalingConfig = &api.ControlPlaneScalingConfig{ |
| 56 | + Tier: aws.String(expectedControlPlaneTier), |
| 57 | + } |
| 58 | + cmd := params.EksctlCreateCmd.WithArgs( |
| 59 | + "cluster", |
| 60 | + "--config-file", "-", |
| 61 | + "--verbose", "4", |
| 62 | + ). |
| 63 | + WithoutArg("--region", params.Region). |
| 64 | + WithStdin(clusterutils.Reader(clusterConfig)) |
| 65 | + |
| 66 | + Expect(cmd).To(RunSuccessfully()) |
| 67 | + |
| 68 | + clusterProvider, err := eks.New(context.Background(), &api.ProviderConfig{Region: params.Region}, clusterConfig) |
| 69 | + Expect(err).NotTo(HaveOccurred()) |
| 70 | + eksAPI = clusterProvider.AWSProvider.EKS() |
| 71 | +}) |
| 72 | + |
| 73 | +var _ = Describe("(Integration) [Cluster Config test]", func() { |
| 74 | + |
| 75 | + Context("Cluster with config options", func() { |
| 76 | + |
| 77 | + It("upgradePolicy should be set", func() { |
| 78 | + cluster, err := eksAPI.DescribeCluster(context.Background(), &awseks.DescribeClusterInput{ |
| 79 | + Name: aws.String(params.ClusterName), |
| 80 | + }) |
| 81 | + ExpectWithOffset(1, err).NotTo(HaveOccurred()) |
| 82 | + Expect(string(cluster.Cluster.UpgradePolicy.SupportType)).To(Equal(expectedSupportType)) |
| 83 | + }) |
| 84 | + |
| 85 | + It("control plane policy should be set", func() { |
| 86 | + cluster, err := eksAPI.DescribeCluster(context.Background(), &awseks.DescribeClusterInput{ |
| 87 | + Name: aws.String(params.ClusterName), |
| 88 | + }) |
| 89 | + ExpectWithOffset(1, err).NotTo(HaveOccurred()) |
| 90 | + Expect(string(cluster.Cluster.ControlPlaneScalingConfig.Tier)).To(Equal(expectedControlPlaneTier)) |
| 91 | + }) |
| 92 | + }) |
| 93 | + |
| 94 | +}) |
| 95 | + |
| 96 | +var _ = AfterSuite(func() { |
| 97 | + if params.SkipDelete { |
| 98 | + return |
| 99 | + } |
| 100 | + cmd := params.EksctlDeleteCmd.WithArgs( |
| 101 | + "cluster", params.ClusterName, |
| 102 | + "--disable-nodegroup-eviction", |
| 103 | + "--verbose", "2", |
| 104 | + ) |
| 105 | + Expect(cmd).To(RunSuccessfully()) |
| 106 | +}) |
0 commit comments