Skip to content

Commit

Permalink
p
Browse files Browse the repository at this point in the history
Signed-off-by: kevin <[email protected]>
  • Loading branch information
khluu committed Sep 24, 2024
1 parent a315f66 commit 9e52954
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions scripts/pipeline_generator/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
KUBERNETES_PLUGIN_NAME = "kubernetes"

class DockerPluginConfig(BaseModel):
"""
Configuration for Docker plugin running in a Buildkite step.
The specification is based on:
https://github.com/buildkite-plugins/docker-buildkite-plugin?tab=readme-ov-file#configuration
"""
image: str = ""
always_pull: bool = Field(default=True, alias="always-pull")
propagate_environment: bool = Field(default=True, alias="propagate-environment")
Expand All @@ -25,6 +30,9 @@ class DockerPluginConfig(BaseModel):
]

class KubernetesPodContainerConfig(BaseModel):
"""
Configuration for a container running in a Kubernetes pod.
"""
image: str
command: List[str]
resources: Dict[str, Dict[str, int]]
Expand Down Expand Up @@ -52,6 +60,9 @@ class KubernetesPodContainerConfig(BaseModel):
)

class KubernetesPodSpec(BaseModel):
"""
Configuration for a Kubernetes pod running in a Buildkite step.
"""
containers: List[KubernetesPodContainerConfig]
priority_class_name: str = Field(default="ci", alias="priorityClassName")
node_selector: Dict[str, Any] = Field(
Expand All @@ -66,13 +77,16 @@ class KubernetesPodSpec(BaseModel):
)

class KubernetesPluginConfig(BaseModel):
"""
Configuration for Kubernetes plugin running in a Buildkite step.
"""
pod_spec: KubernetesPodSpec = Field(alias="podSpec")

def get_kubernetes_plugin_config(docker_image_path: str, test_bash_command: List[str], num_gpus: int) -> Dict:
def get_kubernetes_plugin_config(container_image: str, test_bash_command: List[str], num_gpus: int) -> Dict:
pod_spec = KubernetesPodSpec(
containers=[
KubernetesPodContainerConfig(
image=docker_image_path,
image=container_image,
command=[" ".join(test_bash_command)],
resources={"limits": {"nvidia.com/gpu": num_gpus}}
)
Expand All @@ -87,4 +101,4 @@ def get_docker_plugin_config(docker_image_path: str, test_bash_command: List[str
)
if no_gpu:
docker_plugin_config.gpus = None
return {DOCKER_PLUGIN_NAME: docker_plugin_config.dict(exclude_none=True, by_alias=True)}
return {DOCKER_PLUGIN_NAME: docker_plugin_config.dict(exclude_none=True, by_alias=True)}

0 comments on commit 9e52954

Please sign in to comment.