From 8d7782c7be8b9348653faa1adf4cce4e5bd2631f Mon Sep 17 00:00:00 2001 From: "v.oleynikov" Date: Fri, 22 Mar 2024 12:17:36 +0300 Subject: [PATCH] fix Signed-off-by: v.oleynikov --- images/webhooks/src/main.go | 15 ++++++++------- .../webhooks/src/validators/storageClassUpdate.go | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/images/webhooks/src/main.go b/images/webhooks/src/main.go index 5f31216e..4fd9783b 100644 --- a/images/webhooks/src/main.go +++ b/images/webhooks/src/main.go @@ -23,6 +23,7 @@ import ( kwhhttp "github.com/slok/kubewebhook/v2/pkg/http" kwhlogrus "github.com/slok/kubewebhook/v2/pkg/log/logrus" kwhmutating "github.com/slok/kubewebhook/v2/pkg/webhook/mutating" + kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating" corev1 "k8s.io/api/core/v1" "net/http" "os" @@ -83,15 +84,15 @@ func main() { os.Exit(1) } - scuMF := kwhmutating.MutatorFunc(validators.StorageClassUpdate) + scuMF := kwhvalidating.ValidatorFunc(validators.StorageClassUpdate) - scuMCfg := kwhmutating.WebhookConfig{ - ID: "StorageClassUpdate", - Obj: &v1alpha1.LocalStorageClass{}, - Mutator: scuMF, - Logger: logger, + scuMCfg := kwhvalidating.WebhookConfig{ + ID: "StorageClassUpdate", + Obj: &v1alpha1.LocalStorageClass{}, + Validator: scuMF, + Logger: logger, } - scuWh, err := kwhmutating.NewWebhook(scuMCfg) + scuWh, err := kwhvalidating.NewWebhook(scuMCfg) if err != nil { fmt.Fprintf(os.Stderr, "error creating webhook: %s", err) os.Exit(1) diff --git a/images/webhooks/src/validators/storageClassUpdate.go b/images/webhooks/src/validators/storageClassUpdate.go index b42fc795..d724d98f 100644 --- a/images/webhooks/src/validators/storageClassUpdate.go +++ b/images/webhooks/src/validators/storageClassUpdate.go @@ -22,15 +22,15 @@ import ( "webhooks/v1alpha1" "github.com/slok/kubewebhook/v2/pkg/model" - kwhmutating "github.com/slok/kubewebhook/v2/pkg/webhook/mutating" + kwhvalidating "github.com/slok/kubewebhook/v2/pkg/webhook/validating" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func StorageClassUpdate(ctx context.Context, _ *model.AdmissionReview, obj metav1.Object) (*kwhmutating.MutatorResult, error) { +func StorageClassUpdate(ctx context.Context, _ *model.AdmissionReview, obj metav1.Object) (*kwhvalidating.ValidatorResult, error) { sc, ok := obj.(*v1alpha1.LocalStorageClass) if !ok { // If not a storage class just continue the mutation chain(if there is one) and do nothing. - return &kwhmutating.MutatorResult{}, nil + return &kwhvalidating.ValidatorResult{}, nil } thickExists := false @@ -44,10 +44,10 @@ func StorageClassUpdate(ctx context.Context, _ *model.AdmissionReview, obj metav } if thickExists == true && thinExists == true { - return &kwhmutating.MutatorResult{}, errors.New("There must be only thin or thick pools simultaneously") + return &kwhvalidating.ValidatorResult{Valid: false}, errors.New("there must be only thin or thick pools simultaneously") } - return &kwhmutating.MutatorResult{ - MutatedObject: sc, + return &kwhvalidating.ValidatorResult{ + Valid: true, }, nil }