@@ -38,6 +38,7 @@ import (
38
38
"k8s.io/client-go/informers"
39
39
"k8s.io/client-go/kubernetes"
40
40
fakeclientset "k8s.io/client-go/kubernetes/fake"
41
+ "k8s.io/utils/ptr"
41
42
)
42
43
43
44
var matchEverythingRules = []registrationv1.RuleWithOperations {{
@@ -897,6 +898,40 @@ func NewMutatingTestCases(url *url.URL, configurationName string) []MutatingTest
897
898
"mutation.webhook.admission.k8s.io/round_0_index_0" : mutationAnnotationValue (configurationName , "invalidMutation" , false ),
898
899
},
899
900
},
901
+ {
902
+ Name : "match & invalid patch" ,
903
+ Webhooks : []registrationv1.MutatingWebhook {{
904
+ Name : "invalidPatch" ,
905
+ ClientConfig : ccfgSVC ("invalidPatch" ),
906
+ Rules : matchEverythingRules ,
907
+ NamespaceSelector : & metav1.LabelSelector {},
908
+ ObjectSelector : & metav1.LabelSelector {},
909
+ AdmissionReviewVersions : []string {"v1beta1" },
910
+ }},
911
+ ExpectStatusCode : http .StatusInternalServerError ,
912
+ ErrorContains : "unexpected end of JSON input" ,
913
+ ExpectAnnotations : map [string ]string {
914
+ "mutation.webhook.admission.k8s.io/round_0_index_0" : mutationAnnotationValue (configurationName , "invalidPatch" , false ),
915
+ },
916
+ },
917
+ {
918
+ Name : "match & invalid patch fail open" ,
919
+ Webhooks : []registrationv1.MutatingWebhook {{
920
+ Name : "invalidPatch" ,
921
+ ClientConfig : ccfgSVC ("invalidPatch" ),
922
+ Rules : matchEverythingRules ,
923
+ NamespaceSelector : & metav1.LabelSelector {},
924
+ ObjectSelector : & metav1.LabelSelector {},
925
+ AdmissionReviewVersions : []string {"v1beta1" },
926
+ FailurePolicy : ptr .To (registrationv1 .Ignore ),
927
+ }},
928
+ ExpectAllow : true ,
929
+ ExpectStatusCode : http .StatusOK ,
930
+ ExpectAnnotations : map [string ]string {
931
+ "failed-open.mutation.webhook.admission.k8s.io/round_0_index_0" : "invalidPatch" ,
932
+ "mutation.webhook.admission.k8s.io/round_0_index_0" : mutationAnnotationValue (configurationName , "invalidPatch" , false ),
933
+ },
934
+ },
900
935
{
901
936
Name : "match & remove label dry run unsupported" ,
902
937
Webhooks : []registrationv1.MutatingWebhook {{
0 commit comments