From 43b4f4e4acce47b0bb787cf91a5934acc0da61ac Mon Sep 17 00:00:00 2001 From: Ellis Tarn Date: Thu, 6 Apr 2023 10:23:32 -0700 Subject: [PATCH] fix: No longer include cluster name in launch template name, since the character sets are not compatible (#3701) --- pkg/providers/launchtemplate/launchtemplate.go | 8 ++++---- .../scripts/step16-cleanup.sh | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pkg/providers/launchtemplate/launchtemplate.go b/pkg/providers/launchtemplate/launchtemplate.go index 4cfc386c7366..f585c28d7e38 100644 --- a/pkg/providers/launchtemplate/launchtemplate.go +++ b/pkg/providers/launchtemplate/launchtemplate.go @@ -47,7 +47,7 @@ import ( ) const ( - launchTemplateNameFormat = "Karpenter-%s-%s" + launchTemplateNameFormat = "karpenter.k8s.aws/%s" karpenterManagedTagKey = "karpenter.k8s.aws/cluster" ) @@ -132,7 +132,7 @@ func launchTemplateName(options *amifamily.LaunchTemplate) string { if err != nil { panic(fmt.Sprintf("hashing launch template, %s", err)) } - return fmt.Sprintf(launchTemplateNameFormat, options.ClusterName, fmt.Sprint(hash)) + return fmt.Sprintf(launchTemplateNameFormat, fmt.Sprint(hash)) } func (p *Provider) createAMIOptions(ctx context.Context, machine *v1alpha5.Machine, nodeTemplate *v1alpha1.AWSNodeTemplate, labels map[string]string) (*amifamily.Options, error) { @@ -301,10 +301,10 @@ func (p *Provider) cachedEvictedFunc(ctx context.Context) func(string, interface } launchTemplate := lt.(*ec2.LaunchTemplate) if _, err := p.ec2api.DeleteLaunchTemplate(&ec2.DeleteLaunchTemplateInput{LaunchTemplateId: launchTemplate.LaunchTemplateId}); err != nil { - logging.FromContext(ctx).Errorf("Unable to delete launch template, %v", err) + logging.FromContext(ctx).With("launch-template", launchTemplate.LaunchTemplateName).Errorf("Unable to delete launch template, %v", err) return } - logging.FromContext(ctx).Debugf("deleted launch template") + logging.FromContext(ctx).With("launch-template", launchTemplate.LaunchTemplateName).Debugf("deleted launch template") } } diff --git a/website/content/en/preview/getting-started/getting-started-with-karpenter/scripts/step16-cleanup.sh b/website/content/en/preview/getting-started/getting-started-with-karpenter/scripts/step16-cleanup.sh index 566817606732..959b2e78446d 100755 --- a/website/content/en/preview/getting-started/getting-started-with-karpenter/scripts/step16-cleanup.sh +++ b/website/content/en/preview/getting-started/getting-started-with-karpenter/scripts/step16-cleanup.sh @@ -1,7 +1,6 @@ helm uninstall karpenter --namespace karpenter aws cloudformation delete-stack --stack-name "Karpenter-${CLUSTER_NAME}" -aws ec2 describe-launch-templates \ - | jq -r ".LaunchTemplates[].LaunchTemplateName" \ - | grep -i "Karpenter-${CLUSTER_NAME}" \ - | xargs -I{} aws ec2 delete-launch-template --launch-template-name {} +aws ec2 describe-launch-templates --filters Name=tag:karpenter.k8s.aws/cluster,Values=${CLUSTER_NAME} | + jq -r ".LaunchTemplates[].LaunchTemplateName" | + xargs -I{} aws ec2 delete-launch-template --launch-template-name {} eksctl delete cluster --name "${CLUSTER_NAME}"