Skip to content

Get cluster function #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ray = {version = "2.1.0", extras = ["default"]}
kubernetes = ">= 25.3.0, < 27"
codeflare-torchx = "0.6.0.dev0"
cryptography = "40.0.2"
executing = "1.2.0"

[tool.poetry.group.docs]
optional = true
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ rich==12.5.1
ray[default]==2.1.0
kubernetes>=25.3.0,<27
codeflare-torchx==0.6.0.dev0
cryptography==40.0.2
executing==1.2.0
65 changes: 29 additions & 36 deletions src/codeflare_sdk/cluster/awload.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import openshift as oc
import yaml

from kubernetes import client, config
from .cluster import _kube_api_error_handling


class AWManager:
"""
Expand All @@ -40,10 +43,10 @@ def __init__(self, filename: str) -> None:
self.filename = filename
try:
with open(self.filename) as f:
awyaml = yaml.load(f, Loader=yaml.FullLoader)
assert awyaml["kind"] == "AppWrapper"
self.name = awyaml["metadata"]["name"]
self.namespace = awyaml["metadata"]["namespace"]
self.awyaml = yaml.load(f, Loader=yaml.FullLoader)
assert self.awyaml["kind"] == "AppWrapper"
self.name = self.awyaml["metadata"]["name"]
self.namespace = self.awyaml["metadata"]["namespace"]
except:
raise ValueError(
f"{filename } is not a correctly formatted AppWrapper yaml"
Expand All @@ -55,19 +58,17 @@ def submit(self) -> None:
Attempts to create the AppWrapper custom resource using the yaml file
"""
try:
with oc.project(self.namespace):
oc.invoke("create", ["-f", self.filename])
except oc.OpenShiftPythonException as osp: # pragma: no cover
error_msg = osp.result.err()
if "Unauthorized" in error_msg or "Forbidden" in error_msg:
raise PermissionError(
"Action not permitted, have you put in correct/up-to-date auth credentials?"
)
elif "AlreadyExists" in error_msg:
raise FileExistsError(
f"An AppWrapper of the name {self.name} already exists in namespace {self.namespace}"
)
raise osp
config.load_kube_config()
api_instance = client.CustomObjectsApi()
api_instance.create_namespaced_custom_object(
group="mcad.ibm.com",
version="v1beta1",
namespace=self.namespace,
plural="appwrappers",
body=self.awyaml,
)
except Exception as e:
return _kube_api_error_handling(e)

self.submitted = True
print(f"AppWrapper {self.filename} submitted!")
Expand All @@ -82,25 +83,17 @@ def remove(self) -> None:
return

try:
with oc.project(self.namespace):
oc.invoke("delete", ["AppWrapper", self.name])
except oc.OpenShiftPythonException as osp: # pragma: no cover
error_msg = osp.result.err()
if (
'the server doesn\'t have a resource type "AppWrapper"' in error_msg
or "forbidden" in error_msg
or "Unauthorized" in error_msg
or "Missing or incomplete configuration" in error_msg
):
raise PermissionError(
"Action not permitted, have you put in correct/up-to-date auth credentials?"
)
elif "not found" in error_msg:
self.submitted = False
print("AppWrapper not found, was deleted in another manner")
return
else:
raise osp
config.load_kube_config()
api_instance = client.CustomObjectsApi()
api_instance.delete_namespaced_custom_object(
group="mcad.ibm.com",
version="v1beta1",
namespace=self.namespace,
plural="appwrappers",
name=self.name,
)
except Exception as e:
return _kube_api_error_handling(e)

self.submitted = False
print(f"AppWrapper {self.name} removed!")
Loading