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
4dc42d07
Commit
4dc42d07
authored
Sep 08, 2017
by
Yinan Li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial integration test setup for DaemonSet controller
parent
a9e244d8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
98 additions
and
10 deletions
+98
-10
daemon_controller.go
pkg/controller/daemon/daemon_controller.go
+13
-9
daemon_controller_test.go
pkg/controller/daemon/daemon_controller_test.go
+1
-1
BUILD
test/integration/BUILD
+1
-0
BUILD
test/integration/daemonset/BUILD
+47
-0
OWNERS
test/integration/daemonset/OWNERS
+9
-0
daemonset_test.go
test/integration/daemonset/daemonset_test.go
+0
-0
main_test.go
test/integration/daemonset/main_test.go
+27
-0
No files found.
pkg/controller/daemon/daemon_controller.go
View file @
4dc42d07
...
@@ -298,8 +298,8 @@ func (dsc *DaemonSetsController) enqueueDaemonSetAfter(obj interface{}, after ti
...
@@ -298,8 +298,8 @@ func (dsc *DaemonSetsController) enqueueDaemonSetAfter(obj interface{}, after ti
dsc
.
queue
.
AddAfter
(
key
,
after
)
dsc
.
queue
.
AddAfter
(
key
,
after
)
}
}
// get
PodDaemonSets
returns a list of DaemonSets that potentially match the pod.
// get
DaemonSetsForPod
returns a list of DaemonSets that potentially match the pod.
func
(
dsc
*
DaemonSetsController
)
get
PodDaemonSets
(
pod
*
v1
.
Pod
)
[]
*
extensions
.
DaemonSet
{
func
(
dsc
*
DaemonSetsController
)
get
DaemonSetsForPod
(
pod
*
v1
.
Pod
)
[]
*
extensions
.
DaemonSet
{
sets
,
err
:=
dsc
.
dsLister
.
GetPodDaemonSets
(
pod
)
sets
,
err
:=
dsc
.
dsLister
.
GetPodDaemonSets
(
pod
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
return
nil
...
@@ -362,8 +362,8 @@ func (dsc *DaemonSetsController) addHistory(obj interface{}) {
...
@@ -362,8 +362,8 @@ func (dsc *DaemonSetsController) addHistory(obj interface{}) {
}
}
// updateHistory figures out what DaemonSet(s) manage a ControllerRevision when the ControllerRevision
// updateHistory figures out what DaemonSet(s) manage a ControllerRevision when the ControllerRevision
// is updated and wake them up. If
the anything of the ControllerRevision have changed, we need to
// is updated and wake them up. If
anything of the ControllerRevision has changed, we need to awaken
//
awaken
both the old and new DaemonSets.
// both the old and new DaemonSets.
func
(
dsc
*
DaemonSetsController
)
updateHistory
(
old
,
cur
interface
{})
{
func
(
dsc
*
DaemonSetsController
)
updateHistory
(
old
,
cur
interface
{})
{
curHistory
:=
cur
.
(
*
apps
.
ControllerRevision
)
curHistory
:=
cur
.
(
*
apps
.
ControllerRevision
)
oldHistory
:=
old
.
(
*
apps
.
ControllerRevision
)
oldHistory
:=
old
.
(
*
apps
.
ControllerRevision
)
...
@@ -474,7 +474,7 @@ func (dsc *DaemonSetsController) addPod(obj interface{}) {
...
@@ -474,7 +474,7 @@ func (dsc *DaemonSetsController) addPod(obj interface{}) {
// them to see if anyone wants to adopt it.
// them to see if anyone wants to adopt it.
// DO NOT observe creation because no controller should be waiting for an
// DO NOT observe creation because no controller should be waiting for an
// orphan.
// orphan.
dss
:=
dsc
.
get
PodDaemonSets
(
pod
)
dss
:=
dsc
.
get
DaemonSetsForPod
(
pod
)
if
len
(
dss
)
==
0
{
if
len
(
dss
)
==
0
{
return
return
}
}
...
@@ -495,8 +495,6 @@ func (dsc *DaemonSetsController) updatePod(old, cur interface{}) {
...
@@ -495,8 +495,6 @@ func (dsc *DaemonSetsController) updatePod(old, cur interface{}) {
// Two different versions of the same pod will always have different RVs.
// Two different versions of the same pod will always have different RVs.
return
return
}
}
changedToReady
:=
!
podutil
.
IsPodReady
(
oldPod
)
&&
podutil
.
IsPodReady
(
curPod
)
labelChanged
:=
!
reflect
.
DeepEqual
(
curPod
.
Labels
,
oldPod
.
Labels
)
curControllerRef
:=
metav1
.
GetControllerOf
(
curPod
)
curControllerRef
:=
metav1
.
GetControllerOf
(
curPod
)
oldControllerRef
:=
metav1
.
GetControllerOf
(
oldPod
)
oldControllerRef
:=
metav1
.
GetControllerOf
(
oldPod
)
...
@@ -516,6 +514,7 @@ func (dsc *DaemonSetsController) updatePod(old, cur interface{}) {
...
@@ -516,6 +514,7 @@ func (dsc *DaemonSetsController) updatePod(old, cur interface{}) {
}
}
glog
.
V
(
4
)
.
Infof
(
"Pod %s updated."
,
curPod
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"Pod %s updated."
,
curPod
.
Name
)
dsc
.
enqueueDaemonSet
(
ds
)
dsc
.
enqueueDaemonSet
(
ds
)
changedToReady
:=
!
podutil
.
IsPodReady
(
oldPod
)
&&
podutil
.
IsPodReady
(
curPod
)
// See https://github.com/kubernetes/kubernetes/pull/38076 for more details
// See https://github.com/kubernetes/kubernetes/pull/38076 for more details
if
changedToReady
&&
ds
.
Spec
.
MinReadySeconds
>
0
{
if
changedToReady
&&
ds
.
Spec
.
MinReadySeconds
>
0
{
// Add a second to avoid milliseconds skew in AddAfter.
// Add a second to avoid milliseconds skew in AddAfter.
...
@@ -527,11 +526,12 @@ func (dsc *DaemonSetsController) updatePod(old, cur interface{}) {
...
@@ -527,11 +526,12 @@ func (dsc *DaemonSetsController) updatePod(old, cur interface{}) {
// Otherwise, it's an orphan. If anything changed, sync matching controllers
// Otherwise, it's an orphan. If anything changed, sync matching controllers
// to see if anyone wants to adopt it now.
// to see if anyone wants to adopt it now.
dss
:=
dsc
.
get
PodDaemonSets
(
curPod
)
dss
:=
dsc
.
get
DaemonSetsForPod
(
curPod
)
if
len
(
dss
)
==
0
{
if
len
(
dss
)
==
0
{
return
return
}
}
glog
.
V
(
4
)
.
Infof
(
"Orphan Pod %s updated."
,
curPod
.
Name
)
glog
.
V
(
4
)
.
Infof
(
"Orphan Pod %s updated."
,
curPod
.
Name
)
labelChanged
:=
!
reflect
.
DeepEqual
(
curPod
.
Labels
,
oldPod
.
Labels
)
if
labelChanged
||
controllerRefChanged
{
if
labelChanged
||
controllerRefChanged
{
for
_
,
ds
:=
range
dss
{
for
_
,
ds
:=
range
dss
{
dsc
.
enqueueDaemonSet
(
ds
)
dsc
.
enqueueDaemonSet
(
ds
)
...
@@ -707,7 +707,7 @@ func (dsc *DaemonSetsController) updateNode(old, cur interface{}) {
...
@@ -707,7 +707,7 @@ func (dsc *DaemonSetsController) updateNode(old, cur interface{}) {
dsList
,
err
:=
dsc
.
dsLister
.
List
(
labels
.
Everything
())
dsList
,
err
:=
dsc
.
dsLister
.
List
(
labels
.
Everything
())
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
V
(
4
)
.
Infof
(
"Error
enqueue
ing daemon sets: %v"
,
err
)
glog
.
V
(
4
)
.
Infof
(
"Error
list
ing daemon sets: %v"
,
err
)
return
return
}
}
// TODO: it'd be nice to pass a hint with these enqueues, so that each ds would only examine the added node (unless it has other work to do, too).
// TODO: it'd be nice to pass a hint with these enqueues, so that each ds would only examine the added node (unless it has other work to do, too).
...
@@ -799,6 +799,10 @@ func (dsc *DaemonSetsController) resolveControllerRef(namespace string, controll
...
@@ -799,6 +799,10 @@ func (dsc *DaemonSetsController) resolveControllerRef(namespace string, controll
return
ds
return
ds
}
}
// manage manages the scheduling and running of Pods of ds on nodes.
// After figuring out which nodes should run a Pod of ds but not yet running one and
// which nodes should not run a Pod of ds but currently running one, it calls function
// syncNodes with a list of pods to remove and a list of nodes to run a Pod of ds.
func
(
dsc
*
DaemonSetsController
)
manage
(
ds
*
extensions
.
DaemonSet
,
hash
string
)
error
{
func
(
dsc
*
DaemonSetsController
)
manage
(
ds
*
extensions
.
DaemonSet
,
hash
string
)
error
{
// Find out which nodes are running the daemon pods controlled by ds.
// Find out which nodes are running the daemon pods controlled by ds.
nodeToDaemonPods
,
err
:=
dsc
.
getNodesToDaemonPods
(
ds
)
nodeToDaemonPods
,
err
:=
dsc
.
getNodesToDaemonPods
(
ds
)
...
...
pkg/controller/daemon/daemon_controller_test.go
View file @
4dc42d07
...
@@ -492,7 +492,7 @@ func TestOneNodeDaemonLaunchesPod(t *testing.T) {
...
@@ -492,7 +492,7 @@ func TestOneNodeDaemonLaunchesPod(t *testing.T) {
}
}
// DaemonSets should place onto NotReady nodes
// DaemonSets should place onto NotReady nodes
func
TestNotRead
NodeDaemonDoesNot
LaunchPod
(
t
*
testing
.
T
)
{
func
TestNotRead
yNodeDaemonDoes
LaunchPod
(
t
*
testing
.
T
)
{
for
_
,
strategy
:=
range
updateStrategies
()
{
for
_
,
strategy
:=
range
updateStrategies
()
{
ds
:=
newDaemonSet
(
"foo"
)
ds
:=
newDaemonSet
(
"foo"
)
ds
.
Spec
.
UpdateStrategy
=
*
strategy
ds
.
Spec
.
UpdateStrategy
=
*
strategy
...
...
test/integration/BUILD
View file @
4dc42d07
...
@@ -36,6 +36,7 @@ filegroup(
...
@@ -36,6 +36,7 @@ filegroup(
"//test/integration/auth:all-srcs",
"//test/integration/auth:all-srcs",
"//test/integration/client:all-srcs",
"//test/integration/client:all-srcs",
"//test/integration/configmap:all-srcs",
"//test/integration/configmap:all-srcs",
"//test/integration/daemonset:all-srcs",
"//test/integration/defaulttolerationseconds:all-srcs",
"//test/integration/defaulttolerationseconds:all-srcs",
"//test/integration/deployment:all-srcs",
"//test/integration/deployment:all-srcs",
"//test/integration/etcd:all-srcs",
"//test/integration/etcd:all-srcs",
...
...
test/integration/daemonset/BUILD
0 → 100644
View file @
4dc42d07
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
)
go_test(
name = "go_default_test",
size = "large",
srcs = [
"daemonset_test.go",
"main_test.go",
],
importpath = "k8s.io/kubernetes/test/integration/daemonset",
tags = ["integration"],
deps = [
"//pkg/api/v1/pod:go_default_library",
"//pkg/controller/daemon:go_default_library",
"//test/integration/framework:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/api/extensions/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/client-go/informers:go_default_library",
"//vendor/k8s.io/client-go/kubernetes:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/typed/extensions/v1beta1:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
test/integration/daemonset/OWNERS
0 → 100755
View file @
4dc42d07
approvers:
- mikedanese
- kow3ns
reviewers:
- mikedanese
- kargakis
- lukaszo
- janetkuo
- kow3ns
test/integration/daemonset/daemonset_test.go
0 → 100644
View file @
4dc42d07
This diff is collapsed.
Click to expand it.
test/integration/daemonset/main_test.go
0 → 100644
View file @
4dc42d07
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
daemonset
import
(
"testing"
"k8s.io/kubernetes/test/integration/framework"
)
func
TestMain
(
m
*
testing
.
M
)
{
framework
.
EtcdMain
(
m
.
Run
)
}
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