Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into switch-to-v1
  • Loading branch information
engedaam committed Jul 5, 2024
2 parents 5d221a8 + 2d9970e commit 318d924
Show file tree
Hide file tree
Showing 21 changed files with 869 additions and 151 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/aws/karpenter-provider-aws

go 1.22.5

replace sigs.k8s.io/karpenter v0.37.1-0.20240629051434-89a81c3ae853 => github.com/engedaam/karpenter-core v0.0.0-20240705112536-1d148ce95425

require (
github.com/Pallinder/go-randomdata v1.2.0
github.com/PuerkitoBio/goquery v1.9.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
github.com/engedaam/karpenter-core v0.0.0-20240705112536-1d148ce95425 h1:5e4bB/QsWN1/XuhOCDU49rjbJOvQyw76MpK3RGkUDS8=
github.com/engedaam/karpenter-core v0.0.0-20240705112536-1d148ce95425/go.mod h1:Capmf9EwVSBoANOkP5qy4xHBaZ9/y0wUDyh4UzgRJlk=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down Expand Up @@ -763,8 +765,6 @@ 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.20240629051434-89a81c3ae853 h1:WAFMsZJpnScxrsXBsbou0hsZJOQRFS1RxRXb4Ee/cs4=
sigs.k8s.io/karpenter v0.37.1-0.20240629051434-89a81c3ae853/go.mod h1:jPA1J954ZvzJelythD9EtkrQXZLPUrZaMhQJ4MBRQ/Q=
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
2 changes: 1 addition & 1 deletion hack/docs/instancetypes_gen_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func main() {
Zone: *ec2subnet.AvailabilityZone,
}
})
instanceTypes, err := op.InstanceTypesProvider.List(ctx, &providerv1.KubeletConfiguration{}, nodeClass)
instanceTypes, err := op.InstanceTypesProvider.List(ctx, nodeClass)
if err != nil {
log.Fatalf("listing instance types, %s", err)
}
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,6 +1293,6 @@ spec:
type: object
type: object
served: true
storage: true
storage: false
subresources:
status: {}
7 changes: 4 additions & 3 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"
v1 "sigs.k8s.io/karpenter/pkg/apis/v1"
)

// EC2NodeClassSpec is the top level specification for the AWS Karpenter Provider.
Expand Down Expand Up @@ -186,7 +186,7 @@ type AMISelectorTerm struct {
// KubeletConfiguration defines args to be used when configuring kubelet on provisioned nodes.
// They are a subset of the upstream types, recognizing not all options may be supported.
// Wherever possible, the types and names should reflect the upstream kubelet types.
// https://pkg.go.dev/k8s.io/kubelet/config/v1beta1#KubeletConfiguration
// https://pkg.go.dev/k8s.io/kubelet/config/v1#KubeletConfiguration
// https://github.com/kubernetes/kubernetes/blob/9f82d81e55cafdedab619ea25cabf5d42736dacf/cmd/kubelet/app/options/options.go#L53
type KubeletConfiguration struct {
// clusterDNS is a list of IP addresses for the cluster DNS server.
Expand Down Expand Up @@ -395,6 +395,7 @@ const (

// EC2NodeClass is the Schema for the EC2NodeClass API
// +kubebuilder:object:root=true
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description=""
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description=""
// +kubebuilder:printcolumn:name="Role",type="string",JSONPath=".spec.role",priority=1,description=""
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,
v1.ManagedByAnnotationKey: clusterName,
LabelNodeClass: in.Name,
})
}
Expand Down
173 changes: 173 additions & 0 deletions pkg/apis/v1/ec2nodeclass_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
"context"

"github.com/aws/karpenter-provider-aws/pkg/apis/v1beta1"
"github.com/samber/lo"
"knative.dev/pkg/apis"
)

func (in *EC2NodeClass) ConvertTo(ctx context.Context, to apis.Convertible) error {
v1beta1enc := to.(*v1beta1.EC2NodeClass)
v1beta1enc.ObjectMeta = in.ObjectMeta

in.Spec.convertTo(&v1beta1enc.Spec)
in.Status.convertTo((&v1beta1enc.Status))
return nil
}

func (in *EC2NodeClassSpec) convertTo(v1beta1enc *v1beta1.EC2NodeClassSpec) {
v1beta1enc.SubnetSelectorTerms = lo.Map(in.SubnetSelectorTerms, func(subnet SubnetSelectorTerm, _ int) v1beta1.SubnetSelectorTerm {
return v1beta1.SubnetSelectorTerm{
ID: subnet.ID,
Tags: subnet.Tags,
}
})
v1beta1enc.SecurityGroupSelectorTerms = lo.Map(in.SecurityGroupSelectorTerms, func(sg SecurityGroupSelectorTerm, _ int) v1beta1.SecurityGroupSelectorTerm {
return v1beta1.SecurityGroupSelectorTerm{
ID: sg.ID,
Name: sg.Name,
Tags: sg.Tags,
}
})
v1beta1enc.AMISelectorTerms = lo.Map(in.AMISelectorTerms, func(ami AMISelectorTerm, _ int) v1beta1.AMISelectorTerm {
return v1beta1.AMISelectorTerm{
ID: ami.ID,
Name: ami.Name,
Owner: ami.Owner,
Tags: ami.Tags,
}
})
v1beta1enc.AMIFamily = in.AMIFamily
v1beta1enc.AssociatePublicIPAddress = in.AssociatePublicIPAddress
v1beta1enc.Context = in.Context
v1beta1enc.DetailedMonitoring = in.DetailedMonitoring
v1beta1enc.Role = in.Role
v1beta1enc.InstanceProfile = in.InstanceProfile
v1beta1enc.InstanceStorePolicy = (*v1beta1.InstanceStorePolicy)(in.InstanceStorePolicy)
v1beta1enc.Tags = in.Tags
v1beta1enc.UserData = in.UserData
v1beta1enc.MetadataOptions = (*v1beta1.MetadataOptions)(in.MetadataOptions)
v1beta1enc.BlockDeviceMappings = lo.Map(in.BlockDeviceMappings, func(bdm *BlockDeviceMapping, _ int) *v1beta1.BlockDeviceMapping {
return &v1beta1.BlockDeviceMapping{
DeviceName: bdm.DeviceName,
RootVolume: bdm.RootVolume,
EBS: (*v1beta1.BlockDevice)(bdm.EBS),
}
})
}

