Skip to content

Commit

Permalink
drop: rudimentary v1beta1 API support
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdeal committed Jul 3, 2024
1 parent c57c1cf commit 197cfbd
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions pkg/apis/v1beta1/ec2nodeclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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] != '')"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 197cfbd

Please sign in to comment.