Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
16249951
Commit
16249951
authored
Jun 04, 2018
by
Cao Shufeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix a TODO in ValidatingAdmissionWebhook
parent
27c327cd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
67 deletions
+78
-67
plugin_test.go
...rver/pkg/admission/plugin/webhook/mutating/plugin_test.go
+4
-1
testcase.go
...piserver/pkg/admission/plugin/webhook/testing/testcase.go
+73
-60
plugin_test.go
...er/pkg/admission/plugin/webhook/validating/plugin_test.go
+1
-6
No files found.
staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/mutating/plugin_test.go
View file @
16249951
...
...
@@ -48,7 +48,10 @@ func TestAdmit(t *testing.T) {
stopCh
:=
make
(
chan
struct
{})
defer
close
(
stopCh
)
for
_
,
tt
:=
range
webhooktesting
.
NewTestCases
(
serverURL
)
{
testCases
:=
append
(
webhooktesting
.
NewMutatingTestCases
(
serverURL
),
webhooktesting
.
NewNonMutatingTestCases
(
serverURL
)
...
)
for
_
,
tt
:=
range
testCases
{
wh
,
err
:=
NewMutatingWebhook
(
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"%s: failed to create mutating webhook: %v"
,
tt
.
Name
,
err
)
...
...
staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/testing/testcase.go
View file @
16249951
...
...
@@ -155,8 +155,11 @@ type Test struct {
ErrorContains
string
}
// NewTestCases returns test cases with a given base url.
func
NewTestCases
(
url
*
url
.
URL
)
[]
Test
{
// NewNonMutatingTestCases returns test cases with a given base url.
// All test cases in NewNonMutatingTestCases have no Patch set in
// AdmissionResponse. The test cases are used by both MutatingAdmissionWebhook
// and ValidatingAdmissionWebhook.
func
NewNonMutatingTestCases
(
url
*
url
.
URL
)
[]
Test
{
policyFail
:=
registrationv1beta1
.
Fail
policyIgnore
:=
registrationv1beta1
.
Ignore
ccfgURL
:=
urlConfigGenerator
{
url
}
.
ccfgURL
...
...
@@ -185,64 +188,6 @@ func NewTestCases(url *url.URL) []Test {
ExpectAllow
:
true
,
},
{
Name
:
"match & remove label"
,
Webhooks
:
[]
registrationv1beta1
.
Webhook
{{
Name
:
"removeLabel"
,
ClientConfig
:
ccfgSVC
(
"removeLabel"
),
Rules
:
matchEverythingRules
,
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
}},
ExpectAllow
:
true
,
AdditionalLabels
:
map
[
string
]
string
{
"remove"
:
"me"
},
ExpectLabels
:
map
[
string
]
string
{
"pod.name"
:
"my-pod"
},
},
{
Name
:
"match & add label"
,
Webhooks
:
[]
registrationv1beta1
.
Webhook
{{
Name
:
"addLabel"
,
ClientConfig
:
ccfgSVC
(
"addLabel"
),
Rules
:
matchEverythingRules
,
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
}},
ExpectAllow
:
true
,
ExpectLabels
:
map
[
string
]
string
{
"pod.name"
:
"my-pod"
,
"added"
:
"test"
},
},
{
Name
:
"match CRD & add label"
,
Webhooks
:
[]
registrationv1beta1
.
Webhook
{{
Name
:
"addLabel"
,
ClientConfig
:
ccfgSVC
(
"addLabel"
),
Rules
:
matchEverythingRules
,
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
}},
IsCRD
:
true
,
ExpectAllow
:
true
,
ExpectLabels
:
map
[
string
]
string
{
"crd.name"
:
"my-test-crd"
,
"added"
:
"test"
},
},
{
Name
:
"match CRD & remove label"
,
Webhooks
:
[]
registrationv1beta1
.
Webhook
{{
Name
:
"removeLabel"
,
ClientConfig
:
ccfgSVC
(
"removeLabel"
),
Rules
:
matchEverythingRules
,
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
}},
IsCRD
:
true
,
ExpectAllow
:
true
,
AdditionalLabels
:
map
[
string
]
string
{
"remove"
:
"me"
},
ExpectLabels
:
map
[
string
]
string
{
"crd.name"
:
"my-test-crd"
},
},
{
Name
:
"match & invalid mutation"
,
Webhooks
:
[]
registrationv1beta1
.
Webhook
{{
Name
:
"invalidMutation"
,
ClientConfig
:
ccfgSVC
(
"invalidMutation"
),
Rules
:
matchEverythingRules
,
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
}},
ErrorContains
:
"invalid character"
,
},
{
Name
:
"match & disallow"
,
Webhooks
:
[]
registrationv1beta1
.
Webhook
{{
Name
:
"disallow"
,
...
...
@@ -409,6 +354,74 @@ func NewTestCases(url *url.URL) []Test {
}
}
// NewMutatingTestCases returns test cases with a given base url.
// All test cases in NewMutatingTestCases have Patch set in
// AdmissionResponse. The test cases are only used by both MutatingAdmissionWebhook.
func
NewMutatingTestCases
(
url
*
url
.
URL
)
[]
Test
{
return
[]
Test
{
{
Name
:
"match & remove label"
,
Webhooks
:
[]
registrationv1beta1
.
Webhook
{{
Name
:
"removeLabel"
,
ClientConfig
:
ccfgSVC
(
"removeLabel"
),
Rules
:
matchEverythingRules
,
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
}},
ExpectAllow
:
true
,
AdditionalLabels
:
map
[
string
]
string
{
"remove"
:
"me"
},
ExpectLabels
:
map
[
string
]
string
{
"pod.name"
:
"my-pod"
},
},
{
Name
:
"match & add label"
,
Webhooks
:
[]
registrationv1beta1
.
Webhook
{{
Name
:
"addLabel"
,
ClientConfig
:
ccfgSVC
(
"addLabel"
),
Rules
:
matchEverythingRules
,
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
}},
ExpectAllow
:
true
,
ExpectLabels
:
map
[
string
]
string
{
"pod.name"
:
"my-pod"
,
"added"
:
"test"
},
},
{
Name
:
"match CRD & add label"
,
Webhooks
:
[]
registrationv1beta1
.
Webhook
{{
Name
:
"addLabel"
,
ClientConfig
:
ccfgSVC
(
"addLabel"
),
Rules
:
matchEverythingRules
,
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
}},
IsCRD
:
true
,
ExpectAllow
:
true
,
ExpectLabels
:
map
[
string
]
string
{
"crd.name"
:
"my-test-crd"
,
"added"
:
"test"
},
},
{
Name
:
"match CRD & remove label"
,
Webhooks
:
[]
registrationv1beta1
.
Webhook
{{
Name
:
"removeLabel"
,
ClientConfig
:
ccfgSVC
(
"removeLabel"
),
Rules
:
matchEverythingRules
,
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
}},
IsCRD
:
true
,
ExpectAllow
:
true
,
AdditionalLabels
:
map
[
string
]
string
{
"remove"
:
"me"
},
ExpectLabels
:
map
[
string
]
string
{
"crd.name"
:
"my-test-crd"
},
},
{
Name
:
"match & invalid mutation"
,
Webhooks
:
[]
registrationv1beta1
.
Webhook
{{
Name
:
"invalidMutation"
,
ClientConfig
:
ccfgSVC
(
"invalidMutation"
),
Rules
:
matchEverythingRules
,
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
}},
ErrorContains
:
"invalid character"
,
},
// No need to test everything with the url case, since only the
// connection is different.
}
}
// CachedTest is a test case for the client manager.
type
CachedTest
struct
{
Name
string
...
...
staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/validating/plugin_test.go
View file @
16249951
...
...
@@ -46,12 +46,7 @@ func TestValidate(t *testing.T) {
stopCh
:=
make
(
chan
struct
{})
defer
close
(
stopCh
)
for
_
,
tt
:=
range
webhooktesting
.
NewTestCases
(
serverURL
)
{
// TODO: re-enable all tests
if
!
strings
.
Contains
(
tt
.
Name
,
"no match"
)
{
continue
}
for
_
,
tt
:=
range
webhooktesting
.
NewNonMutatingTestCases
(
serverURL
)
{
wh
,
err
:=
NewValidatingAdmissionWebhook
(
nil
)
if
err
!=
nil
{
t
.
Errorf
(
"%s: failed to create validating webhook: %v"
,
tt
.
Name
,
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment