From 197cfbd12d696bb2bc4ed313d4fa5d7e0acd92b0 Mon Sep 17 00:00:00 2001 From: Jason Deal Date: Wed, 3 Jul 2024 09:46:24 -0700 Subject: [PATCH] drop: rudimentary v1beta1 API support --- pkg/apis/v1beta1/ec2nodeclass.go | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkg/apis/v1beta1/ec2nodeclass.go b/pkg/apis/v1beta1/ec2nodeclass.go index b3395dd3a60d..5a660ff10b00 100644 --- a/pkg/apis/v1beta1/ec2nodeclass.go +++ b/pkg/apis/v1beta1/ec2nodeclass.go @@ -16,7 +16,9 @@ package v1beta1 import ( "fmt" + "strings" + "github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1" "github.com/mitchellh/hashstructure/v2" "github.com/samber/lo" "k8s.io/apimachinery/pkg/api/resource" @@ -155,6 +157,8 @@ type SecurityGroupSelectorTerm struct { // AMISelectorTerm defines selection logic for an ami used by Karpenter to launch nodes. // If multiple fields are used for selection, the requirements are ANDed. type AMISelectorTerm struct { + // +optional + Alias string `json:"alias,omitempty"` // Tags is a map of key/value tags used to select subnets // Specifying '*' for a value selects all values for a given tag key. // +kubebuilder:validation:XValidation:message="empty tag keys or values aren't supported",rule="self.all(k, k != '' && self[k] != '')" @@ -362,6 +366,35 @@ func (in *EC2NodeClass) InstanceProfileTags(clusterName string) map[string]strin }) } +func (in *EC2NodeClass) AMIFamily() string { + if term, ok := lo.Find(in.Spec.AMISelectorTerms, func(t AMISelectorTerm) bool { + return t.Alias != "" + }); ok { + switch strings.Split(term.Alias, "@")[0] { + case "al2": + return AMIFamilyAL2 + case "al2023": + return AMIFamilyAL2023 + case "bottlerocket": + return AMIFamilyBottlerocket + case "windows2019": + return AMIFamilyWindows2019 + case "windows2022": + return AMIFamilyWindows2022 + } + } + return AMIFamilyCustom +} + +func (in *EC2NodeClass) AMIVersion() string { + if term, ok := lo.Find(in.Spec.AMISelectorTerms, func(t AMISelectorTerm) bool { + return t.Alias != "" + }); ok { + return strings.Split(term.Alias, "@")[1] + } + return "" +} + // EC2NodeClassList contains a list of EC2NodeClass // +kubebuilder:object:root=true type EC2NodeClassList struct {