Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9ddc536

Browse files
committedOct 23, 2023
Review feedback applied, auto-select
1 parent aea1321 commit 9ddc536

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed
 

‎src/codeflare_sdk/cluster/cluster.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def get_current_namespace(): # pragma: no cover
611611
return None
612612

613613

614-
def get_cluster(cluster_name: str, namespace: str = "default", mcad=True):
614+
def get_cluster(cluster_name: str, namespace: str = "default"):
615615
try:
616616
config_check()
617617
api_instance = client.CustomObjectsApi(api_config_handler())
@@ -626,13 +626,33 @@ def get_cluster(cluster_name: str, namespace: str = "default", mcad=True):
626626

627627
for rc in rcs["items"]:
628628
if rc["metadata"]["name"] == cluster_name:
629+
mcad = _check_aw_exists(cluster_name, namespace)
629630
return Cluster.from_k8_cluster_object(rc, mcad=mcad)
630631
raise FileNotFoundError(
631632
f"Cluster {cluster_name} is not found in {namespace} namespace"
632633
)
633634

634635

635636
# private methods
637+
def _check_aw_exists(name: str, namespace: str) -> bool:
638+
try:
639+
config_check()
640+
api_instance = client.CustomObjectsApi(api_config_handler())
641+
aws = api_instance.list_namespaced_custom_object(
642+
group="workload.codeflare.dev",
643+
version="v1beta1",
644+
namespace=namespace,
645+
plural="appwrappers",
646+
)
647+
except Exception as e: # pragma: no cover
648+
return _kube_api_error_handling(e, print_error=False)
649+
650+
for aw in aws["items"]:
651+
if aw["metadata"]["name"] == name:
652+
return True
653+
return False
654+
655+
636656
def _get_ingress_domain():
637657
try:
638658
config_check()

‎src/codeflare_sdk/utils/kube_api_helpers.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323

2424

2525
# private methods
26-
def _kube_api_error_handling(e: Exception): # pragma: no cover
26+
def _kube_api_error_handling(
27+
e: Exception, print_error: bool = True
28+
): # pragma: no cover
2729
perm_msg = (
2830
"Action not permitted, have you put in correct/up-to-date auth credentials?"
2931
)
@@ -32,11 +34,13 @@ def _kube_api_error_handling(e: Exception): # pragma: no cover
3234
if type(e) == config.ConfigException:
3335
raise PermissionError(perm_msg)
3436
if type(e) == executing.executing.NotOneValueFound:
35-
print(nf_msg)
37+
if print_error:
38+
print(nf_msg)
3639
return
3740
if type(e) == client.ApiException:
3841
if e.reason == "Not Found":
39-
print(nf_msg)
42+
if print_error:
43+
print(nf_msg)
4044
return
4145
elif e.reason == "Unauthorized" or e.reason == "Forbidden":
4246
raise PermissionError(perm_msg)

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

Lines changed: 3 additions & 3 deletions
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)
Please sign in to comment.