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
a2689736
Unverified
Commit
a2689736
authored
May 19, 2017
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use name from node object on create
parent
ead8c98c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
6 deletions
+29
-6
admission.go
plugin/pkg/admission/noderestriction/admission.go
+13
-2
admission_test.go
plugin/pkg/admission/noderestriction/admission_test.go
+16
-4
No files found.
plugin/pkg/admission/noderestriction/admission.go
View file @
a2689736
...
@@ -196,8 +196,19 @@ func (c *nodePlugin) admitPodStatus(nodeName string, a admission.Attributes) err
...
@@ -196,8 +196,19 @@ func (c *nodePlugin) admitPodStatus(nodeName string, a admission.Attributes) err
}
}
func
(
c
*
nodePlugin
)
admitNode
(
nodeName
string
,
a
admission
.
Attributes
)
error
{
func
(
c
*
nodePlugin
)
admitNode
(
nodeName
string
,
a
admission
.
Attributes
)
error
{
if
a
.
GetName
()
!=
nodeName
{
requestedName
:=
a
.
GetName
()
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"cannot modify other nodes"
))
// On create, get name from new object if unset in admission
if
len
(
requestedName
)
==
0
&&
a
.
GetOperation
()
==
admission
.
Create
{
node
,
ok
:=
a
.
GetObject
()
.
(
*
api
.
Node
)
if
!
ok
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"unexpected type %T"
,
a
.
GetObject
()))
}
requestedName
=
node
.
Name
}
if
requestedName
!=
nodeName
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"node %s cannot modify node %s"
,
nodeName
,
requestedName
))
}
}
return
nil
return
nil
}
}
plugin/pkg/admission/noderestriction/admission_test.go
View file @
a2689736
...
@@ -357,6 +357,12 @@ func Test_nodePlugin_Admit(t *testing.T) {
...
@@ -357,6 +357,12 @@ func Test_nodePlugin_Admit(t *testing.T) {
err
:
""
,
err
:
""
,
},
},
{
{
name
:
"allow create of my node pulling name from object"
,
podsGetter
:
noExistingPods
,
attributes
:
admission
.
NewAttributesRecord
(
mynodeObj
,
nil
,
nodeKind
,
mynodeObj
.
Namespace
,
""
,
nodeResource
,
""
,
admission
.
Create
,
mynode
),
err
:
""
,
},
{
name
:
"allow update of my node"
,
name
:
"allow update of my node"
,
podsGetter
:
existingPods
,
podsGetter
:
existingPods
,
attributes
:
admission
.
NewAttributesRecord
(
mynodeObj
,
mynodeObj
,
nodeKind
,
mynodeObj
.
Namespace
,
mynodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Update
,
mynode
),
attributes
:
admission
.
NewAttributesRecord
(
mynodeObj
,
mynodeObj
,
nodeKind
,
mynodeObj
.
Namespace
,
mynodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Update
,
mynode
),
...
@@ -380,25 +386,31 @@ func Test_nodePlugin_Admit(t *testing.T) {
...
@@ -380,25 +386,31 @@ func Test_nodePlugin_Admit(t *testing.T) {
name
:
"forbid create of other node"
,
name
:
"forbid create of other node"
,
podsGetter
:
noExistingPods
,
podsGetter
:
noExistingPods
,
attributes
:
admission
.
NewAttributesRecord
(
othernodeObj
,
nil
,
nodeKind
,
othernodeObj
.
Namespace
,
othernodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Create
,
mynode
),
attributes
:
admission
.
NewAttributesRecord
(
othernodeObj
,
nil
,
nodeKind
,
othernodeObj
.
Namespace
,
othernodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Create
,
mynode
),
err
:
"cannot modify other nodes"
,
err
:
"cannot modify node"
,
},
{
name
:
"forbid create of other node pulling name from object"
,
podsGetter
:
noExistingPods
,
attributes
:
admission
.
NewAttributesRecord
(
othernodeObj
,
nil
,
nodeKind
,
othernodeObj
.
Namespace
,
""
,
nodeResource
,
""
,
admission
.
Create
,
mynode
),
err
:
"cannot modify node"
,
},
},
{
{
name
:
"forbid update of other node"
,
name
:
"forbid update of other node"
,
podsGetter
:
existingPods
,
podsGetter
:
existingPods
,
attributes
:
admission
.
NewAttributesRecord
(
othernodeObj
,
othernodeObj
,
nodeKind
,
othernodeObj
.
Namespace
,
othernodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Update
,
mynode
),
attributes
:
admission
.
NewAttributesRecord
(
othernodeObj
,
othernodeObj
,
nodeKind
,
othernodeObj
.
Namespace
,
othernodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Update
,
mynode
),
err
:
"cannot modify
other nodes
"
,
err
:
"cannot modify
node
"
,
},
},
{
{
name
:
"forbid delete of other node"
,
name
:
"forbid delete of other node"
,
podsGetter
:
existingPods
,
podsGetter
:
existingPods
,
attributes
:
admission
.
NewAttributesRecord
(
nil
,
nil
,
nodeKind
,
othernodeObj
.
Namespace
,
othernodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Delete
,
mynode
),
attributes
:
admission
.
NewAttributesRecord
(
nil
,
nil
,
nodeKind
,
othernodeObj
.
Namespace
,
othernodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Delete
,
mynode
),
err
:
"cannot modify
other nodes
"
,
err
:
"cannot modify
node
"
,
},
},
{
{
name
:
"forbid update of other node status"
,
name
:
"forbid update of other node status"
,
podsGetter
:
existingPods
,
podsGetter
:
existingPods
,
attributes
:
admission
.
NewAttributesRecord
(
othernodeObj
,
othernodeObj
,
nodeKind
,
othernodeObj
.
Namespace
,
othernodeObj
.
Name
,
nodeResource
,
"status"
,
admission
.
Update
,
mynode
),
attributes
:
admission
.
NewAttributesRecord
(
othernodeObj
,
othernodeObj
,
nodeKind
,
othernodeObj
.
Namespace
,
othernodeObj
.
Name
,
nodeResource
,
"status"
,
admission
.
Update
,
mynode
),
err
:
"cannot modify
other nodes
"
,
err
:
"cannot modify
node
"
,
},
},
// Unrelated objects
// Unrelated objects
...
...
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