@@ -27,9 +27,11 @@ import (
27
27
"k8s.io/apimachinery/pkg/util/validation/field"
28
28
"k8s.io/utils/ptr"
29
29
ctrl "sigs.k8s.io/controller-runtime"
30
+ "sigs.k8s.io/controller-runtime/pkg/client"
30
31
logf "sigs.k8s.io/controller-runtime/pkg/log"
31
32
"sigs.k8s.io/controller-runtime/pkg/webhook"
32
33
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
34
+ kueuev1beta1 "sigs.k8s.io/kueue/apis/kueue/v1beta1"
33
35
34
36
"github.com/project-codeflare/codeflare-operator/pkg/config"
35
37
)
@@ -45,6 +47,7 @@ var rayclusterlog = logf.Log.WithName("raycluster-resource")
45
47
46
48
func SetupRayClusterWebhookWithManager (mgr ctrl.Manager , cfg * config.KubeRayConfiguration ) error {
47
49
rayClusterWebhookInstance := & rayClusterWebhook {
50
+ Client : mgr .GetClient (),
48
51
Config : cfg ,
49
52
}
50
53
return ctrl .NewWebhookManagedBy (mgr ).
@@ -58,6 +61,7 @@ func SetupRayClusterWebhookWithManager(mgr ctrl.Manager, cfg *config.KubeRayConf
58
61
// +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
59
62
60
63
type rayClusterWebhook struct {
64
+ client.Client
61
65
Config * config.KubeRayConfiguration
62
66
}
63
67
@@ -77,6 +81,30 @@ func (w *rayClusterWebhook) Default(ctx context.Context, obj runtime.Object) err
77
81
rayCluster .Spec .HeadGroupSpec .Template .Spec .ServiceAccountName = rayCluster .Name + "-oauth-proxy"
78
82
}
79
83
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
+
80
108
if ptr .Deref (w .Config .MTLSEnabled , true ) {
81
109
rayclusterlog .V (2 ).Info ("Adding create-cert Init Containers" )
82
110
// HeadGroupSpec
0 commit comments