From bb44d8a407483cf97bfc812b2fae89e8b83329c0 Mon Sep 17 00:00:00 2001 From: Mahmoud Saada Date: Wed, 22 Apr 2020 15:54:21 -0400 Subject: [PATCH] add tests and update docs --- examples/05-advanced-nodegroups.yaml | 7 +- pkg/cfn/builder/api_test.go | 35 +++++++- pkg/cfn/builder/nodegroup_test.go | 92 -------------------- site/content/usage/02-managing-nodegroups.md | 5 ++ site/content/usage/15-eks-managed-nodes.md | 1 + 5 files changed, 46 insertions(+), 94 deletions(-) delete mode 100644 pkg/cfn/builder/nodegroup_test.go diff --git a/examples/05-advanced-nodegroups.yaml b/examples/05-advanced-nodegroups.yaml index d84e9b1806b..0fb03d8632c 100644 --- a/examples/05-advanced-nodegroups.yaml +++ b/examples/05-advanced-nodegroups.yaml @@ -1,5 +1,5 @@ # An advanced example of ClusterConfig object with customised nodegroups: ---- +--- apiVersion: eksctl.io/v1alpha5 kind: ClusterConfig @@ -42,6 +42,11 @@ nodeGroups: nodegroup-type: very-special-science-workloads classicLoadBalancerNames: - ng3-classic-load-balancer + asgMetricsCollection: + - granularity: 1Minute + metrics: + - GroupMinSize + - GroupMaxSize taints: special: "true:NoSchedule" privateNetworking: true diff --git a/pkg/cfn/builder/api_test.go b/pkg/cfn/builder/api_test.go index 8c73141220e..081d9e5a840 100644 --- a/pkg/cfn/builder/api_test.go +++ b/pkg/cfn/builder/api_test.go @@ -70,6 +70,7 @@ type Properties struct { VPCZoneIdentifier interface{} LoadBalancerNames []string + MetricsCollection []interface{} TargetGroupARNs []string DesiredCapacity, MinSize, MaxSize string @@ -771,7 +772,15 @@ var _ = Describe("CloudFormation template builder API", func() { Context("NodeGroupAutoScaling", func() { cfg, ng := newClusterConfigAndNodegroup(true) - + ng.ASGMetricsCollection = []api.MetricsCollection{ + { + Granularity: "1Minute", + Metrics: []string{ + "GroupMinSize", + "GroupMaxSize", + }, + }, + } ng.ClassicLoadBalancerNames = []string{"clb-1", "clb-2"} ng.TargetGroupARNs = []string{"tg-arn-1", "tg-arn-2"} @@ -876,6 +885,30 @@ var _ = Describe("CloudFormation template builder API", func() { Expect(ng.Properties.LoadBalancerNames).To(Equal([]string{"clb-1", "clb-2"})) }) + It("should have metrics collections set", func() { + Expect(ngTemplate.Resources).To(HaveKey("NodeGroup")) + ng := ngTemplate.Resources["NodeGroup"] + Expect(ng).ToNot(BeNil()) + Expect(ng.Properties).ToNot(BeNil()) + + Expect(ng.Properties.MetricsCollection).ToNot(BeEmpty()) + var metricsCollection map[string]interface{} = ng.Properties.MetricsCollection[0].(map[string]interface{}) + // Expect(ng.Properties.MetricsCollection[0].(interface{})).To(HaveKeyWithValue("granularity", "1Minute")) + Expect(metricsCollection).To(HaveKey("granularity")) + Expect(metricsCollection).To(HaveKey("metrics")) + Expect(metricsCollection["granularity"]).To(Equal("1Minute")) + Expect(metricsCollection["metrics"]).To(ContainElement("GroupMinSize")) + Expect(metricsCollection["metrics"]).To(ContainElement("GroupMaxSize")) + + // To(Equal(map[string]interface{}{ + // granularity: "1Minute", + // metrics: []string{"GroupMinSize", "GroupMaxSize"}, + // })) + + // Expect(ng.Properties.MetricsCollection[0].(interface{})). + // To(HaveKeyWithValue("metrics", []string{"GroupMinSize", "GroupMaxSize"})) + }) + It("should have target groups ARNs set", func() { Expect(ngTemplate.Resources).To(HaveKey("NodeGroup")) ng := ngTemplate.Resources["NodeGroup"] diff --git a/pkg/cfn/builder/nodegroup_test.go b/pkg/cfn/builder/nodegroup_test.go deleted file mode 100644 index ea17b52c620..00000000000 --- a/pkg/cfn/builder/nodegroup_test.go +++ /dev/null @@ -1,92 +0,0 @@ -package builder - -import ( - "fmt" - "testing" - - "github.com/awslabs/goformation/v4" - "github.com/stretchr/testify/assert" - api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5" -) - - -newClusterConfig := func(clusterName string) *api.ClusterConfig { - cfg := api.NewClusterConfig() - - cfg.Metadata.Region = "us-west-2" - cfg.Metadata.Name = clusterName - cfg.AvailabilityZones = testAZs - - *cfg.VPC.CIDR = api.DefaultCIDR() - - return cfg -} - -func TestMetricsEnabledASG(t *testing.T) { - - ng := cfg.NewNodeGroup() - ng.InstanceType = "t2.medium" - ng.AMIFamily = "AmazonLinux2" - ng.ASGMetricsCollection = []api.MetricsCollection{ - { - Granularity: "1Minute", - Metrics: []string{ - "GroupMinSize", - "GroupMaxSize", - }, - }, - } -} - -func TestManagedNodeRole(t *testing.T) { - nodeRoleTests := []struct { - description string - nodeGroup *api.ManagedNodeGroup - expectedNewRole bool - expectedNodeRoleARN string - }{ - { - description: "InstanceRoleARN is not provided", - nodeGroup: &api.ManagedNodeGroup{ - ScalingConfig: &api.ScalingConfig{}, - SSH: &api.NodeGroupSSH{ - Allow: api.Disabled(), - }, - IAM: &api.NodeGroupIAM{}, - }, - expectedNewRole: true, - expectedNodeRoleARN: fmt.Sprintf("\"Fn::GetAtt\":\"%s.Arn\"", cfnIAMInstanceRoleName), // creating new role - }, - { - description: "InstanceRoleARN is provided", - nodeGroup: &api.ManagedNodeGroup{ - ScalingConfig: &api.ScalingConfig{}, - SSH: &api.NodeGroupSSH{ - Allow: api.Disabled(), - }, - IAM: &api.NodeGroupIAM{ - InstanceRoleARN: "arn::DUMMY::DUMMYROLE", - }, - }, - expectedNewRole: false, - expectedNodeRoleARN: "arn::DUMMY::DUMMYROLE", // using the provided role - }, - } - - for i, tt := range nodeRoleTests { - t.Run(fmt.Sprintf("%d: %s", i, tt.description), func(t *testing.T) { - stack := NewManagedNodeGroup(api.NewClusterConfig(), tt.nodeGroup, "iam-test") - err := stack.AddAllResources() - assert.NoError(t, err) - - bytes, err := stack.RenderJSON() - assert.NoError(t, err) - - template, err := goformation.ParseJSON(bytes) - assert.Contains(t, string(bytes), tt.expectedNodeRoleARN) - assert.NoError(t, err) - _, ok := template.GetAllIAMRoleResources()[cfnIAMInstanceRoleName] - assert.Equal(t, tt.expectedNewRole, ok) - }) - } -} diff --git a/site/content/usage/02-managing-nodegroups.md b/site/content/usage/02-managing-nodegroups.md index 99284cc7ffa..8470cf53b65 100644 --- a/site/content/usage/02-managing-nodegroups.md +++ b/site/content/usage/02-managing-nodegroups.md @@ -82,6 +82,11 @@ nodeGroups: classicLoadBalancerNames: - dev-clb-1 - dev-clb-2 + asgMetricsCollection: + - granularity: 1Minute + metrics: + - GroupMinSize + - GroupMaxSize - name: ng-2-api labels: { role: api } instanceType: m5.2xlarge diff --git a/site/content/usage/15-eks-managed-nodes.md b/site/content/usage/15-eks-managed-nodes.md index 50f80fad865..1e7be41c33e 100644 --- a/site/content/usage/15-eks-managed-nodes.md +++ b/site/content/usage/15-eks-managed-nodes.md @@ -185,6 +185,7 @@ the provisioned Autoscaling Group like in unmanaged nodegroups. - Control over the node bootstrapping process and customization of the kubelet are not supported. This includes the following fields: `classicLoadBalancerNames`, `maxPodsPerNode`, `taints`, `targetGroupARNs`, `preBootstrapCommands`, `overrideBootstrapCommand`, `clusterDNS` and `kubeletExtraConfig`. +- No support for enabling metrics on AutoScalingGroups using `asgMetricsCollection` ### Note for eksctl versions below 0.12.0 - For clusters upgraded from EKS 1.13 to EKS 1.14, managed nodegroups will not be able to communicate with unmanaged