-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55ff20e
commit 8a4a2ea
Showing
9 changed files
with
72 additions
and
10 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
GPU_LABEL = "nvidia.com/gpu" | ||
GPU_LIMIT_ANNOTATION = 'gpu-limit' |
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,37 @@ | ||
from dataclasses import dataclass | ||
import json | ||
from typing import List, Optional | ||
|
||
from dataclasses_json import dataclass_json | ||
from dsmlp.plugin.awsed import AwsedClient, UnsuccessfulRequest | ||
from dsmlp.plugin.console import Console | ||
from dsmlp.plugin.course import ConfigProvider | ||
from dsmlp.plugin.kube import KubeClient, NotFound | ||
import jsonify | ||
|
||
from dsmlp.plugin.logger import Logger | ||
from dsmlp.app.types import * | ||
from dsmlp.app.config import * | ||
|
||
|
||
class GPUValidator(ComponentValidator): | ||
|
||
def __init__(self, kube: KubeClient, logger: Logger) -> None: | ||
self.kube = kube | ||
self.logger = logger | ||
|
||
def validate_pod(self, request: Request): | ||
""" | ||
Validate pods for namespaces with the 'k8s-sync' label | ||
""" | ||
|
||
namespace = self.kube.get_namespace(request.namespace) | ||
curr_gpus = self.kube.get_gpus_in_namespace(request.namespace) | ||
|
||
requested_gpus = 0 | ||
for container in request.object.spec.containers: | ||
if container.resources is not None and GPU_LABEL in container.resources.requests: | ||
requested_gpus += container.resources.requests[GPU_LABEL] | ||
|
||
if requested_gpus + curr_gpus > namespace.gpu_quota: | ||
raise ValidationFailure(f"GPU quota exceeded. Requested {requested_gpus} but with {curr_gpus} already in use, the quota of {namespace.gpu_quota} would be exceeded.") |
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
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