-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Annotate GPU Reservation Pods with GpuIdx
- Loading branch information
Showing
5 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
internal/status-updater/handlers/pod/gpu_reservation_pod_handler.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package pod | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/google/uuid" | ||
"github.com/run-ai/fake-gpu-operator/internal/common/constants" | ||
"github.com/run-ai/fake-gpu-operator/internal/status-updater/util" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
func (p *PodHandler) handleGpuReservationPodAddition(pod *v1.Pod) error { | ||
if !util.IsGpuReservationPod(pod) { | ||
return nil | ||
} | ||
|
||
err := p.setReservationPodGpuIdxAnnotation(pod) | ||
if err != nil { | ||
return fmt.Errorf("failed to set GPU index annotation for reservation pod %s: %w", pod.Name, err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (p *PodHandler) setReservationPodGpuIdxAnnotation(pod *v1.Pod) error { | ||
annotationKey := constants.ReservationPodGpuIdxAnnotation | ||
annotationVal := fmt.Sprintf("GPU-%s", uuid.NewString()) | ||
patch := []byte(fmt.Sprintf(`{"metadata": {"annotations": {"%s": "%s"}}}`, annotationKey, annotationVal)) | ||
|
||
_, err := p.kubeClient.CoreV1().Pods(pod.Namespace).Patch(context.TODO(), pod.Name, types.MergePatchType, patch, metav1.PatchOptions{}) | ||
if err != nil { | ||
return fmt.Errorf("failed to update pod %s: %w", pod.Name, err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters