@@ -27,9 +27,11 @@ import (
2727	"k8s.io/apimachinery/pkg/util/validation/field" 
2828	"k8s.io/utils/ptr" 
2929	ctrl "sigs.k8s.io/controller-runtime" 
30+ 	"sigs.k8s.io/controller-runtime/pkg/client" 
3031	logf "sigs.k8s.io/controller-runtime/pkg/log" 
3132	"sigs.k8s.io/controller-runtime/pkg/webhook" 
3233	"sigs.k8s.io/controller-runtime/pkg/webhook/admission" 
34+ 	kueuev1beta1 "sigs.k8s.io/kueue/apis/kueue/v1beta1" 
3335
3436	"github.com/project-codeflare/codeflare-operator/pkg/config" 
3537)
@@ -45,6 +47,7 @@ var rayclusterlog = logf.Log.WithName("raycluster-resource")
4547
4648func  SetupRayClusterWebhookWithManager (mgr  ctrl.Manager , cfg  * config.KubeRayConfiguration ) error  {
4749	rayClusterWebhookInstance  :=  & rayClusterWebhook {
50+ 		Client : mgr .GetClient (),
4851		Config : cfg ,
4952	}
5053	return  ctrl .NewWebhookManagedBy (mgr ).
@@ -58,6 +61,7 @@ func SetupRayClusterWebhookWithManager(mgr ctrl.Manager, cfg *config.KubeRayConf
5861// +kubebuilder:webhook:path=/validate-ray-io-v1-raycluster,mutating=false,failurePolicy=fail,sideEffects=None,groups=ray.io,resources=rayclusters,verbs=create;update,versions=v1,name=vraycluster.ray.openshift.ai,admissionReviewVersions=v1 
5962
6063type  rayClusterWebhook  struct  {
64+ 	client.Client 
6165	Config  * config.KubeRayConfiguration 
6266}
6367
@@ -77,6 +81,30 @@ func (w *rayClusterWebhook) Default(ctx context.Context, obj runtime.Object) err
7781		rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName  =  rayCluster .Name  +  "-oauth-proxy" 
7882	}
7983
84+ 	// add default queue label if not present 
85+ 	if  rayCluster .GetLabels () ==  nil  {
86+ 		rayCluster .Labels  =  make (map [string ]string )
87+ 	}
88+ 	err  :=  w .Client .List (ctx , & kueuev1beta1.LocalQueueList {})
89+ 	if  err  !=  nil  {
90+ 		rayclusterlog .Error (err , "Failed to list LocalQueues, Kueue CRD might not be installed" )
91+ 		_ , ok  :=  rayCluster .Labels ["kueue.x-k8s.io/queue-name" ]
92+ 		if  ! ok  {
93+ 			// check if CRD Kueue LocalQueue exists 
94+ 			localQueues  :=  & kueuev1beta1.LocalQueueList {}
95+ 			err  :=  w .Client .List (ctx , localQueues )
96+ 			if  err  ==  nil  {
97+ 				for  _ , localQueue  :=  range  localQueues .Items  {
98+ 					is_default , ok  :=  localQueue .Labels ["kueue.x-k8s.io/default-queue" ]
99+ 					if  ok  &&  is_default  ==  "true"  {
100+ 						rayCluster .Labels ["kueue.x-k8s.io/queue-name" ] =  localQueue .Name 
101+ 						break 
102+ 					}
103+ 				}
104+ 			}
105+ 		}
106+ 	}
107+ 
80108	if  ptr .Deref (w .Config .MTLSEnabled , true ) {
81109		rayclusterlog .V (2 ).Info ("Adding create-cert Init Containers" )
82110		// HeadGroupSpec 
0 commit comments