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
f5cb91af
Commit
f5cb91af
authored
Dec 18, 2015
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplified namespace related admission controllers
parent
20f9c2c5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
30 deletions
+15
-30
admission.go
plugin/pkg/admission/namespace/autoprovision/admission.go
+5
-10
admission.go
plugin/pkg/admission/namespace/exists/admission.go
+5
-10
admission.go
plugin/pkg/admission/namespace/lifecycle/admission.go
+5
-10
No files found.
plugin/pkg/admission/namespace/autoprovision/admission.go
View file @
f5cb91af
...
@@ -22,7 +22,6 @@ import (
...
@@ -22,7 +22,6 @@ import (
"k8s.io/kubernetes/pkg/admission"
"k8s.io/kubernetes/pkg/admission"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/client/cache"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
...
@@ -45,17 +44,13 @@ type provision struct {
...
@@ -45,17 +44,13 @@ type provision struct {
}
}
func
(
p
*
provision
)
Admit
(
a
admission
.
Attributes
)
(
err
error
)
{
func
(
p
*
provision
)
Admit
(
a
admission
.
Attributes
)
(
err
error
)
{
kind
,
err
:=
api
.
RESTMapper
.
KindFor
(
a
.
GetResource
()
.
WithVersion
(
""
))
// if we're here, then we've already passed authentication, so we're allowed to do what we're trying to do
if
err
!=
nil
{
// if we're here, then the API server has found a route, which means that if we have a non-empty namespace
return
admission
.
NewForbidden
(
a
,
err
)
// its a namespaced resource.
}
if
len
(
a
.
GetNamespace
())
==
0
||
a
.
GetKind
()
==
api
.
Kind
(
"Namespace"
)
{
mapping
,
err
:=
api
.
RESTMapper
.
RESTMapping
(
kind
.
GroupKind
(),
kind
.
Version
)
if
err
!=
nil
{
return
admission
.
NewForbidden
(
a
,
err
)
}
if
mapping
.
Scope
.
Name
()
!=
meta
.
RESTScopeNameNamespace
{
return
nil
return
nil
}
}
namespace
:=
&
api
.
Namespace
{
namespace
:=
&
api
.
Namespace
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
a
.
GetNamespace
(),
Name
:
a
.
GetNamespace
(),
...
...
plugin/pkg/admission/namespace/exists/admission.go
View file @
f5cb91af
...
@@ -23,7 +23,6 @@ import (
...
@@ -23,7 +23,6 @@ import (
"k8s.io/kubernetes/pkg/admission"
"k8s.io/kubernetes/pkg/admission"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/client/cache"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
...
@@ -46,17 +45,13 @@ type exists struct {
...
@@ -46,17 +45,13 @@ type exists struct {
}
}
func
(
e
*
exists
)
Admit
(
a
admission
.
Attributes
)
(
err
error
)
{
func
(
e
*
exists
)
Admit
(
a
admission
.
Attributes
)
(
err
error
)
{
kind
,
err
:=
api
.
RESTMapper
.
KindFor
(
a
.
GetResource
()
.
WithVersion
(
""
))
// if we're here, then we've already passed authentication, so we're allowed to do what we're trying to do
if
err
!=
nil
{
// if we're here, then the API server has found a route, which means that if we have a non-empty namespace
return
errors
.
NewInternalError
(
err
)
// its a namespaced resource.
}
if
len
(
a
.
GetNamespace
())
==
0
||
a
.
GetKind
()
==
api
.
Kind
(
"Namespace"
)
{
mapping
,
err
:=
api
.
RESTMapper
.
RESTMapping
(
kind
.
GroupKind
(),
kind
.
Version
)
if
err
!=
nil
{
return
errors
.
NewInternalError
(
err
)
}
if
mapping
.
Scope
.
Name
()
!=
meta
.
RESTScopeNameNamespace
{
return
nil
return
nil
}
}
namespace
:=
&
api
.
Namespace
{
namespace
:=
&
api
.
Namespace
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
a
.
GetNamespace
(),
Name
:
a
.
GetNamespace
(),
...
...
plugin/pkg/admission/namespace/lifecycle/admission.go
View file @
f5cb91af
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
"k8s.io/kubernetes/pkg/admission"
"k8s.io/kubernetes/pkg/admission"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/client/cache"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/runtime"
...
@@ -53,17 +52,13 @@ func (l *lifecycle) Admit(a admission.Attributes) (err error) {
...
@@ -53,17 +52,13 @@ func (l *lifecycle) Admit(a admission.Attributes) (err error) {
return
errors
.
NewForbidden
(
a
.
GetResource
(),
a
.
GetName
(),
fmt
.
Errorf
(
"this namespace may not be deleted"
))
return
errors
.
NewForbidden
(
a
.
GetResource
(),
a
.
GetName
(),
fmt
.
Errorf
(
"this namespace may not be deleted"
))
}
}
kind
,
err
:=
api
.
RESTMapper
.
KindFor
(
a
.
GetResource
()
.
WithVersion
(
""
))
// if we're here, then we've already passed authentication, so we're allowed to do what we're trying to do
if
err
!=
nil
{
// if we're here, then the API server has found a route, which means that if we have a non-empty namespace
return
errors
.
NewInternalError
(
err
)
// its a namespaced resource.
}
if
len
(
a
.
GetNamespace
())
==
0
||
a
.
GetKind
()
==
api
.
Kind
(
"Namespace"
)
{
mapping
,
err
:=
api
.
RESTMapper
.
RESTMapping
(
kind
.
GroupKind
(),
kind
.
Version
)
if
err
!=
nil
{
return
errors
.
NewInternalError
(
err
)
}
if
mapping
.
Scope
.
Name
()
!=
meta
.
RESTScopeNameNamespace
{
return
nil
return
nil
}
}
namespaceObj
,
exists
,
err
:=
l
.
store
.
Get
(
&
api
.
Namespace
{
namespaceObj
,
exists
,
err
:=
l
.
store
.
Get
(
&
api
.
Namespace
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
a
.
GetNamespace
(),
Name
:
a
.
GetNamespace
(),
...
...
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