From 6acc75b4185170eb01be266519faf65e329312e3 Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Mon, 3 Feb 2020 10:55:31 -0800 Subject: [PATCH] Only set admission review reponse patch type if the patch is not empty --- test/images/agnhost/webhook/configmap.go | 6 ++++-- test/images/agnhost/webhook/customresource.go | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/images/agnhost/webhook/configmap.go b/test/images/agnhost/webhook/configmap.go index 85fbb1db63f..3ccdf4e27e3 100644 --- a/test/images/agnhost/webhook/configmap.go +++ b/test/images/agnhost/webhook/configmap.go @@ -97,8 +97,10 @@ func mutateConfigmaps(ar v1.AdmissionReview) *v1.AdmissionResponse { reviewResponse.Patch = []byte(configMapPatch2) } - pt := v1.PatchTypeJSONPatch - reviewResponse.PatchType = &pt + if len(reviewResponse.Patch) != 0 { + pt := v1.PatchTypeJSONPatch + reviewResponse.PatchType = &pt + } return &reviewResponse } diff --git a/test/images/agnhost/webhook/customresource.go b/test/images/agnhost/webhook/customresource.go index a1452d6454e..50289e09915 100644 --- a/test/images/agnhost/webhook/customresource.go +++ b/test/images/agnhost/webhook/customresource.go @@ -56,8 +56,10 @@ func mutateCustomResource(ar v1.AdmissionReview) *v1.AdmissionResponse { if cr.Data["mutation-stage-1"] == "yes" { reviewResponse.Patch = []byte(customResourcePatch2) } - pt := v1.PatchTypeJSONPatch - reviewResponse.PatchType = &pt + if len(reviewResponse.Patch) != 0 { + pt := v1.PatchTypeJSONPatch + reviewResponse.PatchType = &pt + } return &reviewResponse }