Skip to content

Commit 883066e

Browse files
committed
change: use current namespace when not specified
1 parent d6bb158 commit 883066e

File tree

9 files changed

+369
-11
lines changed

9 files changed

+369
-11
lines changed

carson.yaml

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
apiVersion: mcad.ibm.com/v1beta1
2+
kind: AppWrapper
3+
metadata:
4+
name: carson
5+
namespace: default
6+
spec:
7+
priority: 9
8+
resources:
9+
GenericItems:
10+
- custompodresources:
11+
- limits:
12+
cpu: 2
13+
memory: 8G
14+
nvidia.com/gpu: 0
15+
replicas: 1
16+
requests:
17+
cpu: 2
18+
memory: 8G
19+
nvidia.com/gpu: 0
20+
- limits:
21+
cpu: 1
22+
memory: 2G
23+
nvidia.com/gpu: 0
24+
replicas: 1
25+
requests:
26+
cpu: 1
27+
memory: 2G
28+
nvidia.com/gpu: 0
29+
generictemplate:
30+
apiVersion: ray.io/v1alpha1
31+
kind: RayCluster
32+
metadata:
33+
labels:
34+
appwrapper.mcad.ibm.com: carson
35+
controller-tools.k8s.io: '1.0'
36+
name: carson
37+
namespace: default
38+
spec:
39+
autoscalerOptions:
40+
idleTimeoutSeconds: 60
41+
imagePullPolicy: Always
42+
resources:
43+
limits:
44+
cpu: 500m
45+
memory: 512Mi
46+
requests:
47+
cpu: 500m
48+
memory: 512Mi
49+
upscalingMode: Default
50+
enableInTreeAutoscaling: false
51+
headGroupSpec:
52+
rayStartParams:
53+
block: 'true'
54+
dashboard-host: 0.0.0.0
55+
num-gpus: '0'
56+
serviceType: ClusterIP
57+
template:
58+
spec:
59+
containers:
60+
- env:
61+
- name: MY_POD_IP
62+
valueFrom:
63+
fieldRef:
64+
fieldPath: status.podIP
65+
- name: RAY_USE_TLS
66+
value: '0'
67+
- name: RAY_TLS_SERVER_CERT
68+
value: /home/ray/workspace/tls/server.crt
69+
- name: RAY_TLS_SERVER_KEY
70+
value: /home/ray/workspace/tls/server.key
71+
- name: RAY_TLS_CA_CERT
72+
value: /home/ray/workspace/tls/ca.crt
73+
image: quay.io/project-codeflare/ray:2.5.0-py38-cu116
74+
imagePullPolicy: Always
75+
lifecycle:
76+
preStop:
77+
exec:
78+
command:
79+
- /bin/sh
80+
- -c
81+
- ray stop
82+
name: ray-head
83+
ports:
84+
- containerPort: 6379
85+
name: gcs
86+
- containerPort: 8265
87+
name: dashboard
88+
- containerPort: 10001
89+
name: client
90+
resources:
91+
limits:
92+
cpu: 2
93+
memory: 8G
94+
nvidia.com/gpu: 0
95+
requests:
96+
cpu: 2
97+
memory: 8G
98+
nvidia.com/gpu: 0
99+
imagePullSecrets: []
100+
rayVersion: 2.1.0
101+
workerGroupSpecs:
102+
- groupName: small-group-carson
103+
maxReplicas: 1
104+
minReplicas: 1
105+
rayStartParams:
106+
block: 'true'
107+
num-gpus: '0'
108+
replicas: 1
109+
template:
110+
metadata:
111+
annotations:
112+
key: value
113+
labels:
114+
key: value
115+
spec:
116+
containers:
117+
- env:
118+
- name: MY_POD_IP
119+
valueFrom:
120+
fieldRef:
121+
fieldPath: status.podIP
122+
- name: RAY_USE_TLS
123+
value: '0'
124+
- name: RAY_TLS_SERVER_CERT
125+
value: /home/ray/workspace/tls/server.crt
126+
- name: RAY_TLS_SERVER_KEY
127+
value: /home/ray/workspace/tls/server.key
128+
- name: RAY_TLS_CA_CERT
129+
value: /home/ray/workspace/tls/ca.crt
130+
image: quay.io/project-codeflare/ray:2.5.0-py38-cu116
131+
lifecycle:
132+
preStop:
133+
exec:
134+
command:
135+
- /bin/sh
136+
- -c
137+
- ray stop
138+
name: machine-learning
139+
resources:
140+
limits:
141+
cpu: 1
142+
memory: 2G
143+
nvidia.com/gpu: 0
144+
requests:
145+
cpu: 1
146+
memory: 2G
147+
nvidia.com/gpu: 0
148+
imagePullSecrets: []
149+
initContainers:
150+
- command:
151+
- sh
152+
- -c
153+
- until nslookup $RAY_IP.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local;
154+
do echo waiting for myservice; sleep 2; done
155+
image: busybox:1.28
156+
name: init-myservice
157+
replicas: 1
158+
- generictemplate:
159+
apiVersion: route.openshift.io/v1
160+
kind: Route
161+
metadata:
162+
labels:
163+
odh-ray-cluster-service: carson-head-svc
164+
name: ray-dashboard-carson
165+
namespace: default
166+
spec:
167+
port:
168+
targetPort: dashboard
169+
to:
170+
kind: Service
171+
name: carson-head-svc
172+
replica: 1
173+
Items: []

