Skip to content

Commit

Permalink
Merge done
Browse files Browse the repository at this point in the history
  • Loading branch information
shouhanzen committed Feb 13, 2024
1 parent 4c00fdb commit 14e5473
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 55 deletions.
15 changes: 14 additions & 1 deletion src/dsmlp/app/id_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,17 @@ def validate_security_context(

if securityContext.runAsGroup is not None and securityContext.runAsGroup not in allowed_teams:
raise ValidationFailure(
f"spec.{context}.securityContext: gid must be in range {allowed_teams}")
f"spec.{context}.securityContext: gid must be in range {allowed_teams}")

def admission_response(self, uid, allowed, message):
return {
"apiVersion": "admission.k8s.io/v1",
"kind": "AdmissionReview",
"response": {
"uid": uid,
"allowed": allowed,
"status": {
"message": message
}
}
}
16 changes: 7 additions & 9 deletions src/dsmlp/app/types.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@

from dataclasses import dataclass
import json
from typing import List, Optional, Dict

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 abc import ABCMeta, abstractmethod

@dataclass_json
Expand Down Expand Up @@ -49,10 +41,16 @@ class PodSpec:
securityContext: Optional[PodSecurityContext] = None
priorityClassName: Optional[str] = None

@dataclass_json
@dataclass
class ObjectMeta:
labels: Dict[str, str]


@dataclass_json
@dataclass
class Object:
metadata: ObjectMeta
spec: PodSpec


Expand Down
20 changes: 19 additions & 1 deletion tests/app/test_gpu_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setup_method(self) -> None:
self.awsed_client = FakeAwsedClient()
self.kube_client = FakeKubeClient()

self.awsed_client.add_user('user10', UserResponse(uid=10))
self.awsed_client.add_user('user10', UserResponse(uid=10, enrollments=[]))
self.awsed_client.add_teams('user10', ListTeamsResponse(
teams=[TeamJson(gid=1000)]
))
Expand All @@ -31,6 +31,9 @@ def test_no_gpus_requested(self):
},
"namespace": "user10",
"object": {
"metadata": {
"labels": {}
},
"kind": "Pod",
"spec": {
"containers": [{}]
Expand Down Expand Up @@ -58,6 +61,9 @@ def test_quota_not_reached(self):
},
"namespace": "user10",
"object": {
"metadata": {
"labels": {}
},
"kind": "Pod",
"spec": {
"containers": [{
Expand Down Expand Up @@ -91,6 +97,9 @@ def test_quota_exceeded(self):
},
"namespace": "user10",
"object": {
"metadata": {
"labels": {}
},
"kind": "Pod",
"spec": {
"containers": [{
Expand Down Expand Up @@ -126,6 +135,9 @@ def test_sum_exceeded(self):
},
"namespace": "user10",
"object": {
"metadata": {
"labels": {}
},
"kind": "Pod",
"spec": {
"containers": [{
Expand Down Expand Up @@ -161,6 +173,9 @@ def test_low_priority(self):
},
"namespace": "user10",
"object": {
"metadata": {
"labels": {}
},
"kind": "Pod",
"spec": {
"containers": [{
Expand Down Expand Up @@ -198,6 +213,9 @@ def test_limit_exceeded(self):
},
"namespace": "user10",
"object": {
"metadata": {
"labels": {}
},
"kind": "Pod",
"spec": {
"containers": [{
Expand Down
Loading

0 comments on commit 14e5473

Please sign in to comment.