Skip to content

Commit d670950

Browse files
committed
removing is_manged_by_kueue logic as it needs to be reworked
1 parent 85658d5 commit d670950

File tree

6 files changed

+144
-262
lines changed

6 files changed

+144
-262
lines changed

batchtools/bd.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
import sys
22
import argparse
33
from typing import cast
4+
45
import openshift_client as oc
6+
57
from .basecommand import Command, override
68
from .basecommand import SubParserFactory
7-
from .helpers import oc_delete, is_kueue_managed_job
9+
from .helpers import oc_delete
810

911

1012
class DeleteJobsCommand(Command):
1113
"""
1214
batchtools bd [job-name [job-name ...]]
1315
14-
Delete specified Kueue-managed GPU jobs, or all such jobs if none are specified.
15-
16-
Description:
17-
Deletes only those Jobs that are both:
18-
- named like your GPU jobs (name starts with 'job-'), and
19-
- detected as Kueue-managed (via labels/Workload linkage).
16+
Delete specified Jobs, or all Jobs if none are specified.
2017
"""
2118

2219
name: str = "bd"
23-
help: str = "Delete specified Kueue-managed GPU jobs, or all if none are specified"
20+
help: str = "Delete specified Jobs, or all if none are specified"
2421

2522
@classmethod
2623
@override
@@ -29,43 +26,34 @@ def build_parser(cls, subparsers: SubParserFactory):
2926
p.add_argument(
3027
"job_names",
3128
nargs="*",
32-
help="Optional list of job names to delete (must be Kueue-managed)",
29+
help="Optional list of job names to delete",
3330
)
3431
return p
3532

3633
@staticmethod
3734
@override
3835
def run(args: argparse.Namespace):
3936
args = cast(DeleteJobsCommand, args)
37+
4038
try:
4139
jobs = oc.selector("jobs").objects()
4240
if not jobs:
4341
print("No jobs found.")
4442
return
4543

46-
gpu_jobs = [
47-
job for job in jobs if job.model.metadata.name.startswith("job-")
48-
]
49-
50-
# only want to delete kueue jobs so filter for kueue jobs
51-
kueue_gpu_jobs = [job for job in gpu_jobs if is_kueue_managed_job(job)]
52-
53-
if not kueue_gpu_jobs:
54-
print("No Kueue-managed GPU jobs to delete.")
55-
return
56-
5744
if args.job_names:
58-
# if jobs are specified, only delete specified jobs
59-
allowed = {job.model.metadata.name for job in kueue_gpu_jobs}
45+
# delete only specified jobs
46+
existing = {job.model.metadata.name for job in jobs}
6047
for name in args.job_names:
61-
if name not in allowed:
62-
print(f"{name} is not a Kueue-managed GPU job; skipping.")
48+
if name not in existing:
49+
print(f"{name} does not exist; skipping.")
6350
continue
6451
oc_delete("job", name)
6552
print(f"Deleted job: {name}")
6653
else:
67-
print("No job names provided -> deleting all Kueue-managed GPU jobs:\n")
68-
for job in kueue_gpu_jobs:
54+
# delete all jobs
55+
print("No job names provided -> deleting ALL jobs:\n")
56+
for job in jobs:
6957
name = job.model.metadata.name
7058
oc_delete("job", name)
7159
print(f"Deleted job: {name}")

batchtools/bj.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import openshift_client as oc
66

77
from .basecommand import Command
8-
from .helpers import is_kueue_managed_job
98

109

1110
class ListJobsCommand(Command):
@@ -38,8 +37,7 @@ def run(args: argparse.Namespace):
3837

3938
print(f"Found {len(jobs)} job(s):\n")
4039
for job in jobs:
41-
if is_kueue_managed_job(job):
42-
print(f"- {job.model.metadata.name}")
40+
print(f"- {job.model.metadata.name}")
4341

4442
except oc.OpenShiftPythonException as e:
4543
sys.exit(f"Error occurred while retrieving jobs: {e}")

batchtools/helpers.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,40 @@ def oc_delete(obj_type: str, obj_name: str) -> None:
2929
print(f"Error occurred while deleting {obj_type}/{obj_name}: {e}")
3030

3131

32-
def is_kueue_managed_job(job_obj) -> bool:
33-
"""
34-
Returns True if the Job is managed by Kueue.
35-
Checks:
36-
1) Job has label 'kueue.x-k8s.io/queue-name'
37-
2) A Workload exists that either:
38-
- has an ownerReference pointing to this Job, or
39-
- has label job-name=<job-name>
40-
"""
41-
try:
42-
md = job_obj.model.metadata
43-
labels = getattr(md, "labels", {}) or {}
44-
if "kueue.x-k8s.io/queue-name" in labels:
45-
return True
32+
# def is_kueue_managed_job(job_obj) -> bool:
33+
# """
34+
# Returns True if the Job is managed by Kueue.
35+
# Checks:
36+
# 1) Job has label 'kueue.x-k8s.io/queue-name'
37+
# 2) A Workload exists that either:
38+
# - has an ownerReference pointing to this Job, or
39+
# - has label job-name=<job-name>
40+
# """
41+
# try:
42+
# md = job_obj.model.metadata
43+
# labels = getattr(md, "labels", {}) or {}
44+
# if "kueue.x-k8s.io/queue-name" in labels:
45+
# return True
4646

47-
job_name = md.name
48-
try:
49-
workloads = oc.selector("workloads").objects()
50-
except oc.OpenShiftPythonException:
51-
workloads = []
47+
# job_name = md.name
48+
# try:
49+
# workloads = oc.selector("workloads").objects()
50+
# except oc.OpenShiftPythonException:
51+
# workloads = []
5252

53-
for wl in workloads:
54-
wl_md = wl.model.metadata
55-
owners = getattr(wl_md, "ownerReferences", []) or []
56-
for o in owners:
57-
if (
58-
getattr(o, "kind", "") == "Job"
59-
and getattr(o, "name", "") == job_name
60-
):
61-
return True
62-
wl_labels = getattr(wl_md, "labels", {}) or {}
63-
if wl_labels.get("job-name") == job_name:
64-
return True
65-
except Exception:
66-
return False
53+
# for wl in workloads:
54+
# wl_md = wl.model.metadata
55+
# owners = getattr(wl_md, "ownerReferences", []) or []
56+
# for o in owners:
57+
# if (
58+
# getattr(o, "kind", "") == "Job"
59+
# and getattr(o, "name", "") == job_name
60+
# ):
61+
# return True
62+
# wl_labels = getattr(wl_md, "labels", {}) or {}
63+
# if wl_labels.get("job-name") == job_name:
64+
# return True
65+
# except Exception:
66+
# return False
6767

68-
return False
68+
# return False

bt-test.sh

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)