func (in *EC2NodeClassStatus) convertTo(v1beta1enc *v1beta1.EC2NodeClassStatus) {
v1beta1enc.Subnets = lo.Map(in.Subnets, func(subnet Subnet, _ int) v1beta1.Subnet {
return v1beta1.Subnet{
ID: subnet.ID,
Zone: subnet.Zone,
ZoneID: subnet.ZoneID,
}
})
v1beta1enc.SecurityGroups = lo.Map(in.SecurityGroups, func(sg SecurityGroup, _ int) v1beta1.SecurityGroup {
return v1beta1.SecurityGroup{
ID: sg.ID,
Name: sg.Name,
}
})
v1beta1enc.AMIs = lo.Map(in.AMIs, func(ami AMI, _ int) v1beta1.AMI {
return v1beta1.AMI{
ID: ami.ID,
Name: ami.Name,
Requirements: ami.Requirements,
}
})
v1beta1enc.InstanceProfile = in.InstanceProfile
v1beta1enc.Conditions = in.Conditions
}

func (in *EC2NodeClass) ConvertFrom(ctx context.Context, from apis.Convertible) error {
v1beta1enc := from.(*v1beta1.EC2NodeClass)
in.ObjectMeta = v1beta1enc.ObjectMeta

in.Spec.convertFrom(&v1beta1enc.Spec)
in.Status.convertFrom((&v1beta1enc.Status))
return nil
}

func (in *EC2NodeClassSpec) convertFrom(v1beta1enc *v1beta1.EC2NodeClassSpec) {
in.SubnetSelectorTerms = lo.Map(v1beta1enc.SubnetSelectorTerms, func(subnet v1beta1.SubnetSelectorTerm, _ int) SubnetSelectorTerm {
return SubnetSelectorTerm{
ID: subnet.ID,
Tags: subnet.Tags,
}
})
in.SecurityGroupSelectorTerms = lo.Map(v1beta1enc.SecurityGroupSelectorTerms, func(sg v1beta1.SecurityGroupSelectorTerm, _ int) SecurityGroupSelectorTerm {
return SecurityGroupSelectorTerm{
ID: sg.ID,
Name: sg.Name,
Tags: sg.Tags,
}
})
in.AMISelectorTerms = lo.Map(v1beta1enc.AMISelectorTerms, func(ami v1beta1.AMISelectorTerm, _ int) AMISelectorTerm {
return AMISelectorTerm{
ID: ami.ID,
Name: ami.Name,
Owner: ami.Owner,
Tags: ami.Tags,
}
})
in.AMIFamily = v1beta1enc.AMIFamily
in.AssociatePublicIPAddress = v1beta1enc.AssociatePublicIPAddress
in.Context = v1beta1enc.Context
in.DetailedMonitoring = v1beta1enc.DetailedMonitoring
in.Role = v1beta1enc.Role
in.InstanceProfile = v1beta1enc.InstanceProfile
in.InstanceStorePolicy = (*InstanceStorePolicy)(v1beta1enc.InstanceStorePolicy)
in.Tags = v1beta1enc.Tags
in.UserData = v1beta1enc.UserData
in.MetadataOptions = (*MetadataOptions)(v1beta1enc.MetadataOptions)
in.BlockDeviceMappings = lo.Map(v1beta1enc.BlockDeviceMappings, func(bdm *v1beta1.BlockDeviceMapping, _ int) *BlockDeviceMapping {
return &BlockDeviceMapping{
DeviceName: bdm.DeviceName,
RootVolume: bdm.RootVolume,
EBS: (*BlockDevice)(bdm.EBS),
}
})
}

func (in *EC2NodeClassStatus) convertFrom(v1beta1enc *v1beta1.EC2NodeClassStatus) {
in.Subnets = lo.Map(v1beta1enc.Subnets, func(subnet v1beta1.Subnet, _ int) Subnet {
return Subnet{
ID: subnet.ID,
Zone: subnet.Zone,
ZoneID: subnet.ZoneID,
}
})
in.SecurityGroups = lo.Map(v1beta1enc.SecurityGroups, func(sg v1beta1.SecurityGroup, _ int) SecurityGroup {
return SecurityGroup{
ID: sg.ID,
Name: sg.Name,
}
})
in.AMIs = lo.Map(v1beta1enc.AMIs, func(ami v1beta1.AMI, _ int) AMI {
return AMI{
ID: ami.ID,
Name: ami.Name,
Requirements: ami.Requirements,
}
})
in.InstanceProfile = v1beta1enc.InstanceProfile
in.Conditions = v1beta1enc.Conditions
}
Loading

0 comments on commit 318d924

Please sign in to comment.