Skip to content

Commit

Permalink
Merge pull request #7722 from cPu1/disable-imds-v1
Browse files Browse the repository at this point in the history
Disable IMDSv1 in unowned integration tests
  • Loading branch information
cPu1 authored Apr 24, 2024
2 parents 5cab628 + 5a63580 commit d35fa56
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions integration/tests/unowned_cluster/unowned_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"testing"
"time"

"github.com/aws/aws-sdk-go-v2/service/ec2"
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"

"github.com/aws/aws-sdk-go-v2/aws"
cfn "github.com/aws/aws-sdk-go-v2/service/cloudformation"
"github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
"github.com/aws/aws-sdk-go-v2/service/ec2"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
awseks "github.com/aws/aws-sdk-go-v2/service/eks"
ekstypes "github.com/aws/aws-sdk-go-v2/service/eks/types"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -74,7 +74,15 @@ var _ = BeforeSuite(func() {
clusterProvider, err := eks.New(context.Background(), &api.ProviderConfig{Region: params.Region}, cfg)
Expect(err).NotTo(HaveOccurred())
ctl = clusterProvider.AWSProvider
cfg.VPC = createClusterWithNodeGroup(context.Background(), params.ClusterName, stackName, mng1, version, ctl)
ctx := context.Background()
cfg.VPC = createClusterWithNodeGroup(ctx, params.ClusterName, stackName, mng1, version, ctl)
DeferCleanup(func() {
By(fmt.Sprintf("deleting launch template: %s", params.ClusterName))
_, err := ctl.EC2().DeleteLaunchTemplate(ctx, &ec2.DeleteLaunchTemplateInput{
LaunchTemplateName: aws.String(params.ClusterName),
})
Expect(err).NotTo(HaveOccurred())
})
}
})

Expand Down Expand Up @@ -412,6 +420,17 @@ func createClusterWithNodeGroup(ctx context.Context, clusterName, stackName, ng1
},
}

launchTemplate, err := ctl.EC2().CreateLaunchTemplate(ctx, &ec2.CreateLaunchTemplateInput{
LaunchTemplateData: &ec2types.RequestLaunchTemplateData{
MetadataOptions: &ec2types.LaunchTemplateInstanceMetadataOptionsRequest{
HttpPutResponseHopLimit: aws.Int32(1),
HttpTokens: ec2types.LaunchTemplateHttpTokensStateRequired,
},
},
LaunchTemplateName: aws.String(params.ClusterName),
})
Expect(err).NotTo(HaveOccurred())

_, err = ctl.EKS().CreateNodegroup(ctx, &awseks.CreateNodegroupInput{
NodegroupName: &ng1,
ClusterName: &clusterName,
Expand All @@ -422,16 +441,16 @@ func createClusterWithNodeGroup(ctx context.Context, clusterName, stackName, ng1
DesiredSize: aws.Int32(1),
MinSize: aws.Int32(1),
},
LaunchTemplate: &ekstypes.LaunchTemplateSpecification{
Id: launchTemplate.LaunchTemplate.LaunchTemplateId,
},
})
Expect(err).NotTo(HaveOccurred())
Eventually(func() string {
out, err := ctl.EKS().DescribeNodegroup(ctx, &awseks.DescribeNodegroupInput{
ClusterName: &clusterName,
NodegroupName: &ng1,
})
Expect(err).NotTo(HaveOccurred())
return string(out.Nodegroup.Status)
}, timeoutDuration, time.Second*30).Should(Equal("ACTIVE"))
waiter := awseks.NewNodegroupActiveWaiter(ctl.EKS())
Expect(waiter.Wait(ctx, &awseks.DescribeNodegroupInput{
ClusterName: &clusterName,
NodegroupName: &ng1,
}, timeoutDuration)).To(Succeed())

return newVPC
}
Expand Down

0 comments on commit d35fa56

Please sign in to comment.