From 2266e9d6a297187818881b999b5ed40800e58dc0 Mon Sep 17 00:00:00 2001 From: Joe North Date: Sat, 28 Sep 2024 16:08:50 -0400 Subject: [PATCH] fix: Karpenter 1.0 installation fails when using Bottlerocket (#251) * fix: Add AMI Lookups for Bottlerocket * fix function name spelling for getEKSOptimizedAMI Fixes #249 --------- Co-authored-by: Joe North --- pkg/application/karpenter/options.go | 13 ++++++++++++- pkg/resource/ssm/parameter/ami_lookup.go | 24 +++++++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/pkg/application/karpenter/options.go b/pkg/application/karpenter/options.go index e0e457e..8a4219b 100644 --- a/pkg/application/karpenter/options.go +++ b/pkg/application/karpenter/options.go @@ -83,7 +83,18 @@ func newOptions() (options *KarpenterOptions, flags cmd.Flags) { } if strings.EqualFold(options.AMIFamily, "Bottlerocket") { options.AMIFamily = "Bottlerocket" - return nil + + bottlerocketAMI, err := ssm.GetBottlerocketAMI(eksVersion) + if err != nil { + return err + } + + bottlerocketArm64AMI, err := ssm.GetBottlerocketArm64AMI(eksVersion) + if err != nil { + return err + } + + options.AMISelectorIDs = append(options.AMISelectorIDs, bottlerocketAMI, bottlerocketArm64AMI) } return nil }, diff --git a/pkg/resource/ssm/parameter/ami_lookup.go b/pkg/resource/ssm/parameter/ami_lookup.go index 23c3acf..816dc83 100644 --- a/pkg/resource/ssm/parameter/ami_lookup.go +++ b/pkg/resource/ssm/parameter/ami_lookup.go @@ -18,23 +18,37 @@ const eksAL2023AMI = "/aws/service/eks/optimized-ami/%s/amazon-linux-2023/x86_64 // /aws/service/eks/optimized-ami//amazon-linux-2023/arm64/standard/recommended/image_id const eksAL2023Arm64AMI = "/aws/service/eks/optimized-ami/%s/amazon-linux-2023/arm64/standard/recommended/image_id" +// /aws/service/bottlerocket/aws-k8s-/x86_64/latest/image_id +const bottlerocketAMI = "/aws/service/bottlerocket/aws-k8s-%s/x86_64/latest/image_id" + +// /aws/service/bottlerocket/aws-k8s-/arm64/latest/image_id +const bottlerocketArm64AMI = "/aws/service/bottlerocket/aws-k8s-%s/arm64/latest/image_id" + func (g *Getter) GetEKSOptimizedAL2AMI(eksVersion string) (string, error) { - return g.getEKSOptmizedAMI(eksAL2AMI, eksVersion) + return g.getEKSOptimizedAMI(eksAL2AMI, eksVersion) } func (g *Getter) GetEKSOptimizedAL2Arm64AMI(eksVersion string) (string, error) { - return g.getEKSOptmizedAMI(eksAL2Arm64AMI, eksVersion) + return g.getEKSOptimizedAMI(eksAL2Arm64AMI, eksVersion) } func (g *Getter) GetEKSOptimizedAL2023AMI(eksVersion string) (string, error) { - return g.getEKSOptmizedAMI(eksAL2023AMI, eksVersion) + return g.getEKSOptimizedAMI(eksAL2023AMI, eksVersion) } func (g *Getter) GetEKSOptimizedAL2023Arm64AMI(eksVersion string) (string, error) { - return g.getEKSOptmizedAMI(eksAL2023Arm64AMI, eksVersion) + return g.getEKSOptimizedAMI(eksAL2023Arm64AMI, eksVersion) +} + +func (g *Getter) GetBottlerocketAMI(eksVersion string) (string, error) { + return g.getEKSOptimizedAMI(bottlerocketAMI, eksVersion) +} + +func (g *Getter) GetBottlerocketArm64AMI(eksVersion string) (string, error) { + return g.getEKSOptimizedAMI(bottlerocketArm64AMI, eksVersion) } -func (g *Getter) getEKSOptmizedAMI(paramName, eksVersion string) (string, error) { +func (g *Getter) getEKSOptimizedAMI(paramName, eksVersion string) (string, error) { param, err := g.ssmClient.GetParameter(fmt.Sprintf(paramName, eksVersion)) if err != nil { return "", err