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 3a24521bfb0..501694f253a 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/userdocs/src/usage/eks-managed-nodes.md b/userdocs/src/usage/eks-managed-nodes.md index 5e5b1db4009..1f2dd8d67a9 100644 --- a/userdocs/src/usage/eks-managed-nodes.md +++ b/userdocs/src/usage/eks-managed-nodes.md @@ -179,6 +179,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 diff --git a/userdocs/src/usage/managing-nodegroups.md b/userdocs/src/usage/managing-nodegroups.md index 72810d4d5bd..7ed295848a1 100644 --- a/userdocs/src/usage/managing-nodegroups.md +++ b/userdocs/src/usage/managing-nodegroups.md @@ -76,6 +76,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