Skip to content

Commit 44e5a26

Browse files
committed
Change Default namespace logic to use user's current namespace
Signed-off-by: Anish Asthana <[email protected]>
1 parent 45aae2a commit 44e5a26

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/codeflare_sdk/cluster/cluster.py

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ def create_app_wrapper(self):
6363
Called upon cluster object creation, creates an AppWrapper yaml based on
6464
the specifications of the ClusterConfiguration.
6565
"""
66+
67+
if self.config.namespace is None:
68+
self.config.namespace = oc.get_project_name()
69+
if type(self.config.namespace) is not str:
70+
raise TypeError(
71+
f"Namespace {self.config.namespace} is of type {type(self.config.namespace)}. Check your Kubernetes Authentication."
72+
)
73+
6674
name = self.config.name
6775
namespace = self.config.namespace
6876
min_cpu = self.config.min_cpus

src/codeflare_sdk/cluster/config.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from dataclasses import dataclass, field
2222
from .auth import Authentication
2323
import pathlib
24+
import openshift
2425

2526
dir = pathlib.Path(__file__).parent.parent.resolve()
2627

@@ -33,7 +34,7 @@ class ClusterConfiguration:
3334
"""
3435

3536
name: str
36-
namespace: str = "default"
37+
namespace: str = None
3738
head_info: list = field(default_factory=list)
3839
machine_types: list = field(default_factory=list) # ["m4.xlarge", "g4dn.xlarge"]
3940
min_cpus: int = 1

tests/unit_test.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,20 @@ def test_cluster_creation():
240240
return cluster
241241

242242

243+
def test_default_cluster_creation(mocker):
244+
mocker.patch("openshift.get_project_name", return_value="opendatahub")
245+
default_config = ClusterConfiguration(
246+
name="unit-test-default-cluster",
247+
)
248+
cluster = Cluster(default_config)
249+
250+
assert cluster.app_wrapper_yaml == "unit-test-default-cluster.yaml"
251+
assert cluster.app_wrapper_name == "unit-test-default-cluster"
252+
assert cluster.config.namespace == "opendatahub"
253+
254+
return cluster
255+
256+
243257
def arg_check_apply_effect(*args):
244258
assert args[0] == "apply"
245259
assert args[1] == ["-f", "unit-test-cluster.yaml"]
@@ -1673,7 +1687,6 @@ def test_DDPJobDefinition_dry_run():
16731687
assert type(ddp_job._scheduler) == type(str())
16741688

16751689
assert ddp_job.request.app_id.startswith("test")
1676-
assert ddp_job.request.working_dir.startswith("/tmp/torchx_workspace")
16771690
assert ddp_job.request.cluster_name == "unit-test-cluster"
16781691
assert ddp_job.request.requirements == "test"
16791692

0 commit comments

Comments
 (0)