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
cc7700ae
Commit
cc7700ae
authored
Apr 23, 2019
by
Serguei Bezverkhi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no admission logic
Signed-off-by:
Serguei Bezverkhi
<
sbezverk@cisco.com
>
parent
90fbbee1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
24 deletions
+35
-24
admission_test.go
.../integration/apiserver/admissionwebhook/admission_test.go
+35
-24
No files found.
test/integration/apiserver/admissionwebhook/admission_test.go
View file @
cc7700ae
...
...
@@ -113,6 +113,12 @@ var (
gvr
(
""
,
"v1"
,
"services/proxy"
)
:
{
"*"
:
testSubresourceProxy
},
}
// admissionExemptResources lists objects which are exempt from admission validation/mutation,
// only resources exempted from admission processing by API server should be listed here.
admissionExemptResources
=
map
[
schema
.
GroupVersionResource
]
bool
{
gvr
(
"admissionregistration.k8s.io"
,
"v1beta1"
,
"mutatingwebhookconfigurations"
)
:
true
,
gvr
(
"admissionregistration.k8s.io"
,
"v1beta1"
,
"validatingwebhookconfigurations"
)
:
true
,
}
// excludedResources lists resources / verb combinations that are not yet tested. this set should trend to zero.
excludedResources
=
map
[
schema
.
GroupVersionResource
]
sets
.
String
{
// 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 (
gvr
(
"authorization.k8s.io"
,
"v1beta1"
,
"subjectaccessreviews"
)
:
sets
.
NewString
(
"*"
),
gvr
(
"authorization.k8s.io"
,
"v1beta1"
,
"selfsubjectaccessreviews"
)
:
sets
.
NewString
(
"*"
),
gvr
(
"authorization.k8s.io"
,
"v1beta1"
,
"selfsubjectrulesreviews"
)
:
sets
.
NewString
(
"*"
),
// TODO: webhook config objects are not subject to admission, verify CRUD works and webhooks do not observe them
gvr
(
"admissionregistration.k8s.io"
,
"v1beta1"
,
"mutatingwebhookconfigurations"
)
:
sets
.
NewString
(
"*"
),
gvr
(
"admissionregistration.k8s.io"
,
"v1beta1"
,
"validatingwebhookconfigurations"
)
:
sets
.
NewString
(
"*"
),
}
parentResources
=
map
[
schema
.
GroupVersionResource
]
schema
.
GroupVersionResource
{
...
...
@@ -142,11 +144,12 @@ type holder struct {
t
*
testing
.
T
expectGVR
metav1
.
GroupVersionResource
recordGVR
metav1
.
GroupVersionResource
recordOperation
v1beta1
.
Operation
recordNamespace
string
recordName
string
expectGVK
schema
.
GroupVersionKind
expectOperation
v1beta1
.
Operation
expectNamespace
string
expectName
string
expectObject
bool
expectOldObject
bool
...
...
@@ -157,11 +160,11 @@ func (h *holder) reset(t *testing.T) {
h
.
lock
.
Lock
()
defer
h
.
lock
.
Unlock
()
h
.
t
=
t
h
.
expect
GVR
=
metav1
.
GroupVersionResource
{}
h
.
record
GVR
=
metav1
.
GroupVersionResource
{}
h
.
expectGVK
=
schema
.
GroupVersionKind
{}
h
.
expect
Operation
=
""
h
.
expect
Name
=
""
h
.
expect
Namespace
=
""
h
.
record
Operation
=
""
h
.
record
Name
=
""
h
.
record
Namespace
=
""
h
.
expectObject
=
false
h
.
expectOldObject
=
false
h
.
recorded
=
map
[
string
]
*
v1beta1
.
AdmissionRequest
{
...
...
@@ -177,11 +180,11 @@ func (h *holder) expect(gvr schema.GroupVersionResource, gvk schema.GroupVersion
h
.
lock
.
Lock
()
defer
h
.
lock
.
Unlock
()
h
.
expect
GVR
=
metav1
.
GroupVersionResource
{
Group
:
gvr
.
Group
,
Version
:
gvr
.
Version
,
Resource
:
gvr
.
Resource
}
h
.
record
GVR
=
metav1
.
GroupVersionResource
{
Group
:
gvr
.
Group
,
Version
:
gvr
.
Version
,
Resource
:
gvr
.
Resource
}
h
.
expectGVK
=
gvk
h
.
expect
Operation
=
operation
h
.
expect
Name
=
name
h
.
expect
Namespace
=
namespace
h
.
record
Operation
=
operation
h
.
record
Name
=
name
h
.
record
Namespace
=
namespace
h
.
expectObject
=
object
h
.
expectOldObject
=
oldObject
h
.
recorded
=
map
[
string
]
*
v1beta1
.
AdmissionRequest
{
...
...
@@ -203,22 +206,22 @@ func (h *holder) record(phase string, request *v1beta1.AdmissionRequest) {
if
len
(
request
.
SubResource
)
>
0
{
resource
.
Resource
+=
"/"
+
request
.
SubResource
}
if
resource
!=
h
.
expect
GVR
{
if
resource
!=
h
.
record
GVR
{
if
debug
{
h
.
t
.
Log
(
resource
,
"!="
,
h
.
expect
GVR
)
h
.
t
.
Log
(
resource
,
"!="
,
h
.
record
GVR
)
}
return
}
if
request
.
Operation
!=
h
.
expect
Operation
{
if
request
.
Operation
!=
h
.
record
Operation
{
if
debug
{
h
.
t
.
Log
(
request
.
Operation
,
"!="
,
h
.
expect
Operation
)
h
.
t
.
Log
(
request
.
Operation
,
"!="
,
h
.
record
Operation
)
}
return
}
if
request
.
Namespace
!=
h
.
expect
Namespace
{
if
request
.
Namespace
!=
h
.
record
Namespace
{
if
debug
{
h
.
t
.
Log
(
request
.
Namespace
,
"!="
,
h
.
expect
Namespace
)
h
.
t
.
Log
(
request
.
Namespace
,
"!="
,
h
.
record
Namespace
)
}
return
}
...
...
@@ -227,9 +230,9 @@ func (h *holder) record(phase string, request *v1beta1.AdmissionRequest) {
if
name
==
""
&&
request
.
Object
.
Object
!=
nil
{
name
=
request
.
Object
.
Object
.
(
*
unstructured
.
Unstructured
)
.
GetName
()
}
if
name
!=
h
.
expect
Name
{
if
name
!=
h
.
record
Name
{
if
debug
{
h
.
t
.
Log
(
name
,
"!="
,
h
.
expect
Name
)
h
.
t
.
Log
(
name
,
"!="
,
h
.
record
Name
)
}
return
}
...
...
@@ -250,6 +253,14 @@ func (h *holder) verify(t *testing.T) {
}
func
(
h
*
holder
)
verifyRequest
(
request
*
v1beta1
.
AdmissionRequest
)
error
{
// Check if current resource should be exempted from Admission processing
if
admissionExemptResources
[
gvr
(
h
.
recordGVR
.
Group
,
h
.
recordGVR
.
Version
,
h
.
recordGVR
.
Resource
)]
{
if
request
==
nil
{
return
nil
}
return
fmt
.
Errorf
(
"admission webhook was called, but not supposed to"
)
}
if
request
==
nil
{
return
fmt
.
Errorf
(
"no request received"
)
}
...
...
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