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

koord-scheduler: refactor the implementation of Validate/Convert of request in DeviceShare #1413

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/extension/scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ type DeviceAllocation struct {
Extension json.RawMessage `json:"extension,omitempty"`
}

var GetDeviceAllocations = func(podAnnotations map[string]string) (DeviceAllocations, error) {
func GetDeviceAllocations(podAnnotations map[string]string) (DeviceAllocations, error) {
deviceAllocations := DeviceAllocations{}
data, ok := podAnnotations[AnnotationDeviceAllocated]
if !ok {
Expand Down
8 changes: 4 additions & 4 deletions pkg/scheduler/plugins/deviceshare/device_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,15 @@ func (n *nodeDevice) updateAllocateSet(deviceType schedulingv1alpha1.DeviceType,
func (n *nodeDevice) tryAllocateDevice(podRequest corev1.ResourceList, required, preferred map[schedulingv1alpha1.DeviceType]sets.Int, requiredDeviceResources, preemptibleDeviceResources map[schedulingv1alpha1.DeviceType]deviceResources) (apiext.DeviceAllocations, error) {
allocateResult := make(apiext.DeviceAllocations)

for deviceType := range DeviceResourceNames {
for deviceType, supportedResourceNames := range DeviceResourceNames {
switch deviceType {
case schedulingv1alpha1.GPU, schedulingv1alpha1.RDMA, schedulingv1alpha1.FPGA:
if !hasDeviceResource(podRequest, deviceType) {
deviceRequest := quotav1.Mask(podRequest, supportedResourceNames)
if quotav1.IsZero(deviceRequest) {
break
}
err := n.tryAllocateDeviceByType(
podRequest,
deviceRequest,
deviceType,
required[deviceType],
preferred[deviceType],
Expand Down Expand Up @@ -297,7 +298,6 @@ func (n *nodeDevice) tryAllocateDeviceByType(
requiredDeviceResources deviceResources,
preemptibleDeviceResources deviceResources,
) error {
podRequest = quotav1.Mask(podRequest, DeviceResourceNames[deviceType])
nodeDeviceTotal := n.deviceTotal[deviceType]
if len(nodeDeviceTotal) == 0 {
return fmt.Errorf("node does not have enough %v", deviceType)
Expand Down
34 changes: 10 additions & 24 deletions pkg/scheduler/plugins/deviceshare/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
quotav1 "k8s.io/apiserver/pkg/quota/v1"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/api/v1/resource"
"k8s.io/kubernetes/pkg/scheduler/framework"

Expand Down Expand Up @@ -159,30 +158,17 @@ func preparePod(pod *corev1.Pod) (skip bool, requests corev1.ResourceList, statu
skip = true
requests = corev1.ResourceList{}

for deviceType := range DeviceResourceNames {
switch deviceType {
case schedulingv1alpha1.GPU:
if !hasDeviceResource(podRequests, deviceType) {
break
}
combination, err := ValidateGPURequest(podRequests)
if err != nil {
return false, nil, framework.NewStatus(framework.Error, err.Error())
}
requests = quotav1.Add(requests, ConvertGPUResource(podRequests, combination))
skip = false
case schedulingv1alpha1.RDMA, schedulingv1alpha1.FPGA:
if !hasDeviceResource(podRequests, deviceType) {
break
}
if err := validateCommonDeviceRequest(podRequests, deviceType); err != nil {
return false, nil, framework.NewStatus(framework.Error, err.Error())
}
requests = quotav1.Add(requests, convertCommonDeviceResource(podRequests, deviceType))
skip = false
default:
klog.Warningf("device type %v is not supported yet, pod: %v", deviceType, klog.KObj(pod))
for _, supportedResourceNames := range DeviceResourceNames {
deviceRequest := quotav1.Mask(podRequests, supportedResourceNames)
if quotav1.IsZero(deviceRequest) {
continue
}
combination, err := ValidateDeviceRequest(deviceRequest)
if err != nil {
return false, nil, framework.NewStatus(framework.Error, err.Error())
}
requests = quotav1.Add(requests, ConvertDeviceRequest(deviceRequest, combination))
skip = false
}
return
}
Expand Down
15 changes: 0 additions & 15 deletions pkg/scheduler/plugins/deviceshare/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/client-go/informers"
kubefake "k8s.io/client-go/kubernetes/fake"
schedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultbinder"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/queuesort"
Expand Down Expand Up @@ -158,23 +157,9 @@ func Test_New(t *testing.T) {
)
proxyNew := frameworkext.PluginFactoryProxy(extenderFactory, New)

deviceSharePluginConfig := schedulerconfig.PluginConfig{
Name: Name,
Args: &config.DeviceShareArgs{},
}

registeredPlugins := []schedulertesting.RegisterPluginFunc{
func(reg *runtime.Registry, profile *schedulerconfig.KubeSchedulerProfile) {
profile.PluginConfig = []schedulerconfig.PluginConfig{
deviceSharePluginConfig,
}
},
schedulertesting.RegisterBindPlugin(defaultbinder.Name, defaultbinder.New),
schedulertesting.RegisterQueueSortPlugin(queuesort.Name, queuesort.New),
schedulertesting.RegisterPreFilterPlugin(Name, proxyNew),
schedulertesting.RegisterFilterPlugin(Name, proxyNew),
schedulertesting.RegisterReservePlugin(Name, proxyNew),
schedulertesting.RegisterPreBindPlugin(Name, proxyNew),
}

cs := kubefake.NewSimpleClientset()
Expand Down