Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/added-20260810-110000.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Added
body: |-
Validate NvFractions GPU memory annotations
28 changes: 24 additions & 4 deletions pkg/admission/webhook/v1alpha2/gpusharing/gpu_sharing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ package gpusharing
import (
"fmt"

"strconv"

v1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/kai-scheduler/KAI-scheduler/pkg/binder/common/gpusharingconfigmap"
"github.com/kai-scheduler/KAI-scheduler/pkg/common/constants"
"github.com/kai-scheduler/KAI-scheduler/pkg/common/resources"

"github.com/kai-scheduler/KAI-scheduler/pkg/binder/common"
gpurequesthandler "github.com/kai-scheduler/KAI-scheduler/pkg/binder/plugins/gpusharing/gpu-request"
)

const (
fractionContainerIndex = 0
CdiDeviceNameBase = "k8s.device-plugin.nvidia.com/gpu=%s"
CdiDeviceNameBase = "k8s.device-plugin.nvidia.com/gpu=%s"
)

type GPUSharing struct {
Expand All @@ -44,7 +45,7 @@ func (p *GPUSharing) Validate(pod *v1.Pod) error {
pod.Namespace, pod.Name,
)
}
return gpurequesthandler.ValidateGpuRequests(pod)
return resources.ValidateGPUFractionRequest(pod)
}

func (p *GPUSharing) Mutate(pod *v1.Pod) error {
Expand All @@ -61,6 +62,11 @@ func (p *GPUSharing) Mutate(pod *v1.Pod) error {
return fmt.Errorf("failed to get fraction container ref: %w", err)
}

err = adjustFractionalMemoryAnnotations(pod, containerRef)
if err != nil {
return err
}

capabilitiesConfigMapName := gpusharingconfigmap.SetGpuCapabilitiesConfigMapName(pod, containerRef)
directEnvVarsMapName, err := gpusharingconfigmap.ExtractDirectEnvVarsConfigMapName(pod, containerRef)
if err != nil {
Expand All @@ -73,3 +79,17 @@ func (p *GPUSharing) Mutate(pod *v1.Pod) error {

return nil
}

// adjustFractionalMemoryAnnotations adjusts the old fractional memory annotations to NvFractions format
func adjustFractionalMemoryAnnotations(pod *v1.Pod, containerRef *gpusharingconfigmap.PodContainerRef) error {
gpuMemoryRequestMiB, foundGPUMemory := pod.Annotations[constants.GpuMemory]
if foundGPUMemory {
gpuMemoryRequestMiB, err := strconv.ParseUint(gpuMemoryRequestMiB, 10, 64)
if err != nil {
return fmt.Errorf("failed to parse gpu memory annotation value: %w", err)
}
memoryQuantity := resources.GpuMemoryAnnotationToNvFractionsMemoryRequest(gpuMemoryRequestMiB)
pod.Annotations[resources.CalcGpuFractionAnnotationForContainer(containerRef.Container.Name)] = memoryQuantity.String()
}
return nil
}
Loading
Loading