Skip to content

Commit accd262

Browse files
authored
Merge pull request #2049 from iiiceoo/fix-del
🐛 Skip custom mutation handler when delete a CR
2 parents af8d903 + f18a0c1 commit accd262

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/webhook/admission/defaulter_custom.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ import (
2222
"errors"
2323
"net/http"
2424

25+
admissionv1 "k8s.io/api/admission/v1"
2526
apierrors "k8s.io/apimachinery/pkg/api/errors"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2628
"k8s.io/apimachinery/pkg/runtime"
2729
)
2830

@@ -60,6 +62,16 @@ func (h *defaulterForType) Handle(ctx context.Context, req Request) Response {
6062
panic("object should never be nil")
6163
}
6264

65+
// Always skip when a DELETE operation received in custom mutation handler.
66+
if req.Operation == admissionv1.Delete {
67+
return Response{AdmissionResponse: admissionv1.AdmissionResponse{
68+
Allowed: true,
69+
Result: &metav1.Status{
70+
Code: http.StatusOK,
71+
},
72+
}}
73+
}
74+
6375
ctx = NewContextWithRequest(ctx, req)
6476

6577
// Get the object in the request

0 commit comments

Comments
 (0)