From f18a0c1acb607b9e0cff635251ce6bc493858e02 Mon Sep 17 00:00:00 2001 From: iiiceoo Date: Fri, 18 Nov 2022 14:13:09 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Skip=20custom=20mutation=20handl?= =?UTF-8?q?er=20when=20delete=20a=20CR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: iiiceoo --- pkg/webhook/admission/defaulter_custom.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/webhook/admission/defaulter_custom.go b/pkg/webhook/admission/defaulter_custom.go index d65727e62c..7007984245 100644 --- a/pkg/webhook/admission/defaulter_custom.go +++ b/pkg/webhook/admission/defaulter_custom.go @@ -22,7 +22,9 @@ import ( "errors" "net/http" + admissionv1 "k8s.io/api/admission/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -60,6 +62,16 @@ func (h *defaulterForType) Handle(ctx context.Context, req Request) Response { panic("object should never be nil") } + // Always skip when a DELETE operation received in custom mutation handler. + if req.Operation == admissionv1.Delete { + return Response{AdmissionResponse: admissionv1.AdmissionResponse{ + Allowed: true, + Result: &metav1.Status{ + Code: http.StatusOK, + }, + }} + } + ctx = NewContextWithRequest(ctx, req) // Get the object in the request