Skip to content

Commit b99ded6

Browse files
Tatsuhiro TsujikawaRainbowMango
authored andcommitted
Do not set PatchType if patch is empty
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.
1 parent 743bd5e commit b99ded6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/webhook/admission/response.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ func PatchResponseFromRaw(original, current []byte) Response {
9090
return Response{
9191
Patches: patches,
9292
AdmissionResponse: admissionv1.AdmissionResponse{
93-
Allowed: true,
94-
PatchType: func() *admissionv1.PatchType { pt := admissionv1.PatchTypeJSONPatch; return &pt }(),
93+
Allowed: true,
94+
PatchType: func() *admissionv1.PatchType {
95+
if len(patches) == 0 {
96+
return nil
97+
}
98+
pt := admissionv1.PatchTypeJSONPatch
99+
return &pt
100+
}(),
95101
},
96102
}
97103
}

0 commit comments

Comments
 (0)