@@ -46,6 +46,17 @@ var _ = Describe("Multi-Handler Admission Webhooks", func() {
46
46
},
47
47
}
48
48
49
+ withWarnings := & fakeHandler {
50
+ fn : func (ctx context.Context , req Request ) Response {
51
+ return Response {
52
+ AdmissionResponse : admissionv1.AdmissionResponse {
53
+ Allowed : true ,
54
+ Warnings : []string {"handler-warning" },
55
+ },
56
+ }
57
+ },
58
+ }
59
+
49
60
Context ("with validating handlers" , func () {
50
61
It ("should deny the request if any handler denies the request" , func () {
51
62
By ("setting up a handler with accept and deny" )
@@ -54,6 +65,7 @@ var _ = Describe("Multi-Handler Admission Webhooks", func() {
54
65
By ("checking that the handler denies the request" )
55
66
resp := handler .Handle (context .Background (), Request {})
56
67
Expect (resp .Allowed ).To (BeFalse ())
68
+ Expect (resp .Warnings ).To (BeEmpty ())
57
69
})
58
70
59
71
It ("should allow the request if all handlers allow the request" , func () {
@@ -63,6 +75,17 @@ var _ = Describe("Multi-Handler Admission Webhooks", func() {
63
75
By ("checking that the handler allows the request" )
64
76
resp := handler .Handle (context .Background (), Request {})
65
77
Expect (resp .Allowed ).To (BeTrue ())
78
+ Expect (resp .Warnings ).To (BeEmpty ())
79
+ })
80
+
81
+ It ("should show the warnings if all handlers allow the request" , func () {
82
+ By ("setting up a handler with only accept" )
83
+ handler := MultiValidatingHandler (alwaysAllow , withWarnings )
84
+
85
+ By ("checking that the handler allows the request" )
86
+ resp := handler .Handle (context .Background (), Request {})
87
+ Expect (resp .Allowed ).To (BeTrue ())
88
+ Expect (resp .Warnings ).To (HaveLen (1 ))
66
89
})
67
90
})
68
91
@@ -107,6 +130,25 @@ var _ = Describe("Multi-Handler Admission Webhooks", func() {
107
130
},
108
131
}
109
132
133
+ patcher3 := & fakeHandler {
134
+ fn : func (ctx context.Context , req Request ) Response {
135
+ return Response {
136
+ Patches : []jsonpatch.JsonPatchOperation {
137
+ {
138
+ Operation : "add" ,
139
+ Path : "/metadata/annotation/newest-key" ,
140
+ Value : "value" ,
141
+ },
142
+ },
143
+ AdmissionResponse : admissionv1.AdmissionResponse {
144
+ Allowed : true ,
145
+ Warnings : []string {"annotation-warning" },
146
+ PatchType : func () * admissionv1.PatchType { pt := admissionv1 .PatchTypeJSONPatch ; return & pt }(),
147
+ },
148
+ }
149
+ },
150
+ }
151
+
110
152
It ("should not return any patches if the request is denied" , func () {
111
153
By ("setting up a webhook with some patches and a deny" )
112
154
handler := MultiMutatingHandler (patcher1 , patcher2 , alwaysDeny )
@@ -128,5 +170,20 @@ var _ = Describe("Multi-Handler Admission Webhooks", func() {
128
170
`[{"op":"add","path":"/metadata/annotation/new-key","value":"new-value"},` +
129
171
`{"op":"replace","path":"/spec/replicas","value":"2"},{"op":"add","path":"/metadata/annotation/hello","value":"world"}]` )))
130
172
})
173
+
174
+ It ("should produce all patches if the requests are all allowed and show warnings" , func () {
175
+ By ("setting up a webhook with some patches" )
176
+ handler := MultiMutatingHandler (patcher1 , patcher2 , alwaysAllow , patcher3 )
177
+
178
+ By ("checking that the handler accepts the request and returns all patches" )
179
+ resp := handler .Handle (context .Background (), Request {})
180
+ Expect (resp .Allowed ).To (BeTrue ())
181
+ Expect (resp .Patch ).To (Equal ([]byte (
182
+ `[{"op":"add","path":"/metadata/annotation/new-key","value":"new-value"},` +
183
+ `{"op":"replace","path":"/spec/replicas","value":"2"},{"op":"add","path":"/metadata/annotation/hello","value":"world"},` +
184
+ `{"op":"add","path":"/metadata/annotation/newest-key","value":"value"}]` )))
185
+ Expect (resp .Warnings ).To (HaveLen (1 ))
186
+ })
187
+
131
188
})
132
189
})
0 commit comments