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
bdc8c822
Commit
bdc8c822
authored
Oct 26, 2016
by
Maciej Szulik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update PodAntiAffinity to ignore calls to subresources
parent
7d0b12f9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
1 deletion
+61
-1
BUILD
plugin/pkg/admission/antiaffinity/BUILD
+1
-0
admission.go
plugin/pkg/admission/antiaffinity/admission.go
+2
-1
admission_test.go
plugin/pkg/admission/antiaffinity/admission_test.go
+58
-0
No files found.
plugin/pkg/admission/antiaffinity/BUILD
View file @
bdc8c822
...
@@ -36,5 +36,6 @@ go_test(
...
@@ -36,5 +36,6 @@ go_test(
"//pkg/admission:go_default_library",
"//pkg/admission:go_default_library",
"//pkg/api:go_default_library",
"//pkg/api:go_default_library",
"//pkg/api/unversioned:go_default_library",
"//pkg/api/unversioned:go_default_library",
"//pkg/runtime:go_default_library",
],
],
)
)
plugin/pkg/admission/antiaffinity/admission.go
View file @
bdc8c822
...
@@ -51,7 +51,8 @@ func NewInterPodAntiAffinity(client clientset.Interface) admission.Interface {
...
@@ -51,7 +51,8 @@ func NewInterPodAntiAffinity(client clientset.Interface) admission.Interface {
// Admit will deny any pod that defines AntiAffinity topology key other than unversioned.LabelHostname i.e. "kubernetes.io/hostname"
// Admit will deny any pod that defines AntiAffinity topology key other than unversioned.LabelHostname i.e. "kubernetes.io/hostname"
// in requiredDuringSchedulingRequiredDuringExecution and requiredDuringSchedulingIgnoredDuringExecution.
// in requiredDuringSchedulingRequiredDuringExecution and requiredDuringSchedulingIgnoredDuringExecution.
func
(
p
*
plugin
)
Admit
(
attributes
admission
.
Attributes
)
(
err
error
)
{
func
(
p
*
plugin
)
Admit
(
attributes
admission
.
Attributes
)
(
err
error
)
{
if
attributes
.
GetResource
()
.
GroupResource
()
!=
api
.
Resource
(
"pods"
)
{
// Ignore all calls to subresources or resources other than pods.
if
len
(
attributes
.
GetSubresource
())
!=
0
||
attributes
.
GetResource
()
.
GroupResource
()
!=
api
.
Resource
(
"pods"
)
{
return
nil
return
nil
}
}
pod
,
ok
:=
attributes
.
GetObject
()
.
(
*
api
.
Pod
)
pod
,
ok
:=
attributes
.
GetObject
()
.
(
*
api
.
Pod
)
...
...
plugin/pkg/admission/antiaffinity/admission_test.go
View file @
bdc8c822
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ 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/unversioned"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/runtime"
)
)
// ensures the hard PodAntiAffinity is denied if it defines TopologyKey other than kubernetes.io/hostname.
// ensures the hard PodAntiAffinity is denied if it defines TopologyKey other than kubernetes.io/hostname.
...
@@ -239,3 +240,60 @@ func TestHandles(t *testing.T) {
...
@@ -239,3 +240,60 @@ func TestHandles(t *testing.T) {
}
}
}
}
}
}
// TestOtherResources ensures that this admission controller is a no-op for other resources,
// subresources, and non-pods.
func
TestOtherResources
(
t
*
testing
.
T
)
{
namespace
:=
"testnamespace"
name
:=
"testname"
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
name
,
Namespace
:
namespace
},
}
tests
:=
[]
struct
{
name
string
kind
string
resource
string
subresource
string
object
runtime
.
Object
expectError
bool
}{
{
name
:
"non-pod resource"
,
kind
:
"Foo"
,
resource
:
"foos"
,
object
:
pod
,
},
{
name
:
"pod subresource"
,
kind
:
"Pod"
,
resource
:
"pods"
,
subresource
:
"eviction"
,
object
:
pod
,
},
{
name
:
"non-pod object"
,
kind
:
"Pod"
,
resource
:
"pods"
,
object
:
&
api
.
Service
{},
expectError
:
true
,
},
}
for
_
,
tc
:=
range
tests
{
handler
:=
&
plugin
{}
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
tc
.
object
,
nil
,
api
.
Kind
(
tc
.
kind
)
.
WithVersion
(
"version"
),
namespace
,
name
,
api
.
Resource
(
tc
.
resource
)
.
WithVersion
(
"version"
),
tc
.
subresource
,
admission
.
Create
,
nil
))
if
tc
.
expectError
{
if
err
==
nil
{
t
.
Errorf
(
"%s: unexpected nil error"
,
tc
.
name
)
}
continue
}
if
err
!=
nil
{
t
.
Errorf
(
"%s: unexpected error: %v"
,
tc
.
name
,
err
)
continue
}
}
}
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