Skip to content

Commit 8ef05eb

Browse files
Remove oc client and add helper functions (#187)
* Remove oc client and add helper functions * Updates for error checking * make sure tests run without oc login * Removing CLI appwrapper generation * Updated import --------- Co-authored-by: Mustafa Eyceoz <[email protected]>
1 parent 74d8846 commit 8ef05eb

File tree

7 files changed

+132
-404
lines changed

7 files changed

+132
-404
lines changed

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": [],

src/codeflare_sdk/cluster/awload.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
from os.path import isfile
2121
import errno
2222
import os
23-
import openshift as oc
2423
import yaml
2524

2625
from kubernetes import client, config
27-
from .cluster import _kube_api_error_handling
26+
from ..utils.kube_api_helpers import _kube_api_error_handling
2827

2928

3029
class AWManager:

src/codeflare_sdk/cluster/cluster.py

+18-24
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
cluster setup queue, a list of all existing clusters, and the user's working namespace.
1919
"""
2020

21-
from os import stat
2221
from time import sleep
2322
from typing import List, Optional, Tuple, Dict
2423

2524
from ray.job_submission import JobSubmissionClient
2625

2726
from ..utils import pretty_print
2827
from ..utils.generate_yaml import generate_appwrapper
28+
from ..utils.kube_api_helpers import _kube_api_error_handling
2929
from .config import ClusterConfiguration
3030
from .model import (
3131
AppWrapper,
@@ -34,7 +34,6 @@
3434
RayCluster,
3535
RayClusterStatus,
3636
)
37-
3837
from kubernetes import client, config
3938

4039
import yaml
@@ -346,6 +345,13 @@ def from_k8_cluster_object(rc):
346345
)
347346
return Cluster(cluster_config)
348347

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

350356
def list_all_clusters(namespace: str, print_to_console: bool = True):
351357
"""
@@ -404,28 +410,16 @@ def get_cluster(cluster_name: str, namespace: str = "default"):
404410

405411

406412
# private methods
407-
408-
409-
def _kube_api_error_handling(e: Exception): # pragma: no cover
410-
perm_msg = (
411-
"Action not permitted, have you put in correct/up-to-date auth credentials?"
412-
)
413-
nf_msg = "No instances found, nothing to be done."
414-
exists_msg = "Resource with this name already exists."
415-
if type(e) == config.ConfigException:
416-
raise PermissionError(perm_msg)
417-
if type(e) == executing.executing.NotOneValueFound:
418-
print(nf_msg)
419-
return
420-
if type(e) == client.ApiException:
421-
if e.reason == "Not Found":
422-
print(nf_msg)
423-
return
424-
elif e.reason == "Unauthorized" or e.reason == "Forbidden":
425-
raise PermissionError(perm_msg)
426-
elif e.reason == "Conflict":
427-
raise FileExistsError(exists_msg)
428-
raise e
413+
def _get_ingress_domain():
414+
try:
415+
config.load_kube_config()
416+
api_client = client.CustomObjectsApi()
417+
ingress = api_client.get_cluster_custom_object(
418+
"config.openshift.io", "v1", "ingresses", "cluster"
419+
)
420+
except Exception as e: # pragma: no cover
421+
return _kube_api_error_handling(e)
422+
return ingress["spec"]["domain"]
429423

430424

431425
def _app_wrapper_status(name, namespace="default") -> Optional[AppWrapper]:

0 commit comments

Comments
 (0)