Skip to content

Commit

Permalink
🐛 skip mutation handler when received deletion verb
Browse files Browse the repository at this point in the history
Signed-off-by: AnyISalIn <anyisalin@gmail.com>
  • Loading branch information
AnyISalIn committed Jan 5, 2022
1 parent e52a8b1 commit 0bf7d46
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/webhook/admission/defaulter.go
Expand Up @@ -21,6 +21,8 @@ import (
"encoding/json"
"net/http"

admissionv1 "k8s.io/api/admission/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

Expand Down Expand Up @@ -56,6 +58,17 @@ func (h *mutatingHandler) Handle(ctx context.Context, req Request) Response {
panic("defaulter should never be nil")
}

// always skip when a DELETE operation received in mutation handler
// describe in https://github.com/kubernetes-sigs/controller-runtime/issues/1762
if req.Operation == admissionv1.Delete {
return Response{AdmissionResponse: admissionv1.AdmissionResponse{
Allowed: true,
Result: &metav1.Status{
Code: http.StatusOK,
},
}}
}

// Get the object in the request
obj := h.defaulter.DeepCopyObject().(Defaulter)
if err := h.decoder.Decode(req, obj); err != nil {
Expand Down

0 comments on commit 0bf7d46

Please sign in to comment.