From cf603bc842197c9411ded10334e4d7a187043f96 Mon Sep 17 00:00:00 2001 From: Bangqi Zhu Date: Tue, 8 Oct 2024 22:18:14 -0700 Subject: [PATCH] Clusterrole and webhook update Signed-off-by: Bangqi Zhu --- api/v1alpha1/ragenging_validation.go | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 api/v1alpha1/ragenging_validation.go diff --git a/api/v1alpha1/ragenging_validation.go b/api/v1alpha1/ragenging_validation.go new file mode 100644 index 00000000..1aecfdf2 --- /dev/null +++ b/api/v1alpha1/ragenging_validation.go @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +package v1alpha1 + +import ( + "context" + "fmt" + + admissionregistrationv1 "k8s.io/api/admissionregistration/v1" + "k8s.io/klog/v2" + "knative.dev/pkg/apis" +) + +func (w *RAGEngine) SupportedVerbs() []admissionregistrationv1.OperationType { + return []admissionregistrationv1.OperationType{ + admissionregistrationv1.Create, + admissionregistrationv1.Update, + } +} + +func (w *RAGEngine) Validate(ctx context.Context) (errs *apis.FieldError) { + base := apis.GetBaseline(ctx) + if base == nil { + klog.InfoS("Validate creation", "ragengine", fmt.Sprintf("%s/%s", w.Namespace, w.Name)) + errs = errs.Also(w.validateCreate().ViaField("spec")) + } + return errs +} + +func (w *RAGEngine) validateCreate() (errs *apis.FieldError) { + if w.Spec.InferenceService == nil { + errs = errs.Also(apis.ErrGeneric("InferenceService must be specified, not neither", "")) + } + return errs +}