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
38583182
Commit
38583182
authored
Sep 07, 2016
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update error handling for daemoncontroller
parent
80f56d83
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
135 additions
and
69 deletions
+135
-69
daemoncontroller.go
pkg/controller/daemon/daemoncontroller.go
+67
-46
daemoncontroller_test.go
pkg/controller/daemon/daemoncontroller_test.go
+1
-22
shared_informer.go
pkg/controller/framework/shared_informer.go
+31
-0
wait.go
pkg/util/wait/wait.go
+6
-1
wait_test.go
pkg/util/wait/wait_test.go
+30
-0
No files found.
pkg/controller/daemon/daemoncontroller.go
View file @
38583182
This diff is collapsed.
Click to expand it.
pkg/controller/daemon/daemoncontroller_test.go
View file @
38583182
...
...
@@ -138,6 +138,7 @@ func newTestController() (*DaemonSetsController, *controller.FakePodControl) {
clientset
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
""
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
testapi
.
Default
.
GroupVersion
()}})
manager
:=
NewDaemonSetsControllerFromClient
(
clientset
,
controller
.
NoResyncPeriodFunc
,
0
)
manager
.
podStoreSynced
=
alwaysReady
manager
.
nodeStoreSynced
=
alwaysReady
podControl
:=
&
controller
.
FakePodControl
{}
manager
.
podControl
=
podControl
return
manager
,
podControl
...
...
@@ -539,28 +540,6 @@ func TestInconsistentNameSelectorDaemonSetDoesNothing(t *testing.T) {
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
0
)
}
func
TestDSManagerNotReady
(
t
*
testing
.
T
)
{
manager
,
podControl
:=
newTestController
()
manager
.
podStoreSynced
=
func
()
bool
{
return
false
}
addNodes
(
manager
.
nodeStore
.
Store
,
0
,
1
,
nil
)
// Simulates the ds reflector running before the pod reflector. We don't
// want to end up creating daemon pods in this case until the pod reflector
// has synced, so the ds manager should just requeue the ds.
ds
:=
newDaemonSet
(
"foo"
)
manager
.
dsStore
.
Add
(
ds
)
dsKey
:=
getKey
(
ds
,
t
)
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
0
,
0
)
queueDS
,
_
:=
manager
.
queue
.
Get
()
if
queueDS
!=
dsKey
{
t
.
Fatalf
(
"Expected to find key %v in queue, found %v"
,
dsKey
,
queueDS
)
}
manager
.
podStoreSynced
=
alwaysReady
syncAndValidateDaemonSets
(
t
,
manager
,
ds
,
podControl
,
1
,
0
)
}
// Daemon with node affinity should launch pods on nodes matching affinity.
func
TestNodeAffinityDaemonLaunchesPods
(
t
*
testing
.
T
)
{
manager
,
podControl
:=
newTestController
()
...
...
pkg/controller/framework/shared_informer.go
View file @
38583182
...
...
@@ -21,9 +21,12 @@ import (
"sync"
"time"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/runtime"
utilruntime
"k8s.io/kubernetes/pkg/util/runtime"
"k8s.io/kubernetes/pkg/util/wait"
)
// if you use this, there is one behavior change compared to a standard Informer.
...
...
@@ -75,6 +78,34 @@ func NewSharedIndexInformer(lw cache.ListerWatcher, objType runtime.Object, resy
return
sharedIndexInformer
}
// InformerSynced is a function that can be used to determine if an informer has synced. This is useful for determining if caches have synced.
type
InformerSynced
func
()
bool
// syncedPollPeriod controls how often you look at the status of your sync funcs
const
syncedPollPeriod
=
100
*
time
.
Millisecond
// WaitForCacheSync waits for caches to populate. It returns true if it was successful, false
// if the contoller should shutdown
func
WaitForCacheSync
(
stopCh
<-
chan
struct
{},
cacheSyncs
...
InformerSynced
)
bool
{
err
:=
wait
.
PollUntil
(
syncedPollPeriod
,
func
()
(
bool
,
error
)
{
for
_
,
syncFunc
:=
range
cacheSyncs
{
if
!
syncFunc
()
{
return
false
,
nil
}
}
return
true
,
nil
},
stopCh
)
if
err
!=
nil
{
glog
.
V
(
2
)
.
Infof
(
"stop requested"
)
return
false
}
glog
.
V
(
4
)
.
Infof
(
"caches populated"
)
return
true
}
type
sharedIndexInformer
struct
{
indexer
cache
.
Indexer
controller
*
Controller
...
...
pkg/util/wait/wait.go
View file @
38583182
...
...
@@ -186,7 +186,12 @@ func pollImmediateInternal(wait WaitFunc, condition ConditionFunc) error {
func
PollInfinite
(
interval
time
.
Duration
,
condition
ConditionFunc
)
error
{
done
:=
make
(
chan
struct
{})
defer
close
(
done
)
return
WaitFor
(
poller
(
interval
,
0
),
condition
,
done
)
return
PollUntil
(
interval
,
condition
,
done
)
}
// PollUntil is like Poll, but it takes a stop change instead of total duration
func
PollUntil
(
interval
time
.
Duration
,
condition
ConditionFunc
,
stopCh
<-
chan
struct
{})
error
{
return
WaitFor
(
poller
(
interval
,
0
),
condition
,
stopCh
)
}
// WaitFunc creates a channel that receives an item every time a test
...
...
pkg/util/wait/wait_test.go
View file @
38583182
...
...
@@ -432,3 +432,33 @@ func TestWaitForWithDelay(t *testing.T) {
t
.
Errorf
(
"expected an ack of the done signal."
)
}
}
func
TestPollUntil
(
t
*
testing
.
T
)
{
stopCh
:=
make
(
chan
struct
{})
called
:=
make
(
chan
bool
)
pollDone
:=
make
(
chan
struct
{})
go
func
()
{
PollUntil
(
time
.
Microsecond
,
ConditionFunc
(
func
()
(
bool
,
error
)
{
called
<-
true
return
false
,
nil
}),
stopCh
)
close
(
pollDone
)
}()
// make sure we're called once
<-
called
// this should trigger a "done"
close
(
stopCh
)
go
func
()
{
// release the condition func if needed
for
{
<-
called
}
}()
// make sure we finished the poll
<-
pollDone
}
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