in pkg/noderesources/allocatable.go [80:118]
func NewAllocatable(_ context.Context, allocArgs runtime.Object, h framework.Handle) (framework.Plugin, error) {
// Start with default values.
mode := config.Least
resToWeightMap := defaultResourcesToWeightMap
// Update values from args, if specified.
if allocArgs != nil {
args, ok := allocArgs.(*config.NodeResourcesAllocatableArgs)
if !ok {
return nil, fmt.Errorf("want args to be of type NodeResourcesAllocatableArgs, got %T", allocArgs)
}
if args.Mode != "" {
mode = args.Mode
if mode != config.Least && mode != config.Most {
return nil, fmt.Errorf("invalid mode, got %s", mode)
}
}
if len(args.Resources) > 0 {
if err := validateResources(args.Resources); err != nil {
return nil, err
}
resToWeightMap = make(resourceToWeightMap)
for _, resource := range args.Resources {
resToWeightMap[v1.ResourceName(resource.Name)] = resource.Weight
}
}
}
return &Allocatable{
handle: h,
resourceAllocationScorer: resourceAllocationScorer{
Name: AllocatableName,
scorer: resourceScorer(resToWeightMap, mode),
resourceToWeightMap: resToWeightMap,
},
}, nil
}