@@ -27,7 +27,6 @@ import (
27
27
"k8s.io/utils/pointer"
28
28
ctrl "sigs.k8s.io/controller-runtime"
29
29
logf "sigs.k8s.io/controller-runtime/pkg/log"
30
- "sigs.k8s.io/controller-runtime/pkg/webhook"
31
30
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
32
31
33
32
"github.com/project-codeflare/codeflare-operator/pkg/config"
@@ -39,7 +38,7 @@ var rayclusterlog = logf.Log.WithName("raycluster-resource")
39
38
func SetupRayClusterWebhookWithManager (mgr ctrl.Manager , cfg * config.KubeRayConfiguration ) error {
40
39
return ctrl .NewWebhookManagedBy (mgr ).
41
40
For (& rayv1.RayCluster {}).
42
- WithDefaulter (& rayClusterDefaulter {
41
+ WithDefaulter (& rayClusterWebhook {
43
42
Config : cfg ,
44
43
}).
45
44
WithValidator (& rayClusterWebhook {
@@ -51,21 +50,15 @@ func SetupRayClusterWebhookWithManager(mgr ctrl.Manager, cfg *config.KubeRayConf
51
50
// +kubebuilder:webhook:path=/mutate-ray-io-v1-raycluster,mutating=true,failurePolicy=fail,sideEffects=None,groups=ray.io,resources=rayclusters,verbs=create;update,versions=v1,name=mraycluster.kb.io,admissionReviewVersions=v1
52
51
// +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.kb.io,admissionReviewVersions=v1
53
52
54
- type rayClusterDefaulter struct {
55
- Config * config.KubeRayConfiguration
56
- }
57
53
type rayClusterWebhook struct {
58
54
Config * config.KubeRayConfiguration
59
55
}
60
56
61
- var _ webhook.CustomDefaulter = & rayClusterDefaulter {}
62
- var _ webhook.CustomValidator = & rayClusterWebhook {}
63
-
64
57
// Default implements webhook.Defaulter so a webhook will be registered for the type
65
- func (r * rayClusterDefaulter ) Default (ctx context.Context , obj runtime.Object ) error {
58
+ func (w * rayClusterWebhook ) Default (ctx context.Context , obj runtime.Object ) error {
66
59
raycluster := obj .(* rayv1.RayCluster )
67
60
68
- if ! pointer .BoolDeref (r .Config .RayDashboardOAuthEnabled , true ) {
61
+ if ! pointer .BoolDeref (w .Config .RayDashboardOAuthEnabled , true ) {
69
62
return nil
70
63
}
71
64
@@ -143,7 +136,7 @@ func (r *rayClusterDefaulter) Default(ctx context.Context, obj runtime.Object) e
143
136
return nil
144
137
}
145
138
146
- func (v * rayClusterWebhook ) ValidateCreate (ctx context.Context , obj runtime.Object ) (admission.Warnings , error ) {
139
+ func (w * rayClusterWebhook ) ValidateCreate (ctx context.Context , obj runtime.Object ) (admission.Warnings , error ) {
147
140
raycluster := obj .(* rayv1.RayCluster )
148
141
var warnings admission.Warnings
149
142
var allErrors field.ErrorList
@@ -157,17 +150,17 @@ func (v *rayClusterWebhook) ValidateCreate(ctx context.Context, obj runtime.Obje
157
150
return warnings , allErrors .ToAggregate ()
158
151
}
159
152
160
- func (v * rayClusterWebhook ) ValidateUpdate (ctx context.Context , oldObj , newObj runtime.Object ) (admission.Warnings , error ) {
153
+ func (w * rayClusterWebhook ) ValidateUpdate (ctx context.Context , oldObj , newObj runtime.Object ) (admission.Warnings , error ) {
161
154
newRayCluster := newObj .(* rayv1.RayCluster )
162
155
if ! newRayCluster .DeletionTimestamp .IsZero () {
163
156
// Object is being deleted, skip validations
164
157
return nil , nil
165
158
}
166
- warnings , err := v .ValidateCreate (ctx , newRayCluster )
159
+ warnings , err := w .ValidateCreate (ctx , newRayCluster )
167
160
return warnings , err
168
161
}
169
162
170
- func (v * rayClusterWebhook ) ValidateDelete (ctx context.Context , obj runtime.Object ) (admission.Warnings , error ) {
163
+ func (w * rayClusterWebhook ) ValidateDelete (ctx context.Context , obj runtime.Object ) (admission.Warnings , error ) {
171
164
// Optional: Add delete validation logic here
172
165
return nil , nil
173
166
}
0 commit comments