Skip to content

Commit

Permalink
Do not set PatchType if patch is empty
Browse files Browse the repository at this point in the history
In admission v1, API server requires that Patch and PatchType are both
provided or none are provided.  Meanwhile, admission v1beta1 does not
have this kind of requirement.

In controller-runtime, PatchResponseFromRaw sets PatchType regardless
of the existence of patch.  If patch is empty, a response contains
only PatchType and API server does not like it.  Webhook call fails.

This change fixes this issue by not setting PatchType if patch is
empty.
  • Loading branch information
tatsuhiro-t committed Dec 16, 2020
1 parent 355962a commit 66972d3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/webhook/admission/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,14 @@ func PatchResponseFromRaw(original, current []byte) Response {
return Response{
Patches: patches,
AdmissionResponse: admissionv1.AdmissionResponse{
Allowed: true,
PatchType: func() *admissionv1.PatchType { pt := admissionv1.PatchTypeJSONPatch; return &pt }(),
Allowed: true,
PatchType: func() *admissionv1.PatchType {
if len(patches) == 0 {
return nil
}
pt := admissionv1.PatchTypeJSONPatch
return &pt
}(),
},
}
}
Expand Down

0 comments on commit 66972d3

Please sign in to comment.