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
ebe32554
Commit
ebe32554
authored
Apr 13, 2017
by
Avesh Agarwal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests when the feature AffinityInAnnotations is disabled.
parent
d2117c01
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
0 deletions
+119
-0
validation_test.go
pkg/api/validation/validation_test.go
+119
-0
No files found.
pkg/api/validation/validation_test.go
View file @
ebe32554
...
@@ -26,6 +26,7 @@ import (
...
@@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/apimachinery/pkg/util/validation/field"
utilfeature
"k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/helper"
"k8s.io/kubernetes/pkg/api/helper"
"k8s.io/kubernetes/pkg/api/service"
"k8s.io/kubernetes/pkg/api/service"
...
@@ -4316,6 +4317,124 @@ func TestValidatePod(t *testing.T) {
...
@@ -4316,6 +4317,124 @@ func TestValidatePod(t *testing.T) {
}
}
}
}
func
TestValidatePodWithDisabledAffinityInAnnotations
(
t
*
testing
.
T
)
{
validPodSpec
:=
func
(
affinity
*
api
.
Affinity
)
api
.
PodSpec
{
spec
:=
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
,
ImagePullPolicy
:
"IfNotPresent"
,
TerminationMessagePolicy
:
"File"
}},
RestartPolicy
:
api
.
RestartPolicyAlways
,
DNSPolicy
:
api
.
DNSClusterFirst
,
}
if
affinity
!=
nil
{
spec
.
Affinity
=
affinity
}
return
spec
}
utilfeature
.
DefaultFeatureGate
.
Set
(
"AffinityInAnnotations=False"
)
errorCases
:=
[]
api
.
Pod
{
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"123"
,
Namespace
:
"ns"
},
Spec
:
validPodSpec
(
&
api
.
Affinity
{
PodAffinity
:
&
api
.
PodAffinity
{
RequiredDuringSchedulingIgnoredDuringExecution
:
[]
api
.
PodAffinityTerm
{
{
LabelSelector
:
&
metav1
.
LabelSelector
{
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{
{
Key
:
"key2"
,
Operator
:
metav1
.
LabelSelectorOpIn
,
Values
:
[]
string
{
"value1"
,
"value2"
},
},
},
},
TopologyKey
:
""
,
Namespaces
:
[]
string
{
"ns"
},
},
},
},
}),
},
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"123"
,
Namespace
:
"ns"
},
Spec
:
validPodSpec
(
&
api
.
Affinity
{
PodAffinity
:
&
api
.
PodAffinity
{
PreferredDuringSchedulingIgnoredDuringExecution
:
[]
api
.
WeightedPodAffinityTerm
{
{
Weight
:
10
,
PodAffinityTerm
:
api
.
PodAffinityTerm
{
LabelSelector
:
&
metav1
.
LabelSelector
{
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{
{
Key
:
"key2"
,
Operator
:
metav1
.
LabelSelectorOpNotIn
,
Values
:
[]
string
{
"value1"
,
"value2"
},
},
},
},
Namespaces
:
[]
string
{
"ns"
},
TopologyKey
:
""
,
},
},
},
},
}),
},
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"123"
,
Namespace
:
"ns"
},
Spec
:
validPodSpec
(
&
api
.
Affinity
{
PodAntiAffinity
:
&
api
.
PodAntiAffinity
{
RequiredDuringSchedulingIgnoredDuringExecution
:
[]
api
.
PodAffinityTerm
{
{
LabelSelector
:
&
metav1
.
LabelSelector
{
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{
{
Key
:
"key2"
,
Operator
:
metav1
.
LabelSelectorOpIn
,
Values
:
[]
string
{
"value1"
,
"value2"
},
},
},
},
TopologyKey
:
""
,
Namespaces
:
[]
string
{
"ns"
},
},
},
},
}),
},
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"123"
,
Namespace
:
"ns"
},
Spec
:
validPodSpec
(
&
api
.
Affinity
{
PodAntiAffinity
:
&
api
.
PodAntiAffinity
{
PreferredDuringSchedulingIgnoredDuringExecution
:
[]
api
.
WeightedPodAffinityTerm
{
{
Weight
:
10
,
PodAffinityTerm
:
api
.
PodAffinityTerm
{
LabelSelector
:
&
metav1
.
LabelSelector
{
MatchExpressions
:
[]
metav1
.
LabelSelectorRequirement
{
{
Key
:
"key2"
,
Operator
:
metav1
.
LabelSelectorOpNotIn
,
Values
:
[]
string
{
"value1"
,
"value2"
},
},
},
},
Namespaces
:
[]
string
{
"ns"
},
TopologyKey
:
""
,
},
},
},
},
}),
},
}
for
_
,
v
:=
range
errorCases
{
if
errs
:=
ValidatePod
(
&
v
);
len
(
errs
)
==
0
{
t
.
Errorf
(
"expected failure for %v"
,
errs
)
}
}
}
func
TestValidatePodUpdate
(
t
*
testing
.
T
)
{
func
TestValidatePodUpdate
(
t
*
testing
.
T
)
{
var
(
var
(
activeDeadlineSecondsZero
=
int64
(
0
)
activeDeadlineSecondsZero
=
int64
(
0
)
...
...
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