Skip to content

Commit

Permalink
🐛 Skip custom mutation handler when delete a CR
Browse files Browse the repository at this point in the history
Signed-off-by: iiiceoo <ziqian.xue@daocloud.io>
  • Loading branch information
iiiceoo committed Nov 18, 2022
1 parent af8d903 commit f18a0c1
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/webhook/admission/defaulter_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f18a0c1

Please sign in to comment.