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
0d717272
Commit
0d717272
authored
Jan 11, 2018
by
Chao Xu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Never let cluster-scoped resources skip webhooks
parent
dc9dd59a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
9 deletions
+9
-9
types.go
pkg/apis/admissionregistration/types.go
+2
-2
types.go
...ing/src/k8s.io/api/admissionregistration/v1beta1/types.go
+2
-2
matcher.go
...iserver/pkg/admission/plugin/webhook/namespace/matcher.go
+2
-2
matcher_test.go
...er/pkg/admission/plugin/webhook/namespace/matcher_test.go
+3
-3
No files found.
pkg/apis/admissionregistration/types.go
View file @
0d717272
...
@@ -195,8 +195,8 @@ type Webhook struct {
...
@@ -195,8 +195,8 @@ type Webhook struct {
// NamespaceSelector decides whether to run the webhook on an object based
// NamespaceSelector decides whether to run the webhook on an object based
// on whether the namespace for that object matches the selector. If the
// on whether the namespace for that object matches the selector. If the
// object itself is a namespace, the matching is performed on
// object itself is a namespace, the matching is performed on
// object.metadata.labels. If the object is other cluster scoped resource,
// object.metadata.labels. If the object is
an
other cluster scoped resource,
// it
is not subjected to
the webhook.
// it
never skips
the webhook.
//
//
// For example, to run the webhook on any objects whose namespace is not
// For example, to run the webhook on any objects whose namespace is not
// associated with "runlevel" of "0" or "1"; you will set the selector as
// associated with "runlevel" of "0" or "1"; you will set the selector as
...
...
staging/src/k8s.io/api/admissionregistration/v1beta1/types.go
View file @
0d717272
...
@@ -147,8 +147,8 @@ type Webhook struct {
...
@@ -147,8 +147,8 @@ type Webhook struct {
// NamespaceSelector decides whether to run the webhook on an object based
// NamespaceSelector decides whether to run the webhook on an object based
// on whether the namespace for that object matches the selector. If the
// on whether the namespace for that object matches the selector. If the
// object itself is a namespace, the matching is performed on
// object itself is a namespace, the matching is performed on
// object.metadata.labels. If the object is other cluster scoped resource,
// object.metadata.labels. If the object is
an
other cluster scoped resource,
// it
is not subjected to
the webhook.
// it
never skips
the webhook.
//
//
// For example, to run the webhook on any objects whose namespace is not
// For example, to run the webhook on any objects whose namespace is not
// associated with "runlevel" of "0" or "1"; you will set the selector as
// associated with "runlevel" of "0" or "1"; you will set the selector as
...
...
staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/namespace/matcher.go
View file @
0d717272
...
@@ -90,10 +90,10 @@ func (m *Matcher) MatchNamespaceSelector(h *v1beta1.Webhook, attr admission.Attr
...
@@ -90,10 +90,10 @@ func (m *Matcher) MatchNamespaceSelector(h *v1beta1.Webhook, attr admission.Attr
namespaceName
:=
attr
.
GetNamespace
()
namespaceName
:=
attr
.
GetNamespace
()
if
len
(
namespaceName
)
==
0
&&
attr
.
GetResource
()
.
Resource
!=
"namespaces"
{
if
len
(
namespaceName
)
==
0
&&
attr
.
GetResource
()
.
Resource
!=
"namespaces"
{
// If the request is about a cluster scoped resource, and it is not a
// If the request is about a cluster scoped resource, and it is not a
// namespace, it is
exempted from all webhooks for now
.
// namespace, it is
never exempted
.
// TODO: figure out a way selective exempt cluster scoped resources.
// TODO: figure out a way selective exempt cluster scoped resources.
// Also update the comment in types.go
// Also update the comment in types.go
return
fals
e
,
nil
return
tru
e
,
nil
}
}
namespaceLabels
,
err
:=
m
.
GetNamespaceLabels
(
attr
)
namespaceLabels
,
err
:=
m
.
GetNamespaceLabels
(
attr
)
// this means the namespace is not found, for backwards compatibility,
// this means the namespace is not found, for backwards compatibility,
...
...
staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/namespace/matcher_test.go
View file @
0d717272
...
@@ -113,7 +113,7 @@ func TestGetNamespaceLabels(t *testing.T) {
...
@@ -113,7 +113,7 @@ func TestGetNamespaceLabels(t *testing.T) {
}
}
}
}
func
TestExemptClusterScopedResource
(
t
*
testing
.
T
)
{
func
Test
Not
ExemptClusterScopedResource
(
t
*
testing
.
T
)
{
hook
:=
&
registrationv1beta1
.
Webhook
{
hook
:=
&
registrationv1beta1
.
Webhook
{
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
NamespaceSelector
:
&
metav1
.
LabelSelector
{},
}
}
...
@@ -123,7 +123,7 @@ func TestExemptClusterScopedResource(t *testing.T) {
...
@@ -123,7 +123,7 @@ func TestExemptClusterScopedResource(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
matches
{
if
!
matches
{
t
.
Errorf
(
"cluster scoped resources (but not a namespace) should
be exempted from all
webhooks"
)
t
.
Errorf
(
"cluster scoped resources (but not a namespace) should
not be exempted from
webhooks"
)
}
}
}
}
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