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
4d5b96f9
Commit
4d5b96f9
authored
Jun 20, 2017
by
Sunil Arora
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed conflict resolution behavior while apply podpresets
parent
ae1ff1a2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
6 deletions
+56
-6
local-up-cluster.sh
hack/local-up-cluster.sh
+0
-1
BUILD
plugin/pkg/admission/podpreset/BUILD
+1
-0
admission.go
plugin/pkg/admission/podpreset/admission.go
+0
-0
admission_test.go
plugin/pkg/admission/podpreset/admission_test.go
+55
-5
No files found.
hack/local-up-cluster.sh
View file @
4d5b96f9
...
@@ -406,7 +406,6 @@ function start_apiserver {
...
@@ -406,7 +406,6 @@ function start_apiserver {
# Admission Controllers to invoke prior to persisting objects in cluster
# Admission Controllers to invoke prior to persisting objects in cluster
ADMISSION_CONTROL
=
Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount
${
security_admission
}
,ResourceQuota,DefaultStorageClass,DefaultTolerationSeconds
ADMISSION_CONTROL
=
Initializers,NamespaceLifecycle,LimitRanger,ServiceAccount
${
security_admission
}
,ResourceQuota,DefaultStorageClass,DefaultTolerationSeconds
# This is the default dir and filename where the apiserver will generate a self-signed cert
# This is the default dir and filename where the apiserver will generate a self-signed cert
# which should be able to be used as the CA to verify itself
# which should be able to be used as the CA to verify itself
...
...
plugin/pkg/admission/podpreset/BUILD
View file @
4d5b96f9
...
@@ -43,6 +43,7 @@ go_library(
...
@@ -43,6 +43,7 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//vendor/k8s.io/apiserver/pkg/admission:go_default_library",
"//vendor/k8s.io/apiserver/pkg/admission:go_default_library",
],
],
)
)
...
...
plugin/pkg/admission/podpreset/admission.go
View file @
4d5b96f9
This diff is collapsed.
Click to expand it.
plugin/pkg/admission/podpreset/admission_test.go
View file @
4d5b96f9
...
@@ -66,8 +66,8 @@ func TestMergeEnv(t *testing.T) {
...
@@ -66,8 +66,8 @@ func TestMergeEnv(t *testing.T) {
for
name
,
test
:=
range
tests
{
for
name
,
test
:=
range
tests
{
result
,
err
:=
mergeEnv
(
result
,
err
:=
mergeEnv
(
&
settings
.
PodPreset
{
Spec
:
settings
.
PodPresetSpec
{
Env
:
test
.
mod
}},
test
.
orig
,
test
.
orig
,
[]
*
settings
.
PodPreset
{{
Spec
:
settings
.
PodPresetSpec
{
Env
:
test
.
mod
}}},
)
)
if
test
.
shouldFail
&&
err
==
nil
{
if
test
.
shouldFail
&&
err
==
nil
{
t
.
Fatalf
(
"expected test %q to fail but got nil"
,
name
)
t
.
Fatalf
(
"expected test %q to fail but got nil"
,
name
)
...
@@ -162,8 +162,8 @@ func TestMergeEnvFrom(t *testing.T) {
...
@@ -162,8 +162,8 @@ func TestMergeEnvFrom(t *testing.T) {
for
name
,
test
:=
range
tests
{
for
name
,
test
:=
range
tests
{
result
,
err
:=
mergeEnvFrom
(
result
,
err
:=
mergeEnvFrom
(
&
settings
.
PodPreset
{
Spec
:
settings
.
PodPresetSpec
{
EnvFrom
:
test
.
mod
}},
test
.
orig
,
test
.
orig
,
[]
*
settings
.
PodPreset
{{
Spec
:
settings
.
PodPresetSpec
{
EnvFrom
:
test
.
mod
}}},
)
)
if
test
.
shouldFail
&&
err
==
nil
{
if
test
.
shouldFail
&&
err
==
nil
{
t
.
Fatalf
(
"expected test %q to fail but got nil"
,
name
)
t
.
Fatalf
(
"expected test %q to fail but got nil"
,
name
)
...
@@ -295,8 +295,8 @@ func TestMergeVolumeMounts(t *testing.T) {
...
@@ -295,8 +295,8 @@ func TestMergeVolumeMounts(t *testing.T) {
for
name
,
test
:=
range
tests
{
for
name
,
test
:=
range
tests
{
result
,
err
:=
mergeVolumeMounts
(
result
,
err
:=
mergeVolumeMounts
(
&
settings
.
PodPreset
{
Spec
:
settings
.
PodPresetSpec
{
VolumeMounts
:
test
.
mod
}},
test
.
orig
,
test
.
orig
,
[]
*
settings
.
PodPreset
{{
Spec
:
settings
.
PodPresetSpec
{
VolumeMounts
:
test
.
mod
}}},
)
)
if
test
.
shouldFail
&&
err
==
nil
{
if
test
.
shouldFail
&&
err
==
nil
{
t
.
Fatalf
(
"expected test %q to fail but got nil"
,
name
)
t
.
Fatalf
(
"expected test %q to fail but got nil"
,
name
)
...
@@ -376,8 +376,8 @@ func TestMergeVolumes(t *testing.T) {
...
@@ -376,8 +376,8 @@ func TestMergeVolumes(t *testing.T) {
for
name
,
test
:=
range
tests
{
for
name
,
test
:=
range
tests
{
result
,
err
:=
mergeVolumes
(
result
,
err
:=
mergeVolumes
(
&
settings
.
PodPreset
{
Spec
:
settings
.
PodPresetSpec
{
Volumes
:
test
.
mod
}},
test
.
orig
,
test
.
orig
,
[]
*
settings
.
PodPreset
{{
Spec
:
settings
.
PodPresetSpec
{
Volumes
:
test
.
mod
}}},
)
)
if
test
.
shouldFail
&&
err
==
nil
{
if
test
.
shouldFail
&&
err
==
nil
{
t
.
Fatalf
(
"expected test %q to fail but got nil"
,
name
)
t
.
Fatalf
(
"expected test %q to fail but got nil"
,
name
)
...
@@ -496,6 +496,56 @@ func TestAdmitConflictWithNonMatchingLabelsShouldNotError(t *testing.T) {
...
@@ -496,6 +496,56 @@ func TestAdmitConflictWithNonMatchingLabelsShouldNotError(t *testing.T) {
}
}
}
}
func
TestAdmitConflictShouldNotModifyPod
(
t
*
testing
.
T
)
{
containerName
:=
"container"
pod
:=
&
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"mypod"
,
Namespace
:
"namespace"
,
Labels
:
map
[
string
]
string
{
"security"
:
"S2"
,
},
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
containerName
,
Env
:
[]
api
.
EnvVar
{{
Name
:
"abc"
,
Value
:
"value2"
},
{
Name
:
"ABC"
,
Value
:
"value3"
}},
},
},
},
}
origPod
:=
*
pod
pip
:=
&
settings
.
PodPreset
{
ObjectMeta
:
v1
.
ObjectMeta
{
Name
:
"hello"
,
Namespace
:
"namespace"
,
},
Spec
:
settings
.
PodPresetSpec
{
Selector
:
v1
.
LabelSelector
{
MatchExpressions
:
[]
v1
.
LabelSelectorRequirement
{
{
Key
:
"security"
,
Operator
:
v1
.
LabelSelectorOpIn
,
Values
:
[]
string
{
"S2"
},
},
},
},
Env
:
[]
api
.
EnvVar
{{
Name
:
"abc"
,
Value
:
"value"
},
{
Name
:
"ABC"
,
Value
:
"value"
}},
},
}
err
:=
admitPod
(
pod
,
pip
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
reflect
.
DeepEqual
(
&
origPod
,
pod
)
{
t
.
Fatalf
(
"pod should not get modified in case of conflict origPod: %+v got: %+v"
,
&
origPod
,
pod
)
}
}
func
TestAdmit
(
t
*
testing
.
T
)
{
func
TestAdmit
(
t
*
testing
.
T
)
{
containerName
:=
"container"
containerName
:=
"container"
...
@@ -759,7 +809,7 @@ func TestAdmitEmptyPodNamespace(t *testing.T) {
...
@@ -759,7 +809,7 @@ func TestAdmitEmptyPodNamespace(t *testing.T) {
// verify PodSpec has not been mutated
// verify PodSpec has not been mutated
if
!
reflect
.
DeepEqual
(
pod
,
originalPod
)
{
if
!
reflect
.
DeepEqual
(
pod
,
originalPod
)
{
t
.
Fatalf
(
"
Expected pod spec of '%v' to be unchanged"
,
pod
.
Name
)
t
.
Fatalf
(
"
pod should not get modified in case of emptyNamespace origPod: %+v got: %+v"
,
originalPod
,
pod
)
}
}
}
}
...
...
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