diff --git a/integration/tests/unowned_cluster/unowned_cluster_test.go b/integration/tests/unowned_cluster/unowned_cluster_test.go index 7f876529f5..3c5e209283 100644 --- a/integration/tests/unowned_cluster/unowned_cluster_test.go +++ b/integration/tests/unowned_cluster/unowned_cluster_test.go @@ -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" @@ -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()) + }) } }) @@ -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, @@ -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 }