Skip to content

Commit 5207b20

Browse files
authored
Merge pull request kubernetes#88544 from liggitt/test-admission-order
Ensure webhook/quota/deny admission comes last
2 parents 5cc572f + c80dcf5 commit 5207b20

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

pkg/kubeapiserver/options/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ go_test(
8989
"admission_test.go",
9090
"authentication_test.go",
9191
"authorization_test.go",
92+
"plugins_test.go",
9293
],
9394
data = [
9495
"testdata/client-expired.pem",

pkg/kubeapiserver/options/plugins.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,15 @@ var AllOrderedPlugins = []string{
8686
storageobjectinuseprotection.PluginName, // StorageObjectInUseProtection
8787
gc.PluginName, // OwnerReferencesPermissionEnforcement
8888
resize.PluginName, // PersistentVolumeClaimResize
89-
mutatingwebhook.PluginName, // MutatingAdmissionWebhook
90-
validatingwebhook.PluginName, // ValidatingAdmissionWebhook
91-
runtimeclass.PluginName, //RuntimeClass
92-
resourcequota.PluginName, // ResourceQuota
93-
deny.PluginName, // AlwaysDeny
89+
runtimeclass.PluginName, // RuntimeClass
90+
91+
// new admission plugins should generally be inserted above here
92+
// webhook, resourcequota, and deny plugins must go at the end
93+
94+
mutatingwebhook.PluginName, // MutatingAdmissionWebhook
95+
validatingwebhook.PluginName, // ValidatingAdmissionWebhook
96+
resourcequota.PluginName, // ResourceQuota
97+
deny.PluginName, // AlwaysDeny
9498
}
9599

96100
// RegisterAllAdmissionPlugins registers all admission plugins and
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package options
18+
19+
import (
20+
"strings"
21+
"testing"
22+
)
23+
24+
func TestAdmissionPluginOrder(t *testing.T) {
25+
// Ensure the last four admission plugins listed are webhooks, quota, and deny
26+
allplugins := strings.Join(AllOrderedPlugins, ",")
27+
expectSuffix := ",MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota,AlwaysDeny"
28+
if !strings.HasSuffix(allplugins, expectSuffix) {
29+
t.Fatalf("AllOrderedPlugins must end with ...%s", expectSuffix)
30+
}
31+
}

0 commit comments

Comments
 (0)