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
15bcfd5e
Unverified
Commit
15bcfd5e
authored
Apr 25, 2018
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent nodes from updating taints
parent
bd0d0937
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
admission.go
plugin/pkg/admission/noderestriction/admission.go
+6
-0
admission_test.go
plugin/pkg/admission/noderestriction/admission_test.go
+33
-1
No files found.
plugin/pkg/admission/noderestriction/admission.go
View file @
15bcfd5e
...
...
@@ -338,6 +338,12 @@ func (c *nodePlugin) admitNode(nodeName string, a admission.Attributes) error {
if
node
.
Spec
.
ConfigSource
!=
nil
&&
!
apiequality
.
Semantic
.
DeepEqual
(
node
.
Spec
.
ConfigSource
,
oldNode
.
Spec
.
ConfigSource
)
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"cannot update configSource to a new non-nil configSource"
))
}
// Don't allow a node to update its own taints. This would allow a node to remove or modify its
// taints in a way that would let it steer disallowed workloads to itself.
if
!
apiequality
.
Semantic
.
DeepEqual
(
node
.
Spec
.
Taints
,
oldNode
.
Spec
.
Taints
)
{
return
admission
.
NewForbidden
(
a
,
fmt
.
Errorf
(
"cannot modify taints"
))
}
}
return
nil
...
...
plugin/pkg/admission/noderestriction/admission_test.go
View file @
15bcfd5e
...
...
@@ -105,7 +105,9 @@ func Test_nodePlugin_Admit(t *testing.T) {
UID
:
"quxUID"
,
KubeletConfigKey
:
"kubelet"
,
}}}}
othernodeObj
=
&
api
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"othernode"
}}
mynodeObjTaintA
=
&
api
.
Node
{
ObjectMeta
:
mynodeObjMeta
,
Spec
:
api
.
NodeSpec
{
Taints
:
[]
api
.
Taint
{{
Key
:
"mykey"
,
Value
:
"A"
}}}}
mynodeObjTaintB
=
&
api
.
Node
{
ObjectMeta
:
mynodeObjMeta
,
Spec
:
api
.
NodeSpec
{
Taints
:
[]
api
.
Taint
{{
Key
:
"mykey"
,
Value
:
"B"
}}}}
othernodeObj
=
&
api
.
Node
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"othernode"
}}
mymirrorpod
=
makeTestPod
(
"ns"
,
"mymirrorpod"
,
"mynode"
,
true
)
othermirrorpod
=
makeTestPod
(
"ns"
,
"othermirrorpod"
,
"othernode"
,
true
)
...
...
@@ -634,6 +636,12 @@ func Test_nodePlugin_Admit(t *testing.T) {
err
:
""
,
},
{
name
:
"allow create of my node with taints"
,
podsGetter
:
noExistingPods
,
attributes
:
admission
.
NewAttributesRecord
(
mynodeObjTaintA
,
nil
,
nodeKind
,
mynodeObj
.
Namespace
,
""
,
nodeResource
,
""
,
admission
.
Create
,
mynode
),
err
:
""
,
},
{
name
:
"allow update of my node"
,
podsGetter
:
existingPods
,
attributes
:
admission
.
NewAttributesRecord
(
mynodeObj
,
mynodeObj
,
nodeKind
,
mynodeObj
.
Namespace
,
mynodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Update
,
mynode
),
...
...
@@ -681,6 +689,30 @@ func Test_nodePlugin_Admit(t *testing.T) {
attributes
:
admission
.
NewAttributesRecord
(
mynodeObj
,
mynodeObjConfigA
,
nodeKind
,
mynodeObj
.
Namespace
,
mynodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Update
,
mynode
),
err
:
""
,
},
{
name
:
"allow update of my node: no change to taints"
,
podsGetter
:
existingPods
,
attributes
:
admission
.
NewAttributesRecord
(
mynodeObjTaintA
,
mynodeObjTaintA
,
nodeKind
,
mynodeObj
.
Namespace
,
mynodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Update
,
mynode
),
err
:
""
,
},
{
name
:
"forbid update of my node: add taints"
,
podsGetter
:
existingPods
,
attributes
:
admission
.
NewAttributesRecord
(
mynodeObjTaintA
,
mynodeObj
,
nodeKind
,
mynodeObj
.
Namespace
,
mynodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Update
,
mynode
),
err
:
"cannot modify taints"
,
},
{
name
:
"forbid update of my node: remove taints"
,
podsGetter
:
existingPods
,
attributes
:
admission
.
NewAttributesRecord
(
mynodeObj
,
mynodeObjTaintA
,
nodeKind
,
mynodeObj
.
Namespace
,
mynodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Update
,
mynode
),
err
:
"cannot modify taints"
,
},
{
name
:
"forbid update of my node: change taints"
,
podsGetter
:
existingPods
,
attributes
:
admission
.
NewAttributesRecord
(
mynodeObjTaintA
,
mynodeObjTaintB
,
nodeKind
,
mynodeObj
.
Namespace
,
mynodeObj
.
Name
,
nodeResource
,
""
,
admission
.
Update
,
mynode
),
err
:
"cannot modify taints"
,
},
// Other node object
{
...
...
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