Copyright 2023 The Volcano Authors.
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 api
import (
"sync"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"volcano.sh/volcano/pkg/scheduler/api/devices/nvidia/gpushare"
"volcano.sh/volcano/pkg/scheduler/api/devices/nvidia/vgpu"
)
const (
GPUSharingDevice = "GpuShare"
)
type Devices interface {
AddResource(pod *v1.Pod)
SubResource(pod *v1.Pod)
HasDeviceRequest(pod *v1.Pod) bool
FilterNode(pod *v1.Pod, policy string) (int, string, error)
ScoreNode(pod *v1.Pod, policy string) float64
Allocate(kubeClient kubernetes.Interface, pod *v1.Pod) error
Release(kubeClient kubernetes.Interface, pod *v1.Pod) error
GetIgnoredDevices() []string
GetStatus() string
}
var _ Devices = new(gpushare.GPUDevices)
var RegisteredDevices = []string{
GPUSharingDevice, vgpu.DeviceName,
}
var IgnoredDevicesList = ignoredDevicesList{}
type ignoredDevicesList struct {
sync.RWMutex
ignoredDevices []string
}
func (l *ignoredDevicesList) Set(deviceLists ...[]string) {
l.Lock()
defer l.Unlock()
l.ignoredDevices = l.ignoredDevices[:0]
for _, devices := range deviceLists {
l.ignoredDevices = append(l.ignoredDevices, devices...)
}
}
func (l *ignoredDevicesList) Range(f func(i int, device string) bool) {
l.RLock()
defer l.RUnlock()
for i, device := range l.ignoredDevices {
if !f(i, device) {
break
}
}
}