mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
* Updating client-go to v1.36.0-beta.0 (and updating golang to 1.26) Signed-off-by: Mark Rossetti <[email protected]> * Bump golangci-lint to v2.11.4 and fix lint issues for Go 1.26 Signed-off-by: Mark Rossetti <[email protected]> * bump go to 1.26 in ray-operator docker file Signed-off-by: Mark Rossetti <[email protected]> * Migrate webhooks from deprecated CustomValidator to admission.Validation[T] Signed-off-by: Mark Rossetti <[email protected]> * Target K8s 1.36 GA deps Signed-off-by: Mark Rossetti <[email protected]> * Merge branch 'master' into go-client-go-updates Signed-off-by: Rueian <[email protected]> --------- Signed-off-by: Mark Rossetti <[email protected]> Signed-off-by: Rueian <[email protected]> Co-authored-by: Rueian <[email protected]>
64 lines
2.4 KiB
Go
64 lines
2.4 KiB
Go
package v1
|
|
|
|
import (
|
|
"context"
|
|
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
|
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
|
|
|
|
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
|
|
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
|
|
)
|
|
|
|
var rayServiceLog = logf.Log.WithName("rayservice-resource")
|
|
|
|
// SetupRayServiceWebhookWithManager registers the webhook for RayService in the manager.
|
|
func SetupRayServiceWebhookWithManager(mgr ctrl.Manager) error {
|
|
return ctrl.NewWebhookManagedBy(mgr, &rayv1.RayService{}).
|
|
WithValidator(&RayServiceWebhook{}).
|
|
Complete()
|
|
}
|
|
|
|
type RayServiceWebhook struct{}
|
|
|
|
//+kubebuilder:webhook:path=/validate-ray-io-v1-rayservice,mutating=false,failurePolicy=fail,sideEffects=None,groups=ray.io,resources=rayservices,verbs=create;update,versions=v1,name=vrayservice.kb.io,admissionReviewVersions=v1
|
|
|
|
var _ admission.Validator[*rayv1.RayService] = &RayServiceWebhook{}
|
|
|
|
// ValidateCreate implements admission.Validator so a webhook will be registered for the type
|
|
func (w *RayServiceWebhook) ValidateCreate(_ context.Context, rayService *rayv1.RayService) (admission.Warnings, error) {
|
|
rayServiceLog.Info("validate create", "name", rayService.Name)
|
|
return nil, w.validateRayService(rayService)
|
|
}
|
|
|
|
// ValidateUpdate implements admission.Validator so a webhook will be registered for the type
|
|
func (w *RayServiceWebhook) ValidateUpdate(_ context.Context, _ *rayv1.RayService, rayService *rayv1.RayService) (admission.Warnings, error) {
|
|
rayServiceLog.Info("validate update", "name", rayService.Name)
|
|
return nil, w.validateRayService(rayService)
|
|
}
|
|
|
|
// ValidateDelete implements admission.Validator so a webhook will be registered for the type
|
|
func (w *RayServiceWebhook) ValidateDelete(_ context.Context, _ *rayv1.RayService) (admission.Warnings, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (w *RayServiceWebhook) validateRayService(rayService *rayv1.RayService) error {
|
|
var allErrs field.ErrorList
|
|
|
|
if err := utils.ValidateRayServiceMetadata(rayService.ObjectMeta); err != nil {
|
|
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("name"), rayService.Name, err.Error()))
|
|
}
|
|
|
|
if len(allErrs) == 0 {
|
|
return nil
|
|
}
|
|
|
|
return apierrors.NewInvalid(
|
|
schema.GroupKind{Group: "ray.io", Kind: "RayService"},
|
|
rayService.Name, allErrs)
|
|
}
|