src/codeflare_sdk/cli/codeflare_cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
import os
33

44
from codeflare_sdk.cli.cli_utils import load_auth
5+
from codeflare_sdk.cluster.cluster import get_current_namespace
56

67
cmd_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "commands"))
78

89

910
class CodeflareContext:
1011
def __init__(self):
1112
self.codeflare_path = _initialize_codeflare_folder()
13+
self.current_namespace = get_current_namespace()
1214

1315

1416
def _initialize_codeflare_folder():

src/codeflare_sdk/cli/commands/define.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ def cli():
1212

1313

1414
@cli.command()
15+
@click.pass_context
1516
@click.option("--name", type=str, required=True)
16-
@click.option("--namespace", "-n", type=str, required=True)
17+
@click.option("--namespace", "-n", type=str)
1718
@click.option("--head_info", cls=PythonLiteralOption, type=list)
1819
@click.option("--machine_types", cls=PythonLiteralOption, type=list)
1920
@click.option("--min_cpus", type=int)
@@ -29,8 +30,10 @@ def cli():
2930
@click.option("--image", type=str)
3031
@click.option("--local_interactive", type=bool)
3132
@click.option("--image_pull_secrets", cls=PythonLiteralOption, type=list)
32-
def raycluster(**kwargs):
33+
def raycluster(ctx, **kwargs):
3334
"""Define a RayCluster with parameter specifications"""
3435
filtered_kwargs = {k: v for k, v in kwargs.items() if v is not None}
36+
if "namespace" not in filtered_kwargs.keys():
37+
filtered_kwargs["namespace"] = ctx.obj.current_namespace
3538
clusterConfig = ClusterConfiguration(**filtered_kwargs)
3639
Cluster(clusterConfig) # Creates yaml file

src/codeflare_sdk/cli/commands/delete.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ def cli():
1212

1313

1414
@cli.command()
15+
@click.pass_context
1516
@click.argument("name", type=str)
16-
@click.option("--namespace", type=str, required=True)
17-
def raycluster(name, namespace):
17+
@click.option("--namespace", type=str)
18+
def raycluster(ctx, name, namespace):
1819
"""
1920
Delete a specified RayCluster from the Kubernetes cluster
2021
"""
22+
namespace = namespace or ctx.obj.current_namespace
2123
try:
2224
cluster = get_cluster(name, namespace)
2325
except FileNotFoundError:

src/codeflare_sdk/cli/commands/details.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ def cli():
1111

1212
@cli.command()
1313
@click.argument("name", type=str)
14-
@click.option("--namespace", type=str, required=True)
14+
@click.option("--namespace", type=str)
1515
@click.pass_context
1616
def raycluster(ctx, name, namespace):
1717
"""Get the details of a specified RayCluster"""
18+
namespace = namespace or ctx.obj.current_namespace
1819
try:
1920
cluster = get_cluster(name, namespace)
2021
except FileNotFoundError:

src/codeflare_sdk/cli/commands/list.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def raycluster(ctx, namespace, all):
2323
if all and namespace:
2424
click.echo("--all and --namespace are mutually exclusive")
2525
return
26-
if not all and not namespace:
27-
click.echo("You must specify either --namespace or --all")
28-
return
26+
namespace = namespace or ctx.obj.current_namespace
2927
if not all:
3028
list_all_clusters(namespace)
3129
return

src/codeflare_sdk/cli/commands/status.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ def cli():
1111

1212
@cli.command()
1313
@click.argument("name", type=str)
14-
@click.option("--namespace", type=str, required=True)
14+
@click.option("--namespace", type=str)
1515
@click.pass_context
1616
def raycluster(ctx, name, namespace):
1717
"""Get the status of a specified RayCluster"""
18+
namespace = namespace or ctx.obj.current_namespace
1819
try:
1920
cluster = get_cluster(name, namespace)
2021
except FileNotFoundError:

0 commit comments

Comments
 (0)