Skip to content

Commit

Permalink
chore: migrate to v1 APIs (#6502)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick Tran <nichotr@amazon.com>
  • Loading branch information
jmdeal and njtran committed Jul 12, 2024
1 parent 5baf0d7 commit c32ccc4
Show file tree
Hide file tree
Showing 126 changed files with 3,977 additions and 3,865 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
k8s.io/utils v0.0.0-20240102154912-e7106e64919e
knative.dev/pkg v0.0.0-20231010144348-ca8c009405dd
sigs.k8s.io/controller-runtime v0.18.4
sigs.k8s.io/karpenter v0.37.1-0.20240710172318-86056e48b9ac
sigs.k8s.io/karpenter v0.37.1-0.20240711192037-195f8961cae4
sigs.k8s.io/yaml v1.4.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -761,8 +761,8 @@ sigs.k8s.io/controller-runtime v0.18.4 h1:87+guW1zhvuPLh1PHybKdYFLU0YJp4FhJRmiHv
sigs.k8s.io/controller-runtime v0.18.4/go.mod h1:TVoGrfdpbA9VRFaRnKgk9P5/atA0pMwq+f+msb9M8Sg=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/karpenter v0.37.1-0.20240710172318-86056e48b9ac h1:8nfNoKGJSAzTMKxweI4DcTADPyMY/oCW2x1qgx3gUVY=
sigs.k8s.io/karpenter v0.37.1-0.20240710172318-86056e48b9ac/go.mod h1:jwEZ2Efxsc0yyNkrDEFN2RduAwlm/s7reIVNblZ8vyM=
sigs.k8s.io/karpenter v0.37.1-0.20240711192037-195f8961cae4 h1:PfXPyel4nqHFf/3fMQ0TSP+gUZTyyrjSjBDjhp7IRjQ=
sigs.k8s.io/karpenter v0.37.1-0.20240711192037-195f8961cae4/go.mod h1:jwEZ2Efxsc0yyNkrDEFN2RduAwlm/s7reIVNblZ8vyM=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4=
sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
Expand Down
32 changes: 16 additions & 16 deletions hack/docs/instancetypes_gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ import (

"github.com/aws/aws-sdk-go/service/ec2"
"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/manager"
corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"
karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1"

coreoperator "sigs.k8s.io/karpenter/pkg/operator"
coreoptions "sigs.k8s.io/karpenter/pkg/operator/options"
coretest "sigs.k8s.io/karpenter/pkg/test"

"github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"
v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1"
"github.com/aws/karpenter-provider-aws/pkg/operator"
"github.com/aws/karpenter-provider-aws/pkg/operator/options"
"github.com/aws/karpenter-provider-aws/pkg/test"
Expand Down Expand Up @@ -103,10 +103,10 @@ func main() {
log.Fatalf("updating instance types offerings, %s", err)
}
// Fake a NodeClass so we can use it to get InstanceTypes
nodeClass := &v1beta1.EC2NodeClass{
Spec: v1beta1.EC2NodeClassSpec{
AMIFamily: &v1beta1.AMIFamilyAL2023,
SubnetSelectorTerms: []v1beta1.SubnetSelectorTerm{
nodeClass := &v1.EC2NodeClass{
Spec: v1.EC2NodeClassSpec{
AMIFamily: &v1.AMIFamilyAL2023,
SubnetSelectorTerms: []v1.SubnetSelectorTerm{
{
Tags: map[string]string{
"*": "*",
Expand All @@ -119,13 +119,13 @@ func main() {
if err != nil {
log.Fatalf("listing subnets, %s", err)
}
nodeClass.Status.Subnets = lo.Map(subnets, func(ec2subnet *ec2.Subnet, _ int) v1beta1.Subnet {
return v1beta1.Subnet{
nodeClass.Status.Subnets = lo.Map(subnets, func(ec2subnet *ec2.Subnet, _ int) v1.Subnet {
return v1.Subnet{
ID: *ec2subnet.SubnetId,
Zone: *ec2subnet.AvailabilityZone,
}
})
instanceTypes, err := op.InstanceTypesProvider.List(ctx, &corev1beta1.KubeletConfiguration{}, nodeClass)
instanceTypes, err := op.InstanceTypesProvider.List(ctx, &v1.KubeletConfiguration{}, nodeClass)
if err != nil {
log.Fatalf("listing instance types, %s", err)
}
Expand Down Expand Up @@ -171,9 +171,9 @@ below are the resources available with some assumptions and after the instance o
sort.Strings(familyNames)

// we don't want to show a few labels that will vary amongst regions
delete(labelNameMap, v1.LabelTopologyZone)
delete(labelNameMap, v1beta1.LabelTopologyZoneID)
delete(labelNameMap, corev1beta1.CapacityTypeLabelKey)
delete(labelNameMap, corev1.LabelTopologyZone)
delete(labelNameMap, v1.LabelTopologyZoneID)
delete(labelNameMap, karpv1.CapacityTypeLabelKey)

labelNames := lo.Keys(labelNameMap)

Expand Down Expand Up @@ -210,7 +210,7 @@ below are the resources available with some assumptions and after the instance o
if !ok {
continue
}
if req.Key == v1.LabelTopologyRegion {
if req.Key == corev1.LabelTopologyRegion {
continue
}
if len(req.Values()) == 1 {
Expand All @@ -221,11 +221,11 @@ below are the resources available with some assumptions and after the instance o
fmt.Fprintln(f, " | Resource | Quantity |")
fmt.Fprintln(f, " |--|--|")
for _, resourceName := range resourceNames {
quantity := minusOverhead[v1.ResourceName(resourceName)]
quantity := minusOverhead[corev1.ResourceName(resourceName)]
if quantity.IsZero() {
continue
}
if v1.ResourceName(resourceName) == v1.ResourceEphemeralStorage {
if corev1.ResourceName(resourceName) == corev1.ResourceEphemeralStorage {
i64, _ := quantity.AsInt64()
quantity = *resource.NewQuantity(i64, resource.BinarySI)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/crds/karpenter.k8s.aws_ec2nodeclasses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ spec:
type: object
type: object
served: true
storage: false
storage: true
subresources:
status: {}
- name: v1beta1
Expand Down Expand Up @@ -1293,7 +1293,7 @@ spec:
type: object
type: object
served: true
storage: true
storage: false
subresources:
status: {}
conversion:
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/crds/karpenter.sh_nodeclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ spec:
- spec
type: object
served: true
storage: false
storage: true
subresources:
status: {}
- additionalPrinterColumns:
Expand Down Expand Up @@ -790,7 +790,7 @@ spec:
- spec
type: object
served: true
storage: true
storage: false
subresources:
status: {}
conversion:
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/crds/karpenter.sh_nodepools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ spec:
- spec
type: object
served: true
storage: false
storage: true
subresources:
status: {}
- additionalPrinterColumns:
Expand Down Expand Up @@ -1068,7 +1068,7 @@ spec:
- spec
type: object
served: true
storage: true
storage: false
subresources:
status: {}
conversion:
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/v1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.
package v1 // doc.go is discovered by codegen

import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"

Expand All @@ -28,7 +28,7 @@ import (

func init() {
gv := schema.GroupVersion{Group: apis.Group, Version: "v1"}
v1.AddToGroupVersion(scheme.Scheme, gv)
corev1.AddToGroupVersion(scheme.Scheme, gv)
scheme.Scheme.AddKnownTypes(gv,
&EC2NodeClass{},
&EC2NodeClassList{},
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/v1/ec2nodeclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/samber/lo"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"
karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1"
)

// EC2NodeClassSpec is the top level specification for the AWS Karpenter Provider.
Expand Down Expand Up @@ -399,6 +399,7 @@ const (
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""
// +kubebuilder:printcolumn:name="Role",type="string",JSONPath=".spec.role",priority=1,description=""
// +kubebuilder:resource:path=ec2nodeclasses,scope=Cluster,categories=karpenter,shortName={ec2nc,ec2ncs}
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
type EC2NodeClass struct {
metav1.TypeMeta `json:",inline"`
Expand Down Expand Up @@ -436,7 +437,7 @@ func (in *EC2NodeClass) InstanceProfileRole() string {
func (in *EC2NodeClass) InstanceProfileTags(clusterName string) map[string]string {
return lo.Assign(in.Spec.Tags, map[string]string{
fmt.Sprintf("kubernetes.io/cluster/%s", clusterName): "owned",
corev1beta1.ManagedByAnnotationKey: clusterName,
karpv1.ManagedByAnnotationKey: clusterName,
LabelNodeClass: in.Name,
})
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apis/v1/ec2nodeclass_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package v1

import (
"github.com/awslabs/operatorpkg/status"
v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
)

const (
Expand Down Expand Up @@ -59,7 +59,7 @@ type AMI struct {
Name string `json:"name,omitempty"`
// Requirements of the AMI to be utilized on an instance type
// +required
Requirements []v1.NodeSelectorRequirement `json:"requirements"`
Requirements []corev1.NodeSelectorRequirement `json:"requirements"`
}

// EC2NodeClassStatus contains the resolved state of the EC2NodeClass
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/v1/ec2nodeclass_validation_cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/ptr"
corev1beta1 "sigs.k8s.io/karpenter/pkg/apis/v1beta1"
karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1"
"sigs.k8s.io/karpenter/pkg/test"

v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1"
Expand Down Expand Up @@ -97,15 +97,15 @@ var _ = Describe("CEL/Validation", func() {
})
It("should fail if tags contain a restricted domain key", func() {
nc.Spec.Tags = map[string]string{
corev1beta1.NodePoolLabelKey: "value",
karpv1.NodePoolLabelKey: "value",
}
Expect(env.Client.Create(ctx, nc)).To(Not(Succeed()))
nc.Spec.Tags = map[string]string{
"kubernetes.io/cluster/test": "value",
}
Expect(env.Client.Create(ctx, nc)).To(Not(Succeed()))
nc.Spec.Tags = map[string]string{
corev1beta1.ManagedByAnnotationKey: "test",
karpv1.ManagedByAnnotationKey: "test",
}
Expect(env.Client.Create(ctx, nc)).To(Not(Succeed()))
nc.Spec.Tags = map[string]string{
Expand Down
60 changes: 30 additions & 30 deletions pkg/apis/v1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ import (
"fmt"
"regexp"

v1 "k8s.io/api/core/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
coreapis "sigs.k8s.io/karpenter/pkg/apis"
"sigs.k8s.io/karpenter/pkg/apis/v1beta1"
karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1"

"github.com/aws/karpenter-provider-aws/pkg/apis"
)

func init() {
v1beta1.RestrictedLabelDomains = v1beta1.RestrictedLabelDomains.Insert(RestrictedLabelDomains...)
v1beta1.WellKnownLabels = v1beta1.WellKnownLabels.Insert(
karpv1.RestrictedLabelDomains = karpv1.RestrictedLabelDomains.Insert(RestrictedLabelDomains...)
karpv1.WellKnownLabels = karpv1.WellKnownLabels.Insert(
LabelInstanceHypervisor,
LabelInstanceEncryptionInTransitSupported,
LabelInstanceCategory,
Expand All @@ -49,19 +49,19 @@ func init() {
LabelInstanceAcceleratorManufacturer,
LabelInstanceAcceleratorCount,
LabelTopologyZoneID,
v1.LabelWindowsBuild,
corev1.LabelWindowsBuild,
)
}

var (
TerminationFinalizer = apis.Group + "/termination"
AWSToKubeArchitectures = map[string]string{
"x86_64": v1beta1.ArchitectureAmd64,
v1beta1.ArchitectureArm64: v1beta1.ArchitectureArm64,
"x86_64": karpv1.ArchitectureAmd64,
karpv1.ArchitectureArm64: karpv1.ArchitectureArm64,
}
WellKnownArchitectures = sets.NewString(
v1beta1.ArchitectureAmd64,
v1beta1.ArchitectureArm64,
karpv1.ArchitectureAmd64,
karpv1.ArchitectureArm64,
)
RestrictedLabelDomains = []string{
apis.Group,
Expand All @@ -70,30 +70,30 @@ var (
// Adheres to cluster name pattern matching as specified in the API spec
// https://docs.aws.amazon.com/eks/latest/APIReference/API_CreateCluster.html
regexp.MustCompile(`^kubernetes\.io/cluster/[0-9A-Za-z][A-Za-z0-9\-_]*$`),
regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(v1beta1.NodePoolLabelKey))),
regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(v1beta1.ManagedByAnnotationKey))),
regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(karpv1.NodePoolLabelKey))),
regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(karpv1.ManagedByAnnotationKey))),
regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(LabelNodeClass))),
regexp.MustCompile(fmt.Sprintf("^%s$", regexp.QuoteMeta(TagNodeClaim))),
}
AMIFamilyBottlerocket = "Bottlerocket"
AMIFamilyAL2 = "AL2"
AMIFamilyAL2023 = "AL2023"
AMIFamilyUbuntu = "Ubuntu"
AMIFamilyWindows2019 = "Windows2019"
AMIFamilyWindows2022 = "Windows2022"
AMIFamilyCustom = "Custom"
Windows2019 = "2019"
Windows2022 = "2022"
WindowsCore = "Core"
Windows2019Build = "10.0.17763"
Windows2022Build = "10.0.20348"
ResourceNVIDIAGPU v1.ResourceName = "nvidia.com/gpu"
ResourceAMDGPU v1.ResourceName = "amd.com/gpu"
ResourceAWSNeuron v1.ResourceName = "aws.amazon.com/neuron"
ResourceHabanaGaudi v1.ResourceName = "habana.ai/gaudi"
ResourceAWSPodENI v1.ResourceName = "vpc.amazonaws.com/pod-eni"
ResourcePrivateIPv4Address v1.ResourceName = "vpc.amazonaws.com/PrivateIPv4Address"
ResourceEFA v1.ResourceName = "vpc.amazonaws.com/efa"
AMIFamilyBottlerocket = "Bottlerocket"
AMIFamilyAL2 = "AL2"
AMIFamilyAL2023 = "AL2023"
AMIFamilyUbuntu = "Ubuntu"
AMIFamilyWindows2019 = "Windows2019"
AMIFamilyWindows2022 = "Windows2022"
AMIFamilyCustom = "Custom"
Windows2019 = "2019"
Windows2022 = "2022"
WindowsCore = "Core"
Windows2019Build = "10.0.17763"
Windows2022Build = "10.0.20348"
ResourceNVIDIAGPU corev1.ResourceName = "nvidia.com/gpu"
ResourceAMDGPU corev1.ResourceName = "amd.com/gpu"
ResourceAWSNeuron corev1.ResourceName = "aws.amazon.com/neuron"
ResourceHabanaGaudi corev1.ResourceName = "habana.ai/gaudi"
ResourceAWSPodENI corev1.ResourceName = "vpc.amazonaws.com/pod-eni"
ResourcePrivateIPv4Address corev1.ResourceName = "vpc.amazonaws.com/PrivateIPv4Address"
ResourceEFA corev1.ResourceName = "vpc.amazonaws.com/efa"

LabelNodeClass = apis.Group + "/ec2nodeclass"

Expand Down
Loading

0 comments on commit c32ccc4

Please sign in to comment.