-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Added check to filter supported nodes by ami's arch type #7933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gnana997
wants to merge
5
commits into
aws:main
Choose a base branch
from
gnana997:ami-req-node-class
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
325bc21
Added check to filter supported nodes by amis
gnana997 a7cad45
Added test cases for filtering nodes by ami arch type
gnana997 45845bb
Merge branch 'main' into ami-req-node-class
gnana997 4495e69
Merge branch 'main' into ami-req-node-class
gnana997 6103671
Merge branch 'main' into ami-req-node-class
gnana997 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
/* | ||
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 amifamily_test | ||
|
||
import ( | ||
"testing" | ||
|
||
v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1" | ||
"github.com/aws/karpenter-provider-aws/pkg/providers/amifamily" | ||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/karpenter/pkg/cloudprovider" | ||
"sigs.k8s.io/karpenter/pkg/scheduling" | ||
) | ||
|
||
func TestFilterInstanceTypesByAMICompatibility(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
instanceTypes []*cloudprovider.InstanceType | ||
amis []v1.AMI | ||
expected int | ||
}{ | ||
{ | ||
name: "amd64 instance type with amd64 ami", | ||
instanceTypes: []*cloudprovider.InstanceType{ | ||
{ | ||
Name: "m5.large", | ||
Requirements: scheduling.NewRequirements( | ||
scheduling.NewRequirement(corev1.LabelArchStable, corev1.NodeSelectorOpIn, "amd64"), | ||
), | ||
}, | ||
}, | ||
amis: []v1.AMI{ | ||
{ | ||
ID: "ami-123", | ||
Requirements: []corev1.NodeSelectorRequirement{ | ||
{ | ||
Key: corev1.LabelArchStable, | ||
Operator: corev1.NodeSelectorOpIn, | ||
Values: []string{"amd64"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: 1, | ||
}, | ||
{ | ||
name: "arm64 instance type with amd64 ami", | ||
instanceTypes: []*cloudprovider.InstanceType{ | ||
{ | ||
Name: "m6g.large", | ||
Requirements: scheduling.NewRequirements( | ||
scheduling.NewRequirement(corev1.LabelArchStable, corev1.NodeSelectorOpIn, "arm64"), | ||
), | ||
}, | ||
}, | ||
amis: []v1.AMI{ | ||
{ | ||
ID: "ami-123", | ||
Requirements: []corev1.NodeSelectorRequirement{ | ||
{ | ||
Key: corev1.LabelArchStable, | ||
Operator: corev1.NodeSelectorOpIn, | ||
Values: []string{"amd64"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: 0, | ||
}, | ||
{ | ||
name: "mixed instance types with both amis", | ||
instanceTypes: []*cloudprovider.InstanceType{ | ||
{ | ||
Name: "m5.large", | ||
Requirements: scheduling.NewRequirements( | ||
scheduling.NewRequirement(corev1.LabelArchStable, corev1.NodeSelectorOpIn, "amd64"), | ||
), | ||
}, | ||
{ | ||
Name: "m6g.large", | ||
Requirements: scheduling.NewRequirements( | ||
scheduling.NewRequirement(corev1.LabelArchStable, corev1.NodeSelectorOpIn, "arm64"), | ||
), | ||
}, | ||
}, | ||
amis: []v1.AMI{ | ||
{ | ||
ID: "ami-123", | ||
Requirements: []corev1.NodeSelectorRequirement{ | ||
{ | ||
Key: corev1.LabelArchStable, | ||
Operator: corev1.NodeSelectorOpIn, | ||
Values: []string{"amd64"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
ID: "ami-456", | ||
Requirements: []corev1.NodeSelectorRequirement{ | ||
{ | ||
Key: corev1.LabelArchStable, | ||
Operator: corev1.NodeSelectorOpIn, | ||
Values: []string{"arm64"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: 2, | ||
}, | ||
{ | ||
name: "empty instance types", | ||
instanceTypes: []*cloudprovider.InstanceType{}, | ||
amis: []v1.AMI{ | ||
{ | ||
ID: "ami-123", | ||
Requirements: []corev1.NodeSelectorRequirement{ | ||
{ | ||
Key: corev1.LabelArchStable, | ||
Operator: corev1.NodeSelectorOpIn, | ||
Values: []string{"amd64"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: 0, | ||
}, | ||
{ | ||
name: "empty amis", | ||
instanceTypes: []*cloudprovider.InstanceType{ | ||
{ | ||
Name: "m5.large", | ||
Requirements: scheduling.NewRequirements( | ||
scheduling.NewRequirement(corev1.LabelArchStable, corev1.NodeSelectorOpIn, "amd64"), | ||
), | ||
}, | ||
}, | ||
amis: []v1.AMI{}, | ||
expected: 0, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
compatible := amifamily.FilterInstanceTypesByAMICompatibility(tc.instanceTypes, tc.amis) | ||
assert.Len(t, compatible, tc.expected) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ import ( | |
"sync/atomic" | ||
|
||
"k8s.io/apimachinery/pkg/api/resource" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
"sigs.k8s.io/karpenter/pkg/scheduling" | ||
|
||
awscache "github.com/aws/karpenter-provider-aws/pkg/cache" | ||
|
@@ -32,14 +34,12 @@ import ( | |
"github.com/mitchellh/hashstructure/v2" | ||
"github.com/patrickmn/go-cache" | ||
corev1 "k8s.io/api/core/v1" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
karpv1 "sigs.k8s.io/karpenter/pkg/apis/v1" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" | ||
"github.com/samber/lo" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
|
||
v1 "github.com/aws/karpenter-provider-aws/pkg/apis/v1" | ||
sdk "github.com/aws/karpenter-provider-aws/pkg/aws" | ||
|
@@ -157,12 +157,24 @@ func (p *DefaultProvider) List(ctx context.Context, nodeClass *v1.EC2NodeClass) | |
// date capacity information. Rather than incurring a cache miss each time an instance is launched into a reserved | ||
// offering (or terminated), offerings are injected to the cached instance types on each call. Note that on-demand and | ||
// spot offerings are still cached - only reserved offerings are generated each time. | ||
return p.offeringProvider.InjectOfferings( | ||
instanceTypesWithOfferings := p.offeringProvider.InjectOfferings( | ||
ctx, | ||
instanceTypes, | ||
nodeClass, | ||
p.allZones, | ||
), nil | ||
) | ||
|
||
// Filter instance types that don't have compatible AMIs to prevent architecture mismatches | ||
filteredInstanceTypes := amifamily.FilterInstanceTypesByAMICompatibility(instanceTypesWithOfferings, nodeClass.Status.AMIs) | ||
if len(filteredInstanceTypes) == 0 { | ||
log.FromContext(ctx).WithValues( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is a log -- this is an error IMO |
||
"nodeclass", nodeClass.Name, | ||
"ami-count", len(nodeClass.Status.AMIs), | ||
"instance-type-count", len(instanceTypesWithOfferings), | ||
).V(4).Info("no instance types are compatible with available AMIs, check NodePool and NodeClass architecture requirements") | ||
} | ||
|
||
return filteredInstanceTypes, nil | ||
} | ||
|
||
func (p *DefaultProvider) resolveInstanceTypes( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we allow our Unknown WellKnown labels to be compatible here? Can we check the other places we are doing instance type compatibility with AMIs?
Also, I wonder if we can just re-leverage
MapInstanceTypes
and then just pull-out the instance types that we supportThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gnana997 Any luck with this update?