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
b2d9f99f
Commit
b2d9f99f
authored
Feb 24, 2017
by
Łukasz Oleś
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved tests and fixed typs
parent
620310c1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
111 additions
and
118 deletions
+111
-118
daemoncontroller_test.go
pkg/controller/daemon/daemoncontroller_test.go
+0
-112
update_test.go
pkg/controller/daemon/update_test.go
+103
-3
daemonset_util_test.go
pkg/controller/daemon/util/daemonset_util_test.go
+7
-2
rollout_status.go
pkg/kubectl/rollout_status.go
+1
-1
No files found.
pkg/controller/daemon/daemoncontroller_test.go
View file @
b2d9f99f
...
@@ -24,7 +24,6 @@ import (
...
@@ -24,7 +24,6 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/api/resource"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/apiserver/pkg/storage/names"
core
"k8s.io/client-go/testing"
core
"k8s.io/client-go/testing"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
...
@@ -1008,114 +1007,3 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
...
@@ -1008,114 +1007,3 @@ func TestNodeShouldRunDaemonPod(t *testing.T) {
}
}
}
}
}
}
func
TestDaemonSetUpdatesPods
(
t
*
testing
.
T
)
{
manager
,
podControl
,
_
:=
newTestController
()
maxUnavailable
:=
2
addNodes
(
manager
.
nodeStore
,
0
,
5
,
nil
)
ds
:=
newDaemonSet
(
"foo"
)
manager
.
dsStore
.
Add
(
ds
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
markPodsReady
(
podControl
.
podStore
)
ds
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
=
"foo2/bar2"
ds
.
Spec
.
UpdateStrategy
.
Type
=
extensions
.
RollingUpdateDaemonSetStrategyType
intStr
:=
intstr
.
FromInt
(
maxUnavailable
)
ds
.
Spec
.
UpdateStrategy
.
RollingUpdate
=
&
extensions
.
RollingUpdateDaemonSet
{
MaxUnavailable
:
&
intStr
}
ds
.
Spec
.
TemplateGeneration
++
manager
.
dsStore
.
Update
(
ds
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
maxUnavailable
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
maxUnavailable
,
0
)
markPodsReady
(
podControl
.
podStore
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
maxUnavailable
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
maxUnavailable
,
0
)
markPodsReady
(
podControl
.
podStore
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
1
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
1
,
0
)
markPodsReady
(
podControl
.
podStore
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
}
func
TestDaemonSetUpdatesWhenNewPosIsNotReady
(
t
*
testing
.
T
)
{
manager
,
podControl
,
_
:=
newTestController
()
maxUnavailable
:=
3
addNodes
(
manager
.
nodeStore
,
0
,
5
,
nil
)
ds
:=
newDaemonSet
(
"foo"
)
manager
.
dsStore
.
Add
(
ds
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
markPodsReady
(
podControl
.
podStore
)
ds
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
=
"foo2/bar2"
ds
.
Spec
.
UpdateStrategy
.
Type
=
extensions
.
RollingUpdateDaemonSetStrategyType
intStr
:=
intstr
.
FromInt
(
maxUnavailable
)
ds
.
Spec
.
UpdateStrategy
.
RollingUpdate
=
&
extensions
.
RollingUpdateDaemonSet
{
MaxUnavailable
:
&
intStr
}
ds
.
Spec
.
TemplateGeneration
++
manager
.
dsStore
.
Update
(
ds
)
// new pods are not ready numUnavailable == maxUnavailable
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
maxUnavailable
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
maxUnavailable
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
}
func
TestDaemonSetUpdatesAllOldPodsNotReady
(
t
*
testing
.
T
)
{
manager
,
podControl
,
_
:=
newTestController
()
maxUnavailable
:=
3
addNodes
(
manager
.
nodeStore
,
0
,
5
,
nil
)
ds
:=
newDaemonSet
(
"foo"
)
manager
.
dsStore
.
Add
(
ds
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
ds
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
=
"foo2/bar2"
ds
.
Spec
.
UpdateStrategy
.
Type
=
extensions
.
RollingUpdateDaemonSetStrategyType
intStr
:=
intstr
.
FromInt
(
maxUnavailable
)
ds
.
Spec
.
UpdateStrategy
.
RollingUpdate
=
&
extensions
.
RollingUpdateDaemonSet
{
MaxUnavailable
:
&
intStr
}
ds
.
Spec
.
TemplateGeneration
++
manager
.
dsStore
.
Update
(
ds
)
// all old pods are unavailable so should be removed
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
5
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
}
func
TestDaemonSetUpdatesNoTemplateChanged
(
t
*
testing
.
T
)
{
manager
,
podControl
,
_
:=
newTestController
()
maxUnavailable
:=
3
addNodes
(
manager
.
nodeStore
,
0
,
5
,
nil
)
ds
:=
newDaemonSet
(
"foo"
)
manager
.
dsStore
.
Add
(
ds
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
ds
.
Spec
.
UpdateStrategy
.
Type
=
extensions
.
RollingUpdateDaemonSetStrategyType
intStr
:=
intstr
.
FromInt
(
maxUnavailable
)
ds
.
Spec
.
UpdateStrategy
.
RollingUpdate
=
&
extensions
.
RollingUpdateDaemonSet
{
MaxUnavailable
:
&
intStr
}
manager
.
dsStore
.
Update
(
ds
)
// template is not changed no pod should be removed
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
}
pkg/controller/daemon/update_test.go
View file @
b2d9f99f
...
@@ -19,17 +19,117 @@ package daemon
...
@@ -19,17 +19,117 @@ package daemon
import
(
import
(
"testing"
"testing"
"k8s.io/apimachinery/pkg/util/intstr"
extensions
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
extensions
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
)
)
// DaemonSets without node selectors should launch pods on every node.
func
TestDaemonSetUpdatesPods
(
t
*
testing
.
T
)
{
func
TestSimpleDaemonSetUpdatesWithRollingUpdate
(
t
*
testing
.
T
)
{
manager
,
podControl
,
_
:=
newTestController
()
manager
,
podControl
,
_
:=
newTestController
()
maxUnavailable
:=
2
addNodes
(
manager
.
nodeStore
,
0
,
5
,
nil
)
addNodes
(
manager
.
nodeStore
,
0
,
5
,
nil
)
ds
:=
newDaemonSet
(
"foo"
)
ds
:=
newDaemonSet
(
"foo"
)
manager
.
dsStore
.
Add
(
ds
)
manager
.
dsStore
.
Add
(
ds
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
markPodsReady
(
podControl
.
podStore
)
ds
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
=
"foo2/bar2"
ds
.
Spec
.
UpdateStrategy
.
Type
=
extensions
.
RollingUpdateDaemonSetStrategyType
intStr
:=
intstr
.
FromInt
(
maxUnavailable
)
ds
.
Spec
.
UpdateStrategy
.
RollingUpdate
=
&
extensions
.
RollingUpdateDaemonSet
{
MaxUnavailable
:
&
intStr
}
ds
.
Spec
.
TemplateGeneration
++
manager
.
dsStore
.
Update
(
ds
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
maxUnavailable
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
maxUnavailable
,
0
)
markPodsReady
(
podControl
.
podStore
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
maxUnavailable
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
maxUnavailable
,
0
)
markPodsReady
(
podControl
.
podStore
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
1
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
1
,
0
)
markPodsReady
(
podControl
.
podStore
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
}
func
TestDaemonSetUpdatesWhenNewPosIsNotReady
(
t
*
testing
.
T
)
{
manager
,
podControl
,
_
:=
newTestController
()
maxUnavailable
:=
3
addNodes
(
manager
.
nodeStore
,
0
,
5
,
nil
)
ds
:=
newDaemonSet
(
"foo"
)
manager
.
dsStore
.
Add
(
ds
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
// change strategy type to RollingUpdate
markPodsReady
(
podControl
.
podStore
)
ds
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
=
"foo2/bar2"
ds
.
Spec
.
UpdateStrategy
.
Type
=
extensions
.
RollingUpdateDaemonSetStrategyType
ds
.
Spec
.
UpdateStrategy
.
Type
=
extensions
.
RollingUpdateDaemonSetStrategyType
intStr
:=
intstr
.
FromInt
(
maxUnavailable
)
ds
.
Spec
.
UpdateStrategy
.
RollingUpdate
=
&
extensions
.
RollingUpdateDaemonSet
{
MaxUnavailable
:
&
intStr
}
ds
.
Spec
.
TemplateGeneration
++
manager
.
dsStore
.
Update
(
ds
)
// new pods are not ready numUnavailable == maxUnavailable
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
maxUnavailable
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
maxUnavailable
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
}
func
TestDaemonSetUpdatesAllOldPodsNotReady
(
t
*
testing
.
T
)
{
manager
,
podControl
,
_
:=
newTestController
()
maxUnavailable
:=
3
addNodes
(
manager
.
nodeStore
,
0
,
5
,
nil
)
ds
:=
newDaemonSet
(
"foo"
)
manager
.
dsStore
.
Add
(
ds
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
ds
.
Spec
.
Template
.
Spec
.
Containers
[
0
]
.
Image
=
"foo2/bar2"
ds
.
Spec
.
UpdateStrategy
.
Type
=
extensions
.
RollingUpdateDaemonSetStrategyType
intStr
:=
intstr
.
FromInt
(
maxUnavailable
)
ds
.
Spec
.
UpdateStrategy
.
RollingUpdate
=
&
extensions
.
RollingUpdateDaemonSet
{
MaxUnavailable
:
&
intStr
}
ds
.
Spec
.
TemplateGeneration
++
manager
.
dsStore
.
Update
(
ds
)
// all old pods are unavailable so should be removed
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
5
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
}
func
TestDaemonSetUpdatesNoTemplateChanged
(
t
*
testing
.
T
)
{
manager
,
podControl
,
_
:=
newTestController
()
maxUnavailable
:=
3
addNodes
(
manager
.
nodeStore
,
0
,
5
,
nil
)
ds
:=
newDaemonSet
(
"foo"
)
manager
.
dsStore
.
Add
(
ds
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
5
,
0
)
ds
.
Spec
.
UpdateStrategy
.
Type
=
extensions
.
RollingUpdateDaemonSetStrategyType
intStr
:=
intstr
.
FromInt
(
maxUnavailable
)
ds
.
Spec
.
UpdateStrategy
.
RollingUpdate
=
&
extensions
.
RollingUpdateDaemonSet
{
MaxUnavailable
:
&
intStr
}
manager
.
dsStore
.
Update
(
ds
)
// template is not changed no pod should be removed
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
0
)
clearExpectations
(
t
,
manager
,
ds
,
podControl
)
}
}
pkg/controller/daemon/util/daemonset_util_test.go
View file @
b2d9f99f
...
@@ -67,6 +67,11 @@ func TestIsPodUpdated(t *testing.T) {
...
@@ -67,6 +67,11 @@ func TestIsPodUpdated(t *testing.T) {
newPod
(
"pod1"
,
"node1"
,
map
[
string
]
string
{}),
newPod
(
"pod1"
,
"node1"
,
map
[
string
]
string
{}),
false
,
false
,
},
},
{
int64
(
12355
),
newPod
(
"pod1"
,
"node1"
,
nil
),
false
,
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
updated
:=
IsPodUpdated
(
test
.
templateGeneration
,
test
.
pod
)
updated
:=
IsPodUpdated
(
test
.
templateGeneration
,
test
.
pod
)
...
@@ -76,12 +81,12 @@ func TestIsPodUpdated(t *testing.T) {
...
@@ -76,12 +81,12 @@ func TestIsPodUpdated(t *testing.T) {
}
}
}
}
func
TestGetPodTemplateWith
Revis
ion
(
t
*
testing
.
T
)
{
func
TestGetPodTemplateWith
Generat
ion
(
t
*
testing
.
T
)
{
generation
:=
int64
(
1
)
generation
:=
int64
(
1
)
podTemplateSpec
:=
v1
.
PodTemplateSpec
{}
podTemplateSpec
:=
v1
.
PodTemplateSpec
{}
newPodTemplate
:=
GetPodTemplateWithGeneration
(
podTemplateSpec
,
generation
)
newPodTemplate
:=
GetPodTemplateWithGeneration
(
podTemplateSpec
,
generation
)
label
,
exists
:=
newPodTemplate
.
ObjectMeta
.
Labels
[
extensions
.
DaemonSetTemplateGenerationKey
]
label
,
exists
:=
newPodTemplate
.
ObjectMeta
.
Labels
[
extensions
.
DaemonSetTemplateGenerationKey
]
if
!
exists
||
label
!=
fmt
.
Sprint
(
generation
)
{
if
!
exists
||
label
!=
fmt
.
Sprint
(
generation
)
{
t
.
Errorf
(
"Error in getting podTemplateSpec with label gene
ar
tion. Exists: %t, label: %s"
,
exists
,
label
)
t
.
Errorf
(
"Error in getting podTemplateSpec with label gene
ra
tion. Exists: %t, label: %s"
,
exists
,
label
)
}
}
}
}
pkg/kubectl/rollout_status.go
View file @
b2d9f99f
...
@@ -86,7 +86,7 @@ func (s *DeploymentStatusViewer) Status(namespace, name string, revision int64)
...
@@ -86,7 +86,7 @@ func (s *DeploymentStatusViewer) Status(namespace, name string, revision int64)
// Status returns a message describing daemon set status, and a bool value indicating if the status is considered done
// Status returns a message describing daemon set status, and a bool value indicating if the status is considered done
func
(
s
*
DaemonSetStatusViewer
)
Status
(
namespace
,
name
string
,
revision
int64
)
(
string
,
bool
,
error
)
{
func
(
s
*
DaemonSetStatusViewer
)
Status
(
namespace
,
name
string
,
revision
int64
)
(
string
,
bool
,
error
)
{
//ignoring revision as DaemonSets do not have history yet
//ignoring revision as DaemonSets do
es
not have history yet
daemon
,
err
:=
s
.
c
.
DaemonSets
(
namespace
)
.
Get
(
name
,
metav1
.
GetOptions
{})
daemon
,
err
:=
s
.
c
.
DaemonSets
(
namespace
)
.
Get
(
name
,
metav1
.
GetOptions
{})
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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