From 981c312c013215c45937db0fb73a83549c74bf37 Mon Sep 17 00:00:00 2001 From: oksanabaza Date: Tue, 28 May 2024 11:11:07 +0100 Subject: [PATCH] prep --- src/codeflare_sdk/utils/generate_yaml.py | 46 ++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/codeflare_sdk/utils/generate_yaml.py b/src/codeflare_sdk/utils/generate_yaml.py index 2ea6dd78d..17c5af201 100755 --- a/src/codeflare_sdk/utils/generate_yaml.py +++ b/src/codeflare_sdk/utils/generate_yaml.py @@ -30,6 +30,7 @@ from os import urandom from base64 import b64encode from urllib3.util import parse_url +from kubernetes.client.rest import ApiException def read_template(template): @@ -307,6 +308,32 @@ def get_default_kueue_name(namespace: str): "Default Local Queue with kueue.x-k8s.io/default-queue: true annotation not found please create a default Local Queue or provide the local_queue name in Cluster Configuration" ) +# test function + +# def _throw_for_no_raycluster( user_yaml: dict, +# output_file_name: str, +# namespace: str, +# local_queue: Optional[str], +# labels: dict,): +# api_instance = client.CustomObjectsApi(api_config_handler()) +# print('hello') +# # try: +# # api_instance.list_namespaced_custom_object( +# # group="kueue.x-k8s.io", +# # version="v1", +# # namespace=namespace, +# # plural="localqueues", +# # ) +# # except ApiException as e: +# # if e.status == 404: +# # raise RuntimeError( +# # "RayCluster CustomResourceDefinition unavailable contact your administrator." +# # ) +# # else: +# # raise RuntimeError( +# # "Failed to get RayCluster CustomResourceDefinition: " + str(e) +# # ) + def local_queue_exists(namespace: str, local_queue_name: str): # get all local queues in the namespace @@ -341,6 +368,12 @@ def write_components( os.makedirs(directory_path) components = user_yaml.get("spec", "resources")["resources"].get("GenericItems") + # check if RayCluster CustomResourceDefinition exists if not throw RuntimeError + # _throw_for_no_raycluster() + # if local_queue is None: + # print( + # "Kueue is not installed or won't be used. The absence of CRDs may lack the necessary functionality." + # ) open(output_file_name, "w").close() lq_name = local_queue or get_default_kueue_name(namespace) cluster_labels = labels @@ -367,22 +400,31 @@ def write_components( ) print(f"Written to: {output_file_name}") - def load_components( user_yaml: dict, name: str, namespace: str, local_queue: Optional[str], - labels: dict, + labels: dict ): component_list = [] components = user_yaml.get("spec", "resources")["resources"].get("GenericItems") lq_name = local_queue or get_default_kueue_name(namespace) cluster_labels = labels +<<<<<<< HEAD if not local_queue_exists(namespace, lq_name): raise ValueError( "local_queue provided does not exist or is not in this namespace. Please provide the correct local_queue name in Cluster Configuration" ) +======= + + # _throw_for_no_raycluster() + + # if local_queue is None: + # print( + # "Kueue is not installed or won't be used. The absence of CRDs may lack the necessary functionality." + # ) +>>>>>>> 1d38c8d (prep) for component in components: if "generictemplate" in component: if (