Skip to content

Commit

Permalink
Try a different approach
Browse files Browse the repository at this point in the history
  • Loading branch information
bdwyertech committed Dec 6, 2021
1 parent d20fb07 commit a110bbf
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
17 changes: 5 additions & 12 deletions pkg/cloudprovider/aws/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/aws/karpenter/pkg/cloudprovider"
"github.com/aws/karpenter/pkg/cloudprovider/aws/apis/v1alpha1"
"github.com/aws/karpenter/pkg/utils/injection"
"github.com/aws/karpenter/pkg/utils/resources"
)

type InstanceProvider struct {
Expand Down Expand Up @@ -237,17 +236,11 @@ func (p *InstanceProvider) instanceToNode(instance *ec2.Instance, instanceTypes
return &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: aws.StringValue(instance.PrivateDnsName),
Labels: func() (labels map[string]string) {
labels = map[string]string{
v1.LabelTopologyZone: aws.StringValue(instance.Placement.AvailabilityZone),
v1.LabelInstanceTypeStable: aws.StringValue(instance.InstanceType),
v1alpha5.LabelCapacityType: getCapacityType(instance),
}
if instanceType.AWSPodENI() {
labels[resources.AWSPodENI] = "true"
}
return
}(),
Labels: map[string]string{
v1.LabelTopologyZone: aws.StringValue(instance.Placement.AvailabilityZone),
v1.LabelInstanceTypeStable: aws.StringValue(instance.InstanceType),
v1alpha5.LabelCapacityType: getCapacityType(instance),
},
},
Spec: v1.NodeSpec{
ProviderID: fmt.Sprintf("aws:///%s/%s", aws.StringValue(instance.Placement.AvailabilityZone), aws.StringValue(instance.InstanceId)),
Expand Down
7 changes: 5 additions & 2 deletions pkg/cloudprovider/aws/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ func (i *InstanceType) Pods() *resource.Quantity {
return resources.Quantity(fmt.Sprint(*i.NetworkInfo.MaximumNetworkInterfaces*(*i.NetworkInfo.Ipv4AddressesPerInterface-1) + 2))
}

func (i *InstanceType) AWSPodENI() bool {
func (i *InstanceType) AWSPodENI() *resource.Quantity {
// Pod ENI is supported by Bare Metal & all Nitro except T3
// https://docs.aws.amazon.com/eks/latest/userguide/security-groups-for-pods.html#supported-instance-types
return (i.BareMetal != nil && *i.BareMetal) || (i.Hypervisor != nil && *i.Hypervisor == "nitro" && !strings.HasPrefix(*i.InstanceType, "t3"))
if aws.BoolValue(i.BareMetal) || (aws.StringValue(i.Hypervisor) == "nitro" && !strings.HasPrefix(*i.InstanceType, "t3")) {
return i.Pods()
}
return resources.Quantity("0")
}

func (i *InstanceType) NvidiaGPUs() *resource.Quantity {
Expand Down
5 changes: 4 additions & 1 deletion pkg/cloudprovider/aws/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ var _ = Describe("Allocation", func() {
test.UnschedulablePod(test.PodOptions{
NodeSelector: map[string]string{
v1.LabelInstanceTypeStable: "t3.large",
resources.AWSPodENI: "true",
},
ResourceRequirements: v1.ResourceRequirements{
Requests: v1.ResourceList{resources.AWSPodENI: resource.MustParse("1")},
Limits: v1.ResourceList{resources.AWSPodENI: resource.MustParse("1")},
},
})) {
ExpectNotScheduled(ctx, env.Client, pod)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/fake/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (c *CloudProvider) GetInstanceTypes(_ context.Context, _ *v1alpha5.Constrai
}),
NewInstanceType(InstanceTypeOptions{
name: "pod-eni-instance-type",
awsPodENI: true,
awsPodENI: resource.MustParse("1"),
}),
NewInstanceType(InstanceTypeOptions{
name: "small-instance-type",
Expand Down
6 changes: 3 additions & 3 deletions pkg/cloudprovider/fake/instancetype.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type InstanceTypeOptions struct {
nvidiaGPUs resource.Quantity
amdGPUs resource.Quantity
awsNeurons resource.Quantity
awsPodENI bool
awsPodENI resource.Quantity
}

type InstanceType struct {
Expand Down Expand Up @@ -111,8 +111,8 @@ func (i *InstanceType) AWSNeurons() *resource.Quantity {
return &i.awsNeurons
}

func (i *InstanceType) AWSPodENI() bool {
return i.awsPodENI
func (i *InstanceType) AWSPodENI() *resource.Quantity {
return &i.awsPodENI
}

func (i *InstanceType) Overhead() v1.ResourceList {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cloudprovider/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type InstanceType interface {
NvidiaGPUs() *resource.Quantity
AMDGPUs() *resource.Quantity
AWSNeurons() *resource.Quantity
AWSPodENI() bool
AWSPodENI() *resource.Quantity
Overhead() v1.ResourceList
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/controllers/provisioning/binpacking/packable.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func PackableFor(i cloudprovider.InstanceType) *Packable {
resources.NvidiaGPU: *i.NvidiaGPUs(),
resources.AMDGPU: *i.AMDGPUs(),
resources.AWSNeuron: *i.AWSNeurons(),
resources.AWSPodENI: *i.AWSPodENI(),
v1.ResourcePods: *i.Pods(),
},
}
Expand Down Expand Up @@ -231,17 +232,17 @@ func (p *Packable) validateAWSNeurons(schedule *scheduling.Schedule) error {
}

func (p *Packable) validateAWSPodENI(schedule *scheduling.Schedule) error {
if p.InstanceType.AWSPodENI() {
return nil
}
for _, pod := range schedule.Pods {
for _, container := range pod.Spec.Containers {
if _, ok := container.Resources.Requests[resources.AWSPodENI]; ok {
if p.InstanceType.AWSPodENI().IsZero() {
return fmt.Errorf("aws pod eni is required")
}
return nil
}
}
}
return fmt.Errorf("aws pod eni is not required")
return nil
}

func packableNames(instanceTypes []*Packable) []string {
Expand Down

0 comments on commit a110bbf

Please sign in to comment.