Skip to content

Commit cc7700a

Browse files
committed
no admission logic
Signed-off-by: Serguei Bezverkhi <[email protected]>
1 parent 90fbbee commit cc7700a

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

test/integration/apiserver/admissionwebhook/admission_test.go

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ var (
113113
gvr("", "v1", "services/proxy"): {"*": testSubresourceProxy},
114114
}
115115

116+
// admissionExemptResources lists objects which are exempt from admission validation/mutation,
117+
// only resources exempted from admission processing by API server should be listed here.
118+
admissionExemptResources = map[schema.GroupVersionResource]bool{
119+
gvr("admissionregistration.k8s.io", "v1beta1", "mutatingwebhookconfigurations"): true,
120+
gvr("admissionregistration.k8s.io", "v1beta1", "validatingwebhookconfigurations"): true,
121+
}
116122
// excludedResources lists resources / verb combinations that are not yet tested. this set should trend to zero.
117123
excludedResources = map[schema.GroupVersionResource]sets.String{
118124
// TODO: verify non-persisted review objects work with webhook admission in place (and determine whether they should be sent to admission)
@@ -126,10 +132,6 @@ var (
126132
gvr("authorization.k8s.io", "v1beta1", "subjectaccessreviews"): sets.NewString("*"),
127133
gvr("authorization.k8s.io", "v1beta1", "selfsubjectaccessreviews"): sets.NewString("*"),
128134
gvr("authorization.k8s.io", "v1beta1", "selfsubjectrulesreviews"): sets.NewString("*"),
129-
130-
// TODO: webhook config objects are not subject to admission, verify CRUD works and webhooks do not observe them
131-
gvr("admissionregistration.k8s.io", "v1beta1", "mutatingwebhookconfigurations"): sets.NewString("*"),
132-
gvr("admissionregistration.k8s.io", "v1beta1", "validatingwebhookconfigurations"): sets.NewString("*"),
133135
}
134136

135137
parentResources = map[schema.GroupVersionResource]schema.GroupVersionResource{
@@ -142,11 +144,12 @@ type holder struct {
142144

143145
t *testing.T
144146

145-
expectGVR metav1.GroupVersionResource
147+
recordGVR metav1.GroupVersionResource
148+
recordOperation v1beta1.Operation
149+
recordNamespace string
150+
recordName string
151+
146152
expectGVK schema.GroupVersionKind
147-
expectOperation v1beta1.Operation
148-
expectNamespace string
149-
expectName string
150153
expectObject bool
151154
expectOldObject bool
152155

@@ -157,11 +160,11 @@ func (h *holder) reset(t *testing.T) {
157160
h.lock.Lock()
158161
defer h.lock.Unlock()
159162
h.t = t
160-
h.expectGVR = metav1.GroupVersionResource{}
163+
h.recordGVR = metav1.GroupVersionResource{}
161164
h.expectGVK = schema.GroupVersionKind{}
162-
h.expectOperation = ""
163-
h.expectName = ""
164-
h.expectNamespace = ""
165+
h.recordOperation = ""
166+
h.recordName = ""
167+
h.recordNamespace = ""
165168
h.expectObject = false
166169
h.expectOldObject = false
167170
h.recorded = map[string]*v1beta1.AdmissionRequest{
@@ -177,11 +180,11 @@ func (h *holder) expect(gvr schema.GroupVersionResource, gvk schema.GroupVersion
177180

178181
h.lock.Lock()
179182
defer h.lock.Unlock()
180-
h.expectGVR = metav1.GroupVersionResource{Group: gvr.Group, Version: gvr.Version, Resource: gvr.Resource}
183+
h.recordGVR = metav1.GroupVersionResource{Group: gvr.Group, Version: gvr.Version, Resource: gvr.Resource}
181184
h.expectGVK = gvk
182-
h.expectOperation = operation
183-
h.expectName = name
184-
h.expectNamespace = namespace
185+
h.recordOperation = operation
186+
h.recordName = name
187+
h.recordNamespace = namespace
185188
h.expectObject = object
186189
h.expectOldObject = oldObject
187190
h.recorded = map[string]*v1beta1.AdmissionRequest{
@@ -203,22 +206,22 @@ func (h *holder) record(phase string, request *v1beta1.AdmissionRequest) {
203206
if len(request.SubResource) > 0 {
204207
resource.Resource += "/" + request.SubResource
205208
}
206-
if resource != h.expectGVR {
209+
if resource != h.recordGVR {
207210
if debug {
208-
h.t.Log(resource, "!=", h.expectGVR)
211+
h.t.Log(resource, "!=", h.recordGVR)
209212
}
210213
return
211214
}
212215

213-
if request.Operation != h.expectOperation {
216+
if request.Operation != h.recordOperation {
214217
if debug {
215-
h.t.Log(request.Operation, "!=", h.expectOperation)
218+
h.t.Log(request.Operation, "!=", h.recordOperation)
216219
}
217220
return
218221
}
219-
if request.Namespace != h.expectNamespace {
222+
if request.Namespace != h.recordNamespace {
220223
if debug {
221-
h.t.Log(request.Namespace, "!=", h.expectNamespace)
224+
h.t.Log(request.Namespace, "!=", h.recordNamespace)
222225
}
223226
return
224227
}
@@ -227,9 +230,9 @@ func (h *holder) record(phase string, request *v1beta1.AdmissionRequest) {
227230
if name == "" && request.Object.Object != nil {
228231
name = request.Object.Object.(*unstructured.Unstructured).GetName()
229232
}
230-
if name != h.expectName {
233+
if name != h.recordName {
231234
if debug {
232-
h.t.Log(name, "!=", h.expectName)
235+
h.t.Log(name, "!=", h.recordName)
233236
}
234237
return
235238
}
@@ -250,6 +253,14 @@ func (h *holder) verify(t *testing.T) {
250253
}
251254

252255
func (h *holder) verifyRequest(request *v1beta1.AdmissionRequest) error {
256+
// Check if current resource should be exempted from Admission processing
257+
if admissionExemptResources[gvr(h.recordGVR.Group, h.recordGVR.Version, h.recordGVR.Resource)] {
258+
if request == nil {
259+
return nil
260+
}
261+
return fmt.Errorf("admission webhook was called, but not supposed to")
262+
}
263+
253264
if request == nil {
254265
return fmt.Errorf("no request received")
255266
}

0 commit comments

Comments
 (0)