Skip to content
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

adding a special instance-types string 'not-specified' #833

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (np NodePool) KarpenterRequirements() []v1.NodeSelectorRequirementApplyConf
}

func (np NodePool) KarpenterInstanceTypeStrategy() string {
if len(np.InstanceTypes) == 0 {
if len(np.InstanceTypes) == 1 && np.InstanceTypes[0] == "not-specified" {
return "not-specified"
}
if len(np.InstanceTypes) == 1 && np.InstanceTypes[0] == "default-for-karpenter" {
Expand Down
7 changes: 0 additions & 7 deletions pkg/aws/instance_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,6 @@ func getCompatibleCPUArchitecture(instanceType *ec2.InstanceTypeInfo) (string, e
return "", fmt.Errorf("didn't find compatible cpu architecture within '%v'", supportedArchitectures)
}

func min(a int64, b int64) int64 {
if a < b {
return a
}
return b
}

func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
Expand Down
8 changes: 4 additions & 4 deletions pkg/updatestrategy/aws_asg.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ func (n *ASGNodePoolsBackend) Scale(_ context.Context, nodePool *api.NodePool, r
}

for _, asg := range asgs {
min := int64(math.Min(float64(aws.Int64Value(asg.DesiredCapacity)), float64(aws.Int64Value(asg.MinSize))))
max := int64(math.Max(float64(aws.Int64Value(asg.DesiredCapacity)), float64(aws.Int64Value(asg.MaxSize))))
minSize := int64(math.Min(float64(aws.Int64Value(asg.DesiredCapacity)), float64(aws.Int64Value(asg.MinSize))))
maxSize := int64(math.Max(float64(aws.Int64Value(asg.DesiredCapacity)), float64(aws.Int64Value(asg.MaxSize))))
Comment on lines +196 to +197
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are min/max builtins in go since 1.21 https://pkg.go.dev/builtin#min
so something like this

minSize := min(aws.Int64Value(asg.DesiredCapacity), aws.Int64Value(asg.MinSize))

should work


params := &autoscaling.UpdateAutoScalingGroupInput{
AutoScalingGroupName: asg.AutoScalingGroupName,
DesiredCapacity: asg.DesiredCapacity,
MinSize: aws.Int64(min),
MaxSize: aws.Int64(max),
MinSize: aws.Int64(minSize),
MaxSize: aws.Int64(maxSize),
}

_, err := n.asgClient.UpdateAutoScalingGroup(params)
Expand Down
6 changes: 3 additions & 3 deletions pkg/updatestrategy/rolling_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ func getFailureDomain(nodes []*Node) string {
}
}

min := len(nodes)
minNodes := len(nodes)
failureDomain := "a"
for fd, num := range fdCount {
if num < min || (num == min && fd < failureDomain) {
min = num
if num < minNodes || (num == minNodes && fd < failureDomain) {
minNodes = num
failureDomain = fd
}
}
Expand Down
Loading