17
17
(in the cluster sub-module) for AppWrapper generation.
18
18
"""
19
19
20
- import typing
20
+ from typing import List , Optional
21
21
import yaml
22
22
import sys
23
23
import os
@@ -467,7 +467,7 @@ def enable_local_interactive(resources, cluster_name, namespace, ingress_domain)
467
467
][0 ].get ("command" )[2 ] = command
468
468
469
469
470
- def del_from_list_by_name (l : list , target : typing . List [str ]) -> list :
470
+ def del_from_list_by_name (l : list , target : List [str ]) -> list :
471
471
return [x for x in l if x ["name" ] not in target ]
472
472
473
473
@@ -622,39 +622,34 @@ def _create_oauth_sidecar_object(
622
622
)
623
623
624
624
625
- def get_default_kueue_name (local_queue : str , namespace : str ):
625
+ def get_default_kueue_name (namespace : str ):
626
626
# If the local queue is set, use it. Otherwise, try to use the default queue.
627
- if local_queue is not None :
628
- return local_queue
629
- else :
630
- try :
631
- config_check ()
632
- api_instance = client .CustomObjectsApi (api_config_handler ())
633
- local_queues = api_instance .list_namespaced_custom_object (
634
- group = "kueue.x-k8s.io" ,
635
- version = "v1beta1" ,
636
- namespace = namespace ,
637
- plural = "localqueues" ,
638
- )
639
- except Exception as e : # pragma: no cover
640
- return _kube_api_error_handling (e )
641
- for lq in local_queues ["items" ]:
642
- if (
643
- "annotations" in lq ["metadata" ]
644
- and "kueue.x-k8s.io/default-queue" in lq ["metadata" ]["annotations" ]
645
- and lq ["metadata" ]["annotations" ][
646
- "kueue.x-k8s.io/default-queue"
647
- ].lower ()
648
- == "true"
649
- ):
650
- return lq ["metadata" ]["name" ]
651
- raise ValueError (
652
- "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"
627
+ try :
628
+ config_check ()
629
+ api_instance = client .CustomObjectsApi (api_config_handler ())
630
+ local_queues = api_instance .list_namespaced_custom_object (
631
+ group = "kueue.x-k8s.io" ,
632
+ version = "v1beta1" ,
633
+ namespace = namespace ,
634
+ plural = "localqueues" ,
653
635
)
636
+ except Exception as e : # pragma: no cover
637
+ return _kube_api_error_handling (e )
638
+ for lq in local_queues ["items" ]:
639
+ if (
640
+ "annotations" in lq ["metadata" ]
641
+ and "kueue.x-k8s.io/default-queue" in lq ["metadata" ]["annotations" ]
642
+ and lq ["metadata" ]["annotations" ]["kueue.x-k8s.io/default-queue" ].lower ()
643
+ == "true"
644
+ ):
645
+ return lq ["metadata" ]["name" ]
646
+ raise ValueError (
647
+ "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"
648
+ )
654
649
655
650
656
651
def write_components (
657
- user_yaml : dict , output_file_name : str , namespace : str , local_queue : str
652
+ user_yaml : dict , output_file_name : str , namespace : str , local_queue : Optional [ str ]
658
653
):
659
654
# Create the directory if it doesn't exist
660
655
directory_path = os .path .dirname (output_file_name )
@@ -663,6 +658,7 @@ def write_components(
663
658
664
659
components = user_yaml .get ("spec" , "resources" )["resources" ].get ("GenericItems" )
665
660
open (output_file_name , "w" ).close ()
661
+ lq_name = local_queue or get_default_kueue_name (namespace )
666
662
with open (output_file_name , "a" ) as outfile :
667
663
for component in components :
668
664
if "generictemplate" in component :
@@ -674,13 +670,7 @@ def write_components(
674
670
"workload.codeflare.dev/appwrapper"
675
671
]
676
672
labels = component ["generictemplate" ]["metadata" ]["labels" ]
677
- labels .update (
678
- {
679
- "kueue.x-k8s.io/queue-name" : get_default_kueue_name (
680
- local_queue , namespace
681
- )
682
- }
683
- )
673
+ labels .update ({"kueue.x-k8s.io/queue-name" : lq_name })
684
674
outfile .write ("---\n " )
685
675
yaml .dump (
686
676
component ["generictemplate" ], outfile , default_flow_style = False
@@ -713,7 +703,7 @@ def generate_appwrapper(
713
703
openshift_oauth : bool ,
714
704
ingress_domain : str ,
715
705
ingress_options : dict ,
716
- local_queue : str ,
706
+ local_queue : Optional [ str ] ,
717
707
):
718
708
user_yaml = read_template (template )
719
709
appwrapper_name , cluster_name = gen_names (name )
0 commit comments