Skip to content

Commit 3f0583a

Browse files
committed
Remove oc client and add helper functions
1 parent a8e9156 commit 3f0583a

File tree

4 files changed

+71
-64
lines changed

4 files changed

+71
-64
lines changed

Diff for: demo-notebooks/interactive/local_interactive.ipynb

+31-57
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,12 @@
3232
},
3333
{
3434
"cell_type": "code",
35-
"execution_count": 2,
35+
"execution_count": null,
3636
"id": "4364ac2e-dd10-4d30-ba66-12708daefb3f",
3737
"metadata": {
3838
"tags": []
3939
},
40-
"outputs": [
41-
{
42-
"name": "stdout",
43-
"output_type": "stream",
44-
"text": [
45-
"Written to: hfgputest-1.yaml\n"
46-
]
47-
}
48-
],
40+
"outputs": [],
4941
"source": [
5042
"# Create our cluster and submit appwrapper\n",
5143
"namespace = \"default\"\n",
@@ -89,7 +81,6 @@
8981
]
9082
},
9183
{
92-
"attachments": {},
9384
"cell_type": "markdown",
9485
"id": "12eef53c",
9586
"metadata": {},
@@ -99,38 +90,21 @@
9990
},
10091
{
10192
"cell_type": "code",
102-
"execution_count": 11,
93+
"execution_count": null,
10394
"id": "cf1b749e-2335-42c2-b673-26768ec9895d",
10495
"metadata": {},
105-
"outputs": [
106-
{
107-
"name": "stdout",
108-
"output_type": "stream",
109-
"text": [
110-
"rayclient-hfgputest-1-default.apps.tedbig412.cp.fyre.ibm.com\n"
111-
]
112-
}
113-
],
96+
"outputs": [],
11497
"source": [
115-
"import openshift as oc\n",
11698
"from codeflare_sdk.utils import generate_cert\n",
11799
"\n",
118100
"if local_interactive:\n",
119101
" generate_cert.generate_tls_cert(cluster_name, namespace)\n",
120-
" generate_cert.export_env(cluster_name, namespace)\n",
121-
"\n",
122-
"with oc.project(namespace):\n",
123-
" routes=oc.selector(\"route\").objects()\n",
124-
" rayclient_url=\"\"\n",
125-
" for r in routes:\n",
126-
" if \"rayclient\" in r.name():\n",
127-
" rayclient_url=r.model.spec.host\n",
128-
"print(rayclient_url)"
102+
" generate_cert.export_env(cluster_name, namespace)"
129103
]
130104
},
131105
{
132106
"cell_type": "code",
133-
"execution_count": 12,
107+
"execution_count": 6,
134108
"id": "9483bb98-33b3-4beb-9b15-163d7e76c1d7",
135109
"metadata": {
136110
"scrolled": true,
@@ -141,15 +115,15 @@
141115
"name": "stderr",
142116
"output_type": "stream",
143117
"text": [
144-
"2023-05-31 14:12:37,816\tINFO client_builder.py:251 -- Passing the following kwargs to ray.init() on the server: logging_level\n",
145-
"2023-05-31 14:12:37,820\tDEBUG worker.py:378 -- client gRPC channel state change: ChannelConnectivity.IDLE\n",
146-
"2023-05-31 14:12:38,034\tDEBUG worker.py:378 -- client gRPC channel state change: ChannelConnectivity.CONNECTING\n",
147-
"2023-05-31 14:12:38,246\tDEBUG worker.py:378 -- client gRPC channel state change: ChannelConnectivity.READY\n",
148-
"2023-05-31 14:12:38,290\tDEBUG worker.py:807 -- Pinging server.\n",
149-
"2023-05-31 14:12:40,521\tDEBUG worker.py:640 -- Retaining 00ffffffffffffffffffffffffffffffffffffff0100000001000000\n",
150-
"2023-05-31 14:12:40,523\tDEBUG worker.py:564 -- Scheduling task get_dashboard_url 0 b'\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x01\\x00\\x00\\x00\\x01\\x00\\x00\\x00'\n",
151-
"2023-05-31 14:12:40,535\tDEBUG worker.py:640 -- Retaining c8ef45ccd0112571ffffffffffffffffffffffff0100000001000000\n",
152-
"2023-05-31 14:12:41,379\tDEBUG worker.py:636 -- Releasing c8ef45ccd0112571ffffffffffffffffffffffff0100000001000000\n"
118+
"2023-06-27 19:14:16,088\tINFO client_builder.py:251 -- Passing the following kwargs to ray.init() on the server: logging_level\n",
119+
"2023-06-27 19:14:16,100\tDEBUG worker.py:378 -- client gRPC channel state change: ChannelConnectivity.IDLE\n",
120+
"2023-06-27 19:14:16,308\tDEBUG worker.py:378 -- client gRPC channel state change: ChannelConnectivity.CONNECTING\n",
121+
"2023-06-27 19:14:16,434\tDEBUG worker.py:378 -- client gRPC channel state change: ChannelConnectivity.READY\n",
122+
"2023-06-27 19:14:16,436\tDEBUG worker.py:807 -- Pinging server.\n",
123+
"2023-06-27 19:14:18,634\tDEBUG worker.py:640 -- Retaining 00ffffffffffffffffffffffffffffffffffffff0100000001000000\n",
124+
"2023-06-27 19:14:18,635\tDEBUG worker.py:564 -- Scheduling task get_dashboard_url 0 b'\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x01\\x00\\x00\\x00\\x01\\x00\\x00\\x00'\n",
125+
"2023-06-27 19:14:18,645\tDEBUG worker.py:640 -- Retaining c8ef45ccd0112571ffffffffffffffffffffffff0100000001000000\n",
126+
"2023-06-27 19:14:19,454\tDEBUG worker.py:636 -- Releasing c8ef45ccd0112571ffffffffffffffffffffffff0100000001000000\n"
153127
]
154128
},
155129
{
@@ -190,18 +164,18 @@
190164
" </tr>\n",
191165
" <tr>\n",
192166
" <td style=\"text-align: left\"><b>Dashboard:</b></td>\n",
193-
" <td style=\"text-align: left\"><b><a href=\"http://10.254.12.141:8265\" target=\"_blank\">http://10.254.12.141:8265</a></b></td>\n",
167+
" <td style=\"text-align: left\"><b><a href=\"http://10.254.20.41:8265\" target=\"_blank\">http://10.254.20.41:8265</a></b></td>\n",
194168
"</tr>\n",
195169
"\n",
196170
" </table>\n",
197171
" </div>\n",
198172
"</div>\n"
199173
],
200174
"text/plain": [
201-
"ClientContext(dashboard_url='10.254.12.141:8265', python_version='3.8.13', ray_version='2.1.0', ray_commit='23f34d948dae8de9b168667ab27e6cf940b3ae85', protocol_version='2022-10-05', _num_clients=1, _context_to_restore=<ray.util.client._ClientContext object at 0x10e5d2bb0>)"
175+
"ClientContext(dashboard_url='10.254.20.41:8265', python_version='3.8.13', ray_version='2.1.0', ray_commit='23f34d948dae8de9b168667ab27e6cf940b3ae85', protocol_version='2022-10-05', _num_clients=1, _context_to_restore=<ray.util.client._ClientContext object at 0x108ca2730>)"
202176
]
203177
},
204-
"execution_count": 12,
178+
"execution_count": 6,
205179
"metadata": {},
206180
"output_type": "execute_result"
207181
}
@@ -210,12 +184,12 @@
210184
"import ray\n",
211185
"\n",
212186
"ray.shutdown()\n",
213-
"ray.init(address=f\"ray://{rayclient_url}\", logging_level=\"DEBUG\")"
187+
"ray.init(address=cluster.local_client_url(), logging_level=\"DEBUG\")"
214188
]
215189
},
216190
{
217191
"cell_type": "code",
218-
"execution_count": 13,
192+
"execution_count": 7,
219193
"id": "3436eb4a-217c-4109-a3c3-309fda7e2442",
220194
"metadata": {},
221195
"outputs": [],
@@ -239,7 +213,7 @@
239213
},
240214
{
241215
"cell_type": "code",
242-
"execution_count": 14,
216+
"execution_count": 8,
243217
"id": "5cca1874-2be3-4631-ae48-9adfa45e3af3",
244218
"metadata": {
245219
"scrolled": true,
@@ -250,8 +224,8 @@
250224
"name": "stderr",
251225
"output_type": "stream",
252226
"text": [
253-
"2023-05-31 14:13:29,868\tDEBUG worker.py:640 -- Retaining 00ffffffffffffffffffffffffffffffffffffff0100000002000000\n",
254-
"2023-05-31 14:13:29,870\tDEBUG worker.py:564 -- Scheduling task heavy_calculation 0 b'\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x01\\x00\\x00\\x00\\x02\\x00\\x00\\x00'\n"
227+
"2023-06-27 19:14:28,222\tDEBUG worker.py:640 -- Retaining 00ffffffffffffffffffffffffffffffffffffff0100000002000000\n",
228+
"2023-06-27 19:14:28,222\tDEBUG worker.py:564 -- Scheduling task heavy_calculation 0 b'\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x01\\x00\\x00\\x00\\x02\\x00\\x00\\x00'\n"
255229
]
256230
}
257231
],
@@ -261,16 +235,16 @@
261235
},
262236
{
263237
"cell_type": "code",
264-
"execution_count": 15,
238+
"execution_count": 9,
265239
"id": "01172c29-e8bf-41ef-8db5-eccb07906111",
266240
"metadata": {},
267241
"outputs": [
268242
{
269243
"name": "stderr",
270244
"output_type": "stream",
271245
"text": [
272-
"2023-05-31 14:13:32,643\tDEBUG worker.py:640 -- Retaining 16310a0f0a45af5cffffffffffffffffffffffff0100000001000000\n",
273-
"2023-05-31 14:13:34,677\tDEBUG worker.py:439 -- Internal retry for get [ClientObjectRef(16310a0f0a45af5cffffffffffffffffffffffff0100000001000000)]\n"
246+
"2023-06-27 19:14:29,202\tDEBUG worker.py:640 -- Retaining 16310a0f0a45af5cffffffffffffffffffffffff0100000001000000\n",
247+
"2023-06-27 19:14:31,224\tDEBUG worker.py:439 -- Internal retry for get [ClientObjectRef(16310a0f0a45af5cffffffffffffffffffffffff0100000001000000)]\n"
274248
]
275249
},
276250
{
@@ -279,7 +253,7 @@
279253
"1789.4644387076714"
280254
]
281255
},
282-
"execution_count": 15,
256+
"execution_count": 9,
283257
"metadata": {},
284258
"output_type": "execute_result"
285259
}
@@ -290,18 +264,18 @@
290264
},
291265
{
292266
"cell_type": "code",
293-
"execution_count": 16,
267+
"execution_count": 10,
294268
"id": "9e79b547-a457-4232-b77d-19147067b972",
295269
"metadata": {},
296270
"outputs": [
297271
{
298272
"name": "stderr",
299273
"output_type": "stream",
300274
"text": [
301-
"2023-05-31 14:13:37,659\tDEBUG dataclient.py:287 -- Got unawaited response connection_cleanup {\n",
275+
"2023-06-27 19:14:33,161\tDEBUG dataclient.py:287 -- Got unawaited response connection_cleanup {\n",
302276
"}\n",
303277
"\n",
304-
"2023-05-31 14:13:38,681\tDEBUG dataclient.py:278 -- Shutting down data channel.\n"
278+
"2023-06-27 19:14:34,460\tDEBUG dataclient.py:278 -- Shutting down data channel.\n"
305279
]
306280
}
307281
],
@@ -312,7 +286,7 @@
312286
},
313287
{
314288
"cell_type": "code",
315-
"execution_count": 17,
289+
"execution_count": 11,
316290
"id": "2c198f1f-68bf-43ff-a148-02b5cb000ff2",
317291
"metadata": {},
318292
"outputs": [],

Diff for: src/codeflare_sdk/cluster/cluster.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
RayCluster,
3535
RayClusterStatus,
3636
)
37-
3837
from kubernetes import client, config
3938

