Skip to content

Commit 28ad59c

Browse files
Altered local_interactive logic & added tests
1 parent c59dab5 commit 28ad59c

File tree

2 files changed

+222
-69
lines changed

2 files changed

+222
-69
lines changed

src/codeflare_sdk/cluster/cluster.py

Lines changed: 89 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def cluster_dashboard_uri(self) -> str:
468468
elif "route.openshift.io/termination" in annotations:
469469
protocol = "https"
470470
return f"{protocol}://{ingress.spec.rules[0].host}"
471-
return "Dashboard ingress not available yet, have you run cluster.up()?"
471+
return "Dashboard not available yet, have you run cluster.up()?"
472472

473473
def list_jobs(self) -> List:
474474
"""
@@ -502,21 +502,55 @@ def torchx_config(
502502
to_return["requirements"] = requirements
503503
return to_return
504504

505-
def from_k8_cluster_object(
506-
rc, mcad=True, ingress_domain=None, ingress_options={}, write_to_file=False
507-
):
505+
def from_k8_cluster_object(rc, mcad=True, ingress_domain=None, ingress_options={}, write_to_file=False):
506+
config_check()
507+
cluster_name = rc["metadata"]["name"]
508+
if is_openshift_cluster():
509+
try:
510+
api_instance = client.CustomObjectsApi(api_config_handler())
511+
routes = api_instance.list_namespaced_custom_object(
512+
group="route.openshift.io",
513+
version="v1",
514+
namespace=rc["metadata"]["namespace"],
515+
plural="routes",
516+
)
517+
except Exception as e: # pragma no cover
518+
return _kube_api_error_handling(e)
519+
for route in routes["items"]:
520+
if (
521+
route["metadata"]["name"] == f"rayclient-{cluster_name}"
522+
and route["spec"]["port"]["targetPort"] == "client"
523+
):
524+
local_interactive = True
525+
break
526+
else:
527+
local_interactive = False
528+
else:
529+
try:
530+
api_instance = client.NetworkingV1Api(api_config_handler())
531+
ingresses = api_instance.list_namespaced_ingress(
532+
rc["metadata"]["namespace"]
533+
)
534+
except Exception as e: # pragma no cover
535+
return _kube_api_error_handling(e)
536+
for ingress in ingresses.items:
537+
if (
538+
f"rayclient-{cluster_name}" == ingress.metadata.name
539+
and ingress.spec.rules[0].http.paths[0].backend.service.port.number
540+
== 10001
541+
):
542+
local_interactive = True
543+
break
544+
else:
545+
local_interactive = False
546+
508547
machine_types = (
509548
rc["metadata"]["labels"]["orderedinstance"].split("_")
510549
if "orderedinstance" in rc["metadata"]["labels"]
511550
else []
512551
)
513-
for volume in rc["spec"]["workerGroupSpecs"][0]["template"]["spec"]["volumes"]:
514-
if volume["name"] == "ca-vol":
515-
local_interactive = True
516-
break
517-
else:
518-
local_interactive = False
519-
if local_interactive:
552+
553+
if local_interactive and ingress_domain == None:
520554
ingress_domain = get_ingress_domain_from_client(
521555
rc["metadata"]["name"], rc["metadata"]["namespace"]
522556
)
@@ -654,56 +688,57 @@ def get_cluster(
654688
for rc in rcs["items"]:
655689
if rc["metadata"]["name"] == cluster_name:
656690
mcad = _check_aw_exists(cluster_name, namespace)
657-
658-
try:
659-
config_check()
660-
api_instance = client.NetworkingV1Api(api_config_handler())
661-
ingresses = api_instance.list_namespaced_ingress(namespace)
662-
ingress_host = None
663-
ingress_options = {}
664-
for ingress in ingresses.items:
665-
# Search for ingress with AppWrapper name as the owner
666-
if (
667-
"ingress-owner" in ingress.metadata.labels
668-
and ingress.metadata.labels["ingress-owner"] == cluster_name
669-
):
670-
ingress_host = ingress.spec.rules[0].host
691+
ingress_host = None
692+
ingress_options = {}
693+
if is_openshift_cluster() == False:
694+
try:
695+
config_check()
696+
api_instance = client.NetworkingV1Api(api_config_handler())
697+
ingresses = api_instance.list_namespaced_ingress(namespace)
698+
for ingress in ingresses.items:
699+
# Search for ingress with AppWrapper name as the owner
671700
if (
672-
"ingress-options" in ingress.metadata.labels
673-
and ingress.metadata.labels["ingress-options"] == "true"
701+
"ingress-owner" in ingress.metadata.labels
702+
and ingress.metadata.labels["ingress-owner"] == cluster_name
674703
):
675-
ingress_name = ingress.metadata.name
676-
port = (
677-
ingress.spec.rules[0]
678-
.http.paths[0]
679-
.backend.service.port.number
680-
)
681-
annotations = ingress.metadata.annotations
682-
path = ingress.spec.rules[0].http.paths[0].path
683-
ingress_class_name = ingress.spec.ingress_class_name
684-
path_type = ingress.spec.rules[0].http.paths[0].path_type
685-
686-
ingress_options = {
687-
"ingresses": [
688-
{
689-
"ingressName": ingress_name,
690-
"port": port,
691-
"annotations": annotations,
692-
"ingressClassName": ingress_class_name,
693-
"pathType": path_type,
694-
"path": path,
695-
"host": ingress_host,
696-
}
697-
]
698-
}
699-
except Exception as e:
700-
return _kube_api_error_handling(e)
704+
ingress_host = ingress.spec.rules[0].host
705+
if (
706+
"ingress-options" in ingress.metadata.labels
707+
and ingress.metadata.labels["ingress-options"] == "true"
708+
):
709+
ingress_name = ingress.metadata.name
710+
port = (
711+
ingress.spec.rules[0]
712+
.http.paths[0]
713+
.backend.service.port.number
714+
)
715+
annotations = ingress.metadata.annotations
716+
path = ingress.spec.rules[0].http.paths[0].path
717+
ingress_class_name = ingress.spec.ingress_class_name
718+
path_type = (
719+
ingress.spec.rules[0].http.paths[0].path_type
720+
)
721+
722+
ingress_options = {
723+
"ingresses": [
724+
{
725+
"ingressName": ingress_name,
726+
"port": port,
727+
"annotations": annotations,
728+
"ingressClassName": ingress_class_name,
729+
"pathType": path_type,
730+
"path": path,
731+
"host": ingress_host,
732+
}
733+
]
734+
}
735+
except Exception as e: # pragma: no cover
736+
return _kube_api_error_handling(e)
701737
# We gather the ingress domain from the host
702738
if ingress_host is not None and ingress_options == {}:
703739
ingress_domain = ingress_host.split(".", 1)[1]
704740
else:
705741
ingress_domain = None
706-
707742
return Cluster.from_k8_cluster_object(
708743
rc,
709744
mcad=mcad,

0 commit comments

Comments
 (0)