Skip to content

Commit

Permalink
Add logs for instance type filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
jigisha620 committed Mar 13, 2024
1 parent 982f2eb commit f997257
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/cloudprovider/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (c *CloudProvider) Create(ctx context.Context, nodeClaim *corev1beta1.NodeC
return nil, cloudprovider.NewInsufficientCapacityError(fmt.Errorf("resolving node class, %w", err))
}
instanceTypes, err := c.resolveInstanceTypes(ctx, nodeClaim, nodeClass)
logging.FromContext(ctx).With("instanceTypes", utils.PrettySlice(utils.GetInstanceNameFromInstanceType(instanceTypes), 5)).Debugf("resolved instance types from nodeclass")
if err != nil {
return nil, fmt.Errorf("resolving instance types, %w", err)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/providers/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (p *Provider) Create(ctx context.Context, nodeClass *v1beta1.EC2NodeClass,
// Only filter the instances if there are no minValues in the requirement.
if !schedulingRequirements.HasMinValues() {
instanceTypes = p.filterInstanceTypes(nodeClaim, instanceTypes)
logging.FromContext(ctx).With("instanceTypes", utils.PrettySlice(utils.GetInstanceNameFromInstanceType(instanceTypes), 5)).Debugf("filtered instance types after removing exotic types and spot instance types costlier than cheapest on-demand")
}
tags := getTags(ctx, nodeClass, nodeClaim)
fleetInstance, err := p.launchInstance(ctx, nodeClass, nodeClaim, instanceTypes, tags)
Expand Down
10 changes: 10 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"regexp"
"strings"

"sigs.k8s.io/karpenter/pkg/cloudprovider"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/samber/lo"
Expand Down Expand Up @@ -66,3 +68,11 @@ func PrettySlice[T any](s []T, maxItems int) string {
}
return sb.String()
}

func GetInstanceNameFromInstanceType(instanceTypes []*cloudprovider.InstanceType) []string {
var names []string
for _, val := range instanceTypes {
names = append(names, val.Name)
}
return names
}

0 comments on commit f997257

Please sign in to comment.