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 669509c
Show file tree
Hide file tree
Showing 19 changed files with 865 additions and 149 deletions.
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 669509c

Please sign in to comment.