@@ -5,24 +5,26 @@ package runtimeenforcement
55
66import (
77 "context"
8+ "fmt"
89
910 v1 "k8s.io/api/core/v1"
11+ "k8s.io/utils/ptr"
1012 "sigs.k8s.io/controller-runtime/pkg/client"
1113
1214 "github.com/NVIDIA/KAI-scheduler/pkg/binder/binding/resourcereservation"
13- "github.com/NVIDIA/KAI-scheduler/pkg/binder/common"
14- "github.com/NVIDIA/KAI-scheduler/pkg/common/constants"
1515 "github.com/NVIDIA/KAI-scheduler/pkg/common/k8s_utils"
1616 "github.com/NVIDIA/KAI-scheduler/pkg/common/resources"
1717)
1818
1919type RuntimeEnforcement struct {
20- kubeClient client.Client
20+ kubeClient client.Client
21+ gpuPodRuntimeClassName string
2122}
2223
23- func New (kubeClient client.Client ) * RuntimeEnforcement {
24+ func New (kubeClient client.Client , gpuPodRuntimeClassName string ) * RuntimeEnforcement {
2425 return & RuntimeEnforcement {
25- kubeClient : kubeClient ,
26+ kubeClient : kubeClient ,
27+ gpuPodRuntimeClassName : gpuPodRuntimeClassName ,
2628 }
2729}
2830
@@ -50,15 +52,23 @@ func (p *RuntimeEnforcement) Mutate(pod *v1.Pod) error {
5052
5153 if resources .RequestsGPU (pod ) {
5254 exists , err := k8s_utils .RuntimeClassExists (context .Background (),
53- p .kubeClient , constants . DefaultRuntimeClassName )
55+ p .kubeClient , p . gpuPodRuntimeClassName )
5456 if err != nil {
5557 return err
5658 } else if ! exists {
57- return nil
59+ return runtimeClassDoesNotExistError ( p . gpuPodRuntimeClassName )
5860 }
5961
60- common . SetNVIDIARuntimeClass (pod )
62+ setRuntimeClass (pod , p . gpuPodRuntimeClassName )
6163 }
6264
6365 return nil
6466}
67+
68+ func setRuntimeClass (pod * v1.Pod , runtimeClassName string ) {
69+ pod .Spec .RuntimeClassName = ptr .To (runtimeClassName )
70+ }
71+
72+ func runtimeClassDoesNotExistError (runtimeClassName string ) error {
73+ return fmt .Errorf ("cannot set runtimeClassName: runtimeClass '%s' does not exist" , runtimeClassName )
74+ }
0 commit comments