Skip to content

Commit

Permalink
Review feedback applied, auto-select
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxusmusti committed Oct 23, 2023
1 parent aea1321 commit 9ddc536
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
22 changes: 21 additions & 1 deletion src/codeflare_sdk/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def get_current_namespace(): # pragma: no cover
return None


def get_cluster(cluster_name: str, namespace: str = "default", mcad=True):
def get_cluster(cluster_name: str, namespace: str = "default"):
try:
config_check()
api_instance = client.CustomObjectsApi(api_config_handler())
Expand All @@ -626,13 +626,33 @@ def get_cluster(cluster_name: str, namespace: str = "default", mcad=True):

for rc in rcs["items"]:
if rc["metadata"]["name"] == cluster_name:
mcad = _check_aw_exists(cluster_name, namespace)
return Cluster.from_k8_cluster_object(rc, mcad=mcad)
raise FileNotFoundError(
f"Cluster {cluster_name} is not found in {namespace} namespace"
)


# private methods
def _check_aw_exists(name: str, namespace: str) -> bool:
try:
config_check()
api_instance = client.CustomObjectsApi(api_config_handler())
aws = api_instance.list_namespaced_custom_object(
group="workload.codeflare.dev",
version="v1beta1",
namespace=namespace,
plural="appwrappers",
)
except Exception as e: # pragma: no cover
return _kube_api_error_handling(e, print_error=False)

for aw in aws["items"]:
if aw["metadata"]["name"] == name:
return True
return False


def _get_ingress_domain():
try:
config_check()
Expand Down
10 changes: 7 additions & 3 deletions src/codeflare_sdk/utils/kube_api_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@


# private methods
def _kube_api_error_handling(e: Exception): # pragma: no cover
def _kube_api_error_handling(
e: Exception, print_error: bool = True
): # pragma: no cover
perm_msg = (
"Action not permitted, have you put in correct/up-to-date auth credentials?"
)
Expand All @@ -32,11 +34,13 @@ def _kube_api_error_handling(e: Exception): # pragma: no cover
if type(e) == config.ConfigException:
raise PermissionError(perm_msg)
if type(e) == executing.executing.NotOneValueFound:
print(nf_msg)
if print_error:
print(nf_msg)
return
if type(e) == client.ApiException:
if e.reason == "Not Found":
print(nf_msg)
if print_error:
print(nf_msg)
return
elif e.reason == "Unauthorized" or e.reason == "Forbidden":
raise PermissionError(perm_msg)
Expand Down
6 changes: 3 additions & 3 deletions tests/test-case-no-mcad.yamls
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ spec:
value: /home/ray/workspace/tls/server.key
- name: RAY_TLS_CA_CERT
value: /home/ray/workspace/tls/ca.crt
image: quay.io/project-codeflare/ray:2.5.0-py38-cu116
image: quay.io/project-codeflare/ray:latest-py39-cu118
imagePullPolicy: Always
lifecycle:
preStop:
Expand Down Expand Up @@ -79,7 +79,7 @@ spec:
nvidia.com/gpu: 0
imagePullSecrets:
- name: unit-test-pull-secret
rayVersion: 2.5.0
rayVersion: 2.7.0
workerGroupSpecs:
- groupName: small-group-unit-test-cluster-ray
maxReplicas: 2
Expand Down Expand Up @@ -118,7 +118,7 @@ spec:
value: /home/ray/workspace/tls/server.key
- name: RAY_TLS_CA_CERT
value: /home/ray/workspace/tls/ca.crt
image: quay.io/project-codeflare/ray:2.5.0-py38-cu116
image: quay.io/project-codeflare/ray:latest-py39-cu118
lifecycle:
preStop:
exec:
Expand Down

0 comments on commit 9ddc536

Please sign in to comment.