Skip to content

Commit 902da8b

Browse files
committedOct 13, 2023
Review feedback applied, auto-select
1 parent cf21da9 commit 902da8b

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed
 

‎src/codeflare_sdk/cluster/cluster.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ def get_current_namespace(): # pragma: no cover
549549
return None
550550

551551

552-
def get_cluster(cluster_name: str, namespace: str = "default", mcad=True):
552+
def get_cluster(cluster_name: str, namespace: str = "default"):
553553
try:
554554
config_check()
555555
api_instance = client.CustomObjectsApi(api_config_handler())
@@ -564,13 +564,33 @@ def get_cluster(cluster_name: str, namespace: str = "default", mcad=True):
564564

565565
for rc in rcs["items"]:
566566
if rc["metadata"]["name"] == cluster_name:
567+
mcad = _check_aw_exists(cluster_name, namespace)
567568
return Cluster.from_k8_cluster_object(rc, mcad=mcad)
568569
raise FileNotFoundError(
569570
f"Cluster {cluster_name} is not found in {namespace} namespace"
570571
)
571572

572573

573574
# private methods
575+
def _check_aw_exists(name: str, namespace: str) -> bool:
576+
try:
577+
config_check()
578+
api_instance = client.CustomObjectsApi(api_config_handler())
579+
aws = api_instance.list_namespaced_custom_object(
580+
group="workload.codeflare.dev",
581+
version="v1beta1",
582+
namespace=namespace,
583+
plural="appwrappers",
584+
)
585+
except Exception as e: # pragma: no cover
586+
return _kube_api_error_handling(e, print_error=False)
587+
588+
for aw in aws["items"]:
589+
if aw["metadata"]["name"] == name:
590+
return True
591+
return False
592+
593+
574594
def _get_ingress_domain():
575595
try:
576596
config_check()

‎src/codeflare_sdk/utils/kube_api_helpers.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323

2424
# private methods
25-
def _kube_api_error_handling(e: Exception): # pragma: no cover
25+
def _kube_api_error_handling(
26+
e: Exception, print_error: bool = True
27+
): # pragma: no cover
2628
perm_msg = (
2729
"Action not permitted, have you put in correct/up-to-date auth credentials?"
2830
)
@@ -31,11 +33,13 @@ def _kube_api_error_handling(e: Exception): # pragma: no cover
3133
if type(e) == config.ConfigException:
3234
raise PermissionError(perm_msg)
3335
if type(e) == executing.executing.NotOneValueFound:
34-
print(nf_msg)
36+
if print_error:
37+
print(nf_msg)
3538
return
3639
if type(e) == client.ApiException:
3740
if e.reason == "Not Found":
38-
print(nf_msg)
41+
if print_error:
42+
print(nf_msg)
3943
return
4044
elif e.reason == "Unauthorized" or e.reason == "Forbidden":
4145
raise PermissionError(perm_msg)

‎tests/test-case-no-mcad.yamls

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ spec:
5151
value: /home/ray/workspace/tls/server.key
5252
- name: RAY_TLS_CA_CERT
5353
value: /home/ray/workspace/tls/ca.crt
54-
image: quay.io/project-codeflare/ray:2.5.0-py38-cu116
54+
image: quay.io/project-codeflare/ray:latest-py39-cu118
5555
imagePullPolicy: Always
5656
lifecycle:
5757
preStop:
@@ -79,7 +79,7 @@ spec:
7979
nvidia.com/gpu: 0
8080
imagePullSecrets:
8181
- name: unit-test-pull-secret
82-
rayVersion: 2.5.0
82+
rayVersion: 2.7.0
8383
workerGroupSpecs:
8484
- groupName: small-group-unit-test-cluster-ray
8585
maxReplicas: 2
@@ -118,7 +118,7 @@ spec:
118118
value: /home/ray/workspace/tls/server.key
119119
- name: RAY_TLS_CA_CERT
120120
value: /home/ray/workspace/tls/ca.crt
121-
image: quay.io/project-codeflare/ray:2.5.0-py38-cu116
121+
image: quay.io/project-codeflare/ray:latest-py39-cu118
122122
lifecycle:
123123
preStop:
124124
exec:

0 commit comments

Comments
 (0)