Skip to content

Commit

Permalink
Merge branch 'main' into new-unit
Browse files Browse the repository at this point in the history
  • Loading branch information
weicongw authored Aug 30, 2024
2 parents c03d0ed + 0b6bbd8 commit 9b7b5f4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 19 deletions.
8 changes: 6 additions & 2 deletions kubetest2/internal/deployers/eksapi/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (m *NodegroupManager) createManagedNodegroup(infra *Infrastructure, cluster
func (m *NodegroupManager) createUnmanagedNodegroup(infra *Infrastructure, cluster *Cluster, opts *deployerOptions) error {
stackName := m.getUnmanagedNodegroupStackName()
klog.Infof("creating unmanaged nodegroup stack...")
userData, userDataIsMimePart, err := generateUserData(opts.UserDataFormat, cluster)
userData, userDataIsMimePart, err := generateUserData(opts.UserDataFormat, opts.EFA, cluster)
if err != nil {
return err
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func (m *NodegroupManager) createUnmanagedNodegroup(infra *Infrastructure, clust
func (m *NodegroupManager) createUnmanagedNodegroupWithEFA(infra *Infrastructure, cluster *Cluster, opts *deployerOptions) error {
stackName := m.getUnmanagedNodegroupStackName()
klog.Infof("creating unmanaged nodegroup with EFA stack...")
userData, _, err := generateUserData(opts.UserDataFormat, cluster)
userData, userDataIsMimePart, err := generateUserData(opts.UserDataFormat, opts.EFA, cluster)
if err != nil {
return err
}
Expand Down Expand Up @@ -283,6 +283,10 @@ func (m *NodegroupManager) createUnmanagedNodegroupWithEFA(infra *Infrastructure
ParameterKey: aws.String("UserData"),
ParameterValue: aws.String(userData),
},
{
ParameterKey: aws.String("UserDataIsMIMEPart"),
ParameterValue: aws.String(strconv.FormatBool(userDataIsMimePart)),
},
{
ParameterKey: aws.String("ClusterName"),
ParameterValue: aws.String(cluster.name),
Expand Down
1 change: 1 addition & 0 deletions kubetest2/internal/deployers/eksapi/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type UserDataTemplateData struct {
CertificateAuthority string
CIDR string
APIServerEndpoint string
EFAEnabled bool
}

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ Parameters:
Type: String
Description: Capacity reservation id for the unmanaged nodegroup

UserDataIsMIMEPart:
Description: "User data should be embedded as a part of a multi-part MIME document"
Default: true
Type: String
AllowedValues: [true, false]

InstanceType:
Type: String
Description: Efa supports only one instance type in the cluster. eg. p3dn.24xlarge, p4d.24xlarge or p5.48xlarge
Expand All @@ -57,6 +63,8 @@ Conditions:
!Equals [Ref: InstanceType, p5.48xlarge]
IsCapacityReservationIdSet:
!Not [!Equals [!Ref CapacityReservationId, ""]]
IsUserDataMIMEPart:
!Equals [true, !Ref UserDataIsMIMEPart]

Resources:
EFASecurityGroup:
Expand Down Expand Up @@ -305,24 +313,28 @@ Resources:
- !Ref EFASecurityGroup
UserData:
Fn::Base64:
Fn::Sub: |
Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0
Fn::If:
- IsUserDataMIMEPart
- Fn::Sub: |
Content-Type: multipart/mixed; boundary="BOUNDARY"
MIME-Version: 1.0

--BOUNDARY
${UserData}
--BOUNDARY
${UserData}

--BOUNDARY
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
--BOUNDARY
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0

#!/usr/bin/env bash
/opt/aws/bin/cfn-signal \
--stack ${AWS::StackName} \
--resource NodeGroup \
--region ${AWS::Region}
#!/usr/bin/env bash
/opt/aws/bin/cfn-signal \
--stack ${AWS::StackName} \
--resource NodeGroup \
--region ${AWS::Region}

--BOUNDARY--
--BOUNDARY--
- Fn::Sub: |
${UserData}

NodeGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@

[settings.host-containers.admin]
"enabled" = true

[settings.efa]
"enabled" = {{.EFAEnabled}}
3 changes: 2 additions & 1 deletion kubetest2/internal/deployers/eksapi/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/aws/aws-k8s-tester/kubetest2/internal/deployers/eksapi/templates"
)

func generateUserData(format string, cluster *Cluster) (string, bool, error) {
func generateUserData(format string, efaEnabled bool, cluster *Cluster) (string, bool, error) {
userDataIsMimePart := true
var t *template.Template
switch format {
Expand All @@ -29,6 +29,7 @@ func generateUserData(format string, cluster *Cluster) (string, bool, error) {
CertificateAuthority: cluster.certificateAuthorityData,
CIDR: cluster.cidr,
Name: cluster.name,
EFAEnabled: efaEnabled,
}); err != nil {
return "", false, err
}
Expand Down
24 changes: 22 additions & 2 deletions kubetest2/internal/deployers/eksapi/userdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,49 @@ spec:
name: cluster
apiServerEndpoint: https://example.com
certificateAuthority: certificateAuthority
cidr: 10.100.0.0/16
cidr: 10.100.0.0/16
`
const bottlerocketUserData = `[settings.kubernetes]
"cluster-name" = "cluster"
"api-server" = "https://example.com"
"cluster-certificate" = "certificateAuthority"
[settings.host-containers.admin]
"enabled" = true
[settings.efa]
"enabled" = true
`

func Test_generateUserData(t *testing.T) {
cases := []struct {
format string
efa bool
expected string
expectedIsMimePart bool
}{
{
format: "bootstrap.sh",
efa: false,
expected: bootstrapShUserData,
expectedIsMimePart: true,
},
{
format: "nodeadm",
efa: false,
expected: nodeadmUserData,
expectedIsMimePart: true,
},
{
format: "bottlerocket",
efa: true,
expected: bottlerocketUserData,
expectedIsMimePart: false,
},
}
for _, c := range cases {
t.Run(c.format, func(t *testing.T) {
actual, isMimePart, err := generateUserData(c.format, &cluster)
actual, isMimePart, err := generateUserData(c.format, c.efa, &cluster)
if err != nil {
t.Log(err)
t.Error(err)
Expand Down

0 comments on commit 9b7b5f4

Please sign in to comment.