diff --git a/pkg/cfn/builder/api_test.go b/pkg/cfn/builder/api_test.go index 7d25228879..d926d8eb85 100644 --- a/pkg/cfn/builder/api_test.go +++ b/pkg/cfn/builder/api_test.go @@ -3007,6 +3007,24 @@ var _ = Describe("CloudFormation template builder API", func() { HaveKeyWithValue("SuspendProcesses", []interface{}{"Launch", "InstanceRefresh"}), ) }) + Context("empty asgSuspendProcesses", func() { + cfg, ng := newClusterConfigAndNodegroup(true) + + ng.ASGSuspendProcesses = []string{} + build(cfg, "eksctl-test-asgSuspendProcesses-empty", ng) + + roundtrip() + + It("shouldn't be included in resource", func() { + Expect(ngTemplate.Resources).To(HaveKey("NodeGroup")) + ngResource := ngTemplate.Resources["NodeGroup"] + Expect(ng).ToNot(BeNil()) + Expect(ngResource.UpdatePolicy).To(HaveKey("AutoScalingRollingUpdate")) + Expect(ngResource.UpdatePolicy["AutoScalingRollingUpdate"]).ToNot( + HaveKey("SuspendProcesses"), + ) + }) + }) }) }) diff --git a/pkg/cfn/builder/nodegroup.go b/pkg/cfn/builder/nodegroup.go index e5798524d2..8147588d5a 100644 --- a/pkg/cfn/builder/nodegroup.go +++ b/pkg/cfn/builder/nodegroup.go @@ -326,15 +326,19 @@ func nodeGroupResource(launchTemplateName *gfnt.Value, vpcZoneIdentifier interfa } } + rollingUpdate := map[string]interface{}{ + "MinInstancesInService": "0", + "MaxBatchSize": "1", + } + if len(ng.ASGSuspendProcesses) > 0 { + rollingUpdate["SuspendProcesses"] = ng.ASGSuspendProcesses + } + return &awsCloudFormationResource{ Type: "AWS::AutoScaling::AutoScalingGroup", Properties: ngProps, UpdatePolicy: map[string]map[string]interface{}{ - "AutoScalingRollingUpdate": { - "MinInstancesInService": "0", - "MaxBatchSize": "1", - "SuspendProcesses": ng.ASGSuspendProcesses, - }, + "AutoScalingRollingUpdate": rollingUpdate, }, } }