Skip to content

Commit 01d10ba

Browse files
authored
*: prefer SSM param over AMI ID, do not include "SSM:Parameter" in CFN (#187)
* *: prefer SSM param over AMI ID, do not include "SSM:Parameter" in CFN if empty Signed-off-by: Gyuho Lee <[email protected]> * *: add CHANGELOG, update AWS SDK Go Signed-off-by: Gyuho Lee <[email protected]>
1 parent cbc2bde commit 01d10ba

File tree

10 files changed

+99
-33
lines changed

10 files changed

+99
-33
lines changed

CHANGELOG/CHANGELOG-1.5.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@
33
<hr>
44

55

6+
## [v1.5.5](https://github.com/aws/aws-k8s-tester/releases/tag/v1.5.5) (2020-11-12)
7+
8+
See [code changes](https://github.com/aws/aws-k8s-tester/compare/v1.5.4...v1.5.5).
9+
10+
### `ec2config`
11+
12+
- Overwrite [ASG AMI ID if SSM parameter is specified](https://github.com/aws/aws-k8s-tester/pull/187).
13+
14+
### `eksconfig`
15+
16+
- Overwrite [node group AMI ID if SSM parameter is specified](https://github.com/aws/aws-k8s-tester/pull/187).
17+
18+
### `eks`
19+
20+
- Do [not include `AWS::SSM::Parameter` in node group CFN template if the parameter is empty](https://github.com/aws/aws-k8s-tester/pull/187).
21+
- Skip [deleting CMK, VPC, IAM role if EKS cluster delete fails](https://github.com/aws/aws-k8s-tester/pull/186).
22+
23+
### Dependency
24+
25+
- Upgrade [`github.com/aws/aws-sdk-go`](https://github.com/aws/aws-sdk-go/releases) from [`v1.35.25`](https://github.com/aws/aws-sdk-go/releases/tag/v1.35.25) to [`v1.35.27`](https://github.com/aws/aws-sdk-go/releases/tag/v1.35.27).
26+
27+
### Go
28+
29+
- Compile with [*Go 1.15.5*](https://golang.org/doc/devel/release.html#go1.15).
30+
31+
32+
<hr>
33+
34+
635
## [v1.5.4](https://github.com/aws/aws-k8s-tester/releases/tag/v1.5.4) (2020-11-11)
736

837
See [code changes](https://github.com/aws/aws-k8s-tester/compare/v1.5.3...v1.5.4).

ec2config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ type ASG struct {
278278
AMIType string `json:"ami-type,omitempty"`
279279
// ImageID is the Amazon Machine Image (AMI).
280280
// This value overrides any AWS Systems Manager Parameter Store value.
281+
// NOTE: THIS FIELD IS SET TO EMPTY IF "ImageIDSSMParameter" IS NOT EMPTY.
281282
ImageID string `json:"image-id"`
282283
// ImageIDSSMParameter is the AWS Systems Manager Parameter Store
283284
// parameter of the AMI ID.

ec2config/validate-defaults.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ func (cfg *Config) validateASGs() error {
379379
if cur.ImageID == "" && cur.ImageIDSSMParameter == "" {
380380
return fmt.Errorf("%q both ImageID and ImageIDSSMParameter are empty", cur.Name)
381381
}
382+
// prefer "ImageIDSSMParameter"
383+
if cur.ImageID != "" && cur.ImageIDSSMParameter != "" {
384+
cur.ImageID = ""
385+
}
382386

383387
switch cur.AMIType {
384388
case AMITypeBottleRocketCPU:

eks/ng/nodes.go

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,41 @@ e.g.
3333
aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2
3434
3535
e.g.
36-
aws ssm get-parameters --names /aws/service/eks/optimized-ami/1.16/amazon-linux-2/recommended/image_id
37-
aws ssm get-parameters --names /aws/service/bottlerocket/aws-k8s-1.16/x86_64/latest/image_id
36+
aws ssm get-parameters --names /aws/service/eks/optimized-ami/1.18/amazon-linux-2/recommended/image_id
37+
aws ssm get-parameters --names /aws/service/bottlerocket/aws-k8s-1.18/x86_64/latest/image_id
3838
3939
TODO
4040
4141
BootstrapArguments:
4242
Type: String
4343
Description: Arguments to pass to the bootstrap script. See files/bootstrap.sh in https://github.com/awslabs/amazon-eks-ami
44+
45+
46+
NOTE for new regions
47+
"AWS::SSM::Parameter" may not be onboarded yet, so we need templatize CFN template
48+
so that we do not pass invalid "AWS::SSM::Parameter" at all in those regions
49+
50+
ImageID:
51+
Type: String
52+
Default: ""
53+
Description: (Optional) Specify your own custom image ID. This value overrides any AWS Systems Manager Parameter Store value specified above.
54+
55+
ImageIDSSMParameter:
56+
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
57+
Default: /aws/service/eks/optimized-ami/1.18/amazon-linux-2/recommended/image_id
58+
Description: AWS Systems Manager Parameter Store parameter of the AMI ID for the worker node instances.
59+
60+
HasImageID:
61+
Fn::Not:
62+
- Fn::Equals:
63+
- Ref: ImageID
64+
- ""
65+
66+
ImageId:
67+
Fn::If:
68+
- HasImageID
69+
- !Ref ImageID
70+
- !Ref ImageIDSSMParameter
4471
*/
4572

4673
// TemplateASG is the CloudFormation template for EKS node group.
@@ -83,15 +110,13 @@ Parameters:
83110
Type: AWS::EC2::KeyPair::KeyName
84111
Description: The EC2 Key Pair to allow SSH access to the instances
85112
86-
ImageID:
113+
{{ if ne .ImageID "" }} ImageID:
87114
Type: String
88115
Default: ""
89-
Description: (Optional) Specify your own custom image ID. This value overrides any AWS Systems Manager Parameter Store value specified above.
90-
91-
ImageIDSSMParameter:
92-
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
93-
Default: /aws/service/eks/optimized-ami/1.15/amazon-linux-2/recommended/image_id
94-
Description: AWS Systems Manager Parameter Store parameter of the AMI ID for the worker node instances.
116+
Description: Specify your own custom image ID. This value overrides any AWS Systems Manager Parameter Store value specified above.{{ end }}{{ if ne .ImageIDSSMParameter "" }} ImageIDSSMParameter:
117+
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
118+
Default: /aws/service/eks/optimized-ami/1.18/amazon-linux-2/recommended/image_id
119+
Description: AWS Systems Manager Parameter Store parameter of the AMI ID for the worker node instances.{{ end }}
95120
96121
InstanceTypes:
97122
Type: CommaDelimitedList
@@ -129,12 +154,6 @@ Parameters:
129154
130155
Conditions:
131156
132-
HasImageID:
133-
Fn::Not:
134-
- Fn::Equals:
135-
- Ref: ImageID
136-
- ""
137-
138157
Has2InstanceTypes:
139158
Fn::Or:
140159
- Fn::Equals:
@@ -181,11 +200,7 @@ Resources:
181200
LaunchTemplateData:
182201
IamInstanceProfile:
183202
Arn: !GetAtt InstanceProfile.Arn
184-
ImageId:
185-
Fn::If:
186-
- HasImageID
187-
- !Ref ImageID
188-
- !Ref ImageIDSSMParameter
203+
{{ if ne .ImageID "" }} ImageId: !Ref ImageID{{ end }}{{ if ne .ImageIDSSMParameter "" }} ImageId: !Ref ImageIDSSMParameter{{ end }}
189204
KeyName: !Ref RemoteAccessKeyName
190205
BlockDeviceMappings:
191206
- DeviceName: /dev/xvda
@@ -374,10 +389,12 @@ const asgTagDataNG = ` - Key: !Sub k8s.io/cluster-autoscaler/${ClusterName}
374389
`
375390

376391
type templateASG struct {
377-
Metadata string
378-
UserData string
379-
ASGDesiredCapacity int64
380-
ASGTagData string
392+
ImageID string
393+
ImageIDSSMParameter string
394+
Metadata string
395+
UserData string
396+
ASGDesiredCapacity int64
397+
ASGTagData string
381398
}
382399

383400
func (ts *tester) createASGs() error {
@@ -400,7 +417,9 @@ func (ts *tester) createASGs() error {
400417
// "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
401418
// already includes SSM agent + AWS CLI
402419
tg := templateASG{
403-
ASGDesiredCapacity: cur.ASGDesiredCapacity,
420+
ImageID: cur.ImageID,
421+
ImageIDSSMParameter: cur.ImageIDSSMParameter,
422+
ASGDesiredCapacity: cur.ASGDesiredCapacity,
404423
}
405424
switch cur.AMIType {
406425
case ec2config.AMITypeBottleRocketCPU:
@@ -517,6 +536,9 @@ func (ts *tester) createASGs() error {
517536
},
518537
},
519538
}
539+
540+
// "eksconfig" validate already ensures that either "ImageID" or "ImageIDSSMParameter" is non-empty
541+
// both cannot be non-empty at the same time!
520542
if cur.ImageID != "" {
521543
ts.cfg.Logger.Info("added image ID", zap.String("image-id", cur.ImageID))
522544
stackInput.Parameters = append(stackInput.Parameters, &cloudformation.Parameter{

eks/ng/nodes_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ng
33
import (
44
"bytes"
55
"fmt"
6+
"strings"
67
"testing"
78
"text/template"
89
)
@@ -17,11 +18,16 @@ func TestTemplateASG(t *testing.T) {
1718

1819
buf.Reset()
1920
if err := tpl.Execute(buf, templateASG{
20-
Metadata: metadataAL2InstallSSM,
21-
UserData: userDataAL2InstallSSM,
22-
ASGDesiredCapacity: 1,
21+
ImageID: "abc",
22+
ImageIDSSMParameter: "",
23+
Metadata: metadataAL2InstallSSM,
24+
UserData: userDataAL2InstallSSM,
25+
ASGDesiredCapacity: 1,
2326
}); err != nil {
2427
t.Fatal(err)
2528
}
2629
fmt.Println(buf.String())
30+
if strings.Contains(buf.String(), "AWS::SSM::Parameter") {
31+
t.Fatal("unexpected AWS::SSM::Parameter in CFN template")
32+
}
2733
}

eksconfig/add-on-node-groups.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,10 @@ func (cfg *Config) validateAddOnNodeGroups() error {
280280
if cur.ImageID == "" && cur.ImageIDSSMParameter == "" {
281281
return fmt.Errorf("%q both ImageID and ImageIDSSMParameter are empty", cur.Name)
282282
}
283+
// prefer "ImageIDSSMParameter"
284+
if cur.ImageID != "" && cur.ImageIDSSMParameter != "" {
285+
cur.ImageID = ""
286+
}
283287

284288
if !cfg.AddOnNodeGroups.RoleCreate {
285289
if cur.ClusterAutoscaler != nil && cur.ClusterAutoscaler.Enable {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ replace (
4343
)
4444

4545
require (
46-
github.com/aws/aws-sdk-go v1.35.25
46+
github.com/aws/aws-sdk-go v1.35.27
4747
github.com/briandowns/spinner v1.11.1
4848
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575
4949
github.com/davecgh/go-spew v1.1.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ github.com/auth0/go-jwt-middleware v0.0.0-20170425171159-5493cabe49f7/go.mod h1:
102102
github.com/aws/aws-sdk-go v1.6.10/go.mod h1:ZRmQr0FajVIyZ4ZzBYKG5P3ZqPz9IHG41ZoMu1ADI3k=
103103
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
104104
github.com/aws/aws-sdk-go v1.28.2/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
105-
github.com/aws/aws-sdk-go v1.35.25 h1:0+UC6ZquMOLvYABoz0olShCAe+M9oKllgPfr2hnv9zE=
106-
github.com/aws/aws-sdk-go v1.35.25/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
105+
github.com/aws/aws-sdk-go v1.35.27 h1:F0dUW+kouzchjt4X6kYfYMw1YtQPkA4pihpCDqQMrq8=
106+
github.com/aws/aws-sdk-go v1.35.27/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
107107
github.com/bazelbuild/bazel-gazelle v0.18.2/go.mod h1:D0ehMSbS+vesFsLGiD6JXu3mVEzOlfUl8wNnq+x/9p0=
108108
github.com/bazelbuild/bazel-gazelle v0.19.1-0.20191105222053-70208cbdc798/go.mod h1:rPwzNHUqEzngx1iVBfO/2X2npKaT3tqPqqHW6rVsn/A=
109109
github.com/bazelbuild/buildtools v0.0.0-20190731111112-f720930ceb60/go.mod h1:5JP0TXzWDHXv8qvxRC4InIazwdyDseBDbzESUMKk1yU=

vendor/github.com/aws/aws-sdk-go/aws/version.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ github.com/andybalholm/brotli
8484
github.com/armon/circbuf
8585
# github.com/asaskevich/govalidator v0.0.0-20200108200545-475eaeb16496
8686
github.com/asaskevich/govalidator
87-
# github.com/aws/aws-sdk-go v1.35.25
87+
# github.com/aws/aws-sdk-go v1.35.27
8888
## explicit
8989
github.com/aws/aws-sdk-go/aws
9090
github.com/aws/aws-sdk-go/aws/arn

0 commit comments

Comments
 (0)