4039
import yaml
@@ -344,6 +343,13 @@ def from_k8_cluster_object(rc):
344343
)
345344
return Cluster(cluster_config)
346345

346+
def local_client_url(self):
347+
if self.config.local_interactive == True:
348+
ingress_domain = _get_ingress_domain()
349+
return f"ray://rayclient-{self.config.name}-{self.config.namespace}.{ingress_domain}"
350+
else:
351+
return "None"
352+
347353

348354
def list_all_clusters(namespace: str, print_to_console: bool = True):
349355
"""
@@ -402,6 +408,13 @@ def get_cluster(cluster_name: str, namespace: str = "default"):
402408

403409

404410
# private methods
411+
def _get_ingress_domain():
412+
config.load_kube_config()
413+
api_client = client.CustomObjectsApi()
414+
ingress = api_client.get_cluster_custom_object(
415+
"config.openshift.io", "v1", "ingresses", "cluster"
416+
)
417+
return ingress["spec"]["domain"]
405418

406419

407420
def _kube_api_error_handling(e: Exception): # pragma: no cover

Diff for: src/codeflare_sdk/utils/generate_yaml.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import sys
2222
import argparse
2323
import uuid
24-
import openshift as oc
24+
from kubernetes import client, config
2525

2626

2727
def read_template(template):
@@ -239,12 +239,13 @@ def enable_local_interactive(resources, cluster_name, namespace):
239239
][0].get("command")[2]
240240

241241
command = command.replace("deployment-name", cluster_name)
242-
243-
server_name = (
244-
oc.whoami("--show-server").split(":")[1].split("//")[1].replace("api", "apps")
242+
config.load_kube_config()
243+
api_client = client.CustomObjectsApi()
244+
ingress = api_client.get_cluster_custom_object(
245+
"config.openshift.io", "v1", "ingresses", "cluster"
245246
)
246-
247-
command = command.replace("server-name", server_name)
247+
domain = ingress["spec"]["domain"]
248+
command = command.replace("server-name", domain)
248249

249250
item["generictemplate"]["spec"]["headGroupSpec"]["template"]["spec"][
250251
"initContainers"

Diff for: tests/unit_test.py

+19
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,25 @@ def test_cluster_uris(mocker):
379379
)
380380

381381

382+
def test_local_client_url(mocker):
383+
mocker.patch(
384+
"kubernetes.client.CustomObjectsApi.get_cluster_custom_object",
385+
return_value={"spec": {"domain": ""}},
386+
)
387+
mocker.patch(
388+
"codeflare_sdk.cluster.cluster._get_ingress_domain",
389+
return_value="apps.cluster.awsroute.org",
390+
)
391+
default_config = ClusterConfiguration(
392+
name="unit-test-cluster", namespace="ns", local_interactive=True
393+
)
394+
cluster = Cluster(default_config)
395+
assert (
396+
cluster.local_client_url()
397+
== "ray://rayclient-unit-test-cluster-ns.apps.cluster.awsroute.org"
398+
)
399+
400+
382401
def ray_addr(self, *args):
383402
return self._address
384403

0 commit comments

Comments
 (0)