Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve K8s Comments (Part 2) #197

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion conf/common/system/kubernetes_cluster.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ kube_config_path = ""

install_path = "./install"
output_path = "./results"
default_image = "ubuntu:22.04"
default_namespace = "default"

[global_env_vars]
Expand Down
4 changes: 4 additions & 0 deletions conf/common/test_template/sleep.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ name = "Sleep"
[cmd_args.seconds]
type = "int"
default = "5"

[cmd_args.docker_image_url]
type = "str"
default = "ubuntu:22.04"
12 changes: 2 additions & 10 deletions src/cloudai/runner/kubernetes/kubernetes_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,25 @@ class KubernetesJob(BaseJob):
mode (str): The mode of the job (e.g., 'run', 'dry-run').
system (System): The system in which the job is running.
test_run (TestRun): The test instance associated with this job.
namespace (str): The namespace of the job.
name (str): The name of the job.
kind (str): The kind of the job.
output_path (Path): The path where the job's output is stored.
"""

def __init__(
self, mode: str, system: System, test_run: TestRun, namespace: str, name: str, kind: str, output_path: Path
):
def __init__(self, mode: str, system: System, test_run: TestRun, name: str, kind: str, output_path: Path):
"""
Initialize a KubernetesJob instance.

Args:
mode (str): The mode of the job (e.g., 'run', 'dry-run').
system (System): The system in which the job is running.
test_run (TestRun): The test instance associated with this job.
namespace (str): The namespace of the job.
name (str): The name of the job.
kind (str): The kind of the job.
output_path (Path): The path where the job's output is stored.
"""
super().__init__(mode, system, test_run, output_path)
self.id = name
self.namespace = namespace
self.name = name
self.kind = kind

Expand All @@ -62,7 +57,4 @@ def __repr__(self) -> str:
Returns
str: String representation of the job.
"""
return (
f"KubernetesJob(name={self.name}, namespace={self.namespace}, test={self.test_run.test.name}, "
f"kind={self.kind})"
)
return f"KubernetesJob(name={self.name}, test={self.test_run.test.name}, kind={self.kind})"
13 changes: 6 additions & 7 deletions src/cloudai/runner/kubernetes/kubernetes_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ def _submit_test(self, tr: TestRun) -> KubernetesJob:
job_spec = tr.test.gen_json(job_output_path, job_name, tr.time_limit, tr.num_nodes, tr.nodes)
job_kind = job_spec.get("kind", "").lower()
logging.info(f"Generated JSON string for test {tr.test.section_name}: {job_spec}")
job_namespace = ""

if self.mode == "run":
k8s_system: KubernetesSystem = cast(KubernetesSystem, self.system)
job_name, job_namespace = k8s_system.create_job(job_spec)
job_name = k8s_system.create_job(job_spec)

return KubernetesJob(self.mode, self.system, tr, job_namespace, job_name, job_kind, job_output_path)
return KubernetesJob(self.mode, self.system, tr, job_name, job_kind, job_output_path)

async def job_completion_callback(self, job: BaseJob) -> None:
"""
Expand All @@ -59,8 +58,8 @@ async def job_completion_callback(self, job: BaseJob) -> None:
"""
k8s_system: KubernetesSystem = cast(KubernetesSystem, self.system)
k_job = cast(KubernetesJob, job)
k8s_system.store_logs_for_job(k_job.namespace, k_job.name, k_job.output_path)
k8s_system.delete_job(k_job.namespace, k_job.name, k_job.kind)
k8s_system.store_logs_for_job(k_job.name, k_job.output_path)
k8s_system.delete_job(k_job.name, k_job.kind)

def kill_job(self, job: BaseJob) -> None:
"""
Expand All @@ -71,5 +70,5 @@ def kill_job(self, job: BaseJob) -> None:
"""
k8s_system: KubernetesSystem = cast(KubernetesSystem, self.system)
k_job = cast(KubernetesJob, job)
k8s_system.store_logs_for_job(k_job.namespace, k_job.name, k_job.output_path)
k8s_system.delete_job(k_job.namespace, k_job.name, k_job.kind)
k8s_system.store_logs_for_job(k_job.name, k_job.output_path)
k8s_system.delete_job(k_job.name, k_job.kind)
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def gen_json(
{
"args": ["sleep " + sec],
"command": ["/bin/bash", "-c"],
"image": kubernetes_system.default_image,
"image": self.final_cmd_args["docker_image_url"],
"name": "task",
}
],
Expand Down
Loading