Skip to content

Commit 0bf7d46

Browse files
committed
🐛 skip mutation handler when received deletion verb
Signed-off-by: AnyISalIn <[email protected]>
1 parent e52a8b1 commit 0bf7d46

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/webhook/admission/defaulter.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"encoding/json"
2222
"net/http"
2323

24+
admissionv1 "k8s.io/api/admission/v1"
25+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2426
"k8s.io/apimachinery/pkg/runtime"
2527
)
2628

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

61+
// always skip when a DELETE operation received in mutation handler
62+
// describe in https://github.com/kubernetes-sigs/controller-runtime/issues/1762
63+
if req.Operation == admissionv1.Delete {
64+
return Response{AdmissionResponse: admissionv1.AdmissionResponse{
65+
Allowed: true,
66+
Result: &metav1.Status{
67+
Code: http.StatusOK,
68+
},
69+
}}
70+
}
71+
5972
// Get the object in the request
6073
obj := h.defaulter.DeepCopyObject().(Defaulter)
6174
if err := h.decoder.Decode(req, obj); err != nil {

0 commit comments

Comments
 (0)