mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-19 16:49:35 +00:00
Always resync after resyncInterval
This commit is contained in:
parent
0a822bb742
commit
17b0a964f4
@ -475,6 +475,7 @@ type Kubelet struct {
|
|||||||
rootDirectory string
|
rootDirectory string
|
||||||
podWorkers PodWorkers
|
podWorkers PodWorkers
|
||||||
resyncInterval time.Duration
|
resyncInterval time.Duration
|
||||||
|
resyncTicker *time.Ticker
|
||||||
sourcesReady SourcesReadyFn
|
sourcesReady SourcesReadyFn
|
||||||
// sourcesSeen records the sources seen by kubelet. This set is not thread
|
// sourcesSeen records the sources seen by kubelet. This set is not thread
|
||||||
// safe and should only be access by the main kubelet syncloop goroutine.
|
// safe and should only be access by the main kubelet syncloop goroutine.
|
||||||
@ -2010,6 +2011,7 @@ func (kl *Kubelet) canAdmitPod(pods []*api.Pod, pod *api.Pod) (bool, string, str
|
|||||||
// state every sync-frequency seconds. Never returns.
|
// state every sync-frequency seconds. Never returns.
|
||||||
func (kl *Kubelet) syncLoop(updates <-chan kubetypes.PodUpdate, handler SyncHandler) {
|
func (kl *Kubelet) syncLoop(updates <-chan kubetypes.PodUpdate, handler SyncHandler) {
|
||||||
glog.Info("Starting kubelet main sync loop.")
|
glog.Info("Starting kubelet main sync loop.")
|
||||||
|
kl.resyncTicker = time.NewTicker(kl.resyncInterval)
|
||||||
var housekeepingTimestamp time.Time
|
var housekeepingTimestamp time.Time
|
||||||
for {
|
for {
|
||||||
if !kl.containerRuntimeUp() {
|
if !kl.containerRuntimeUp() {
|
||||||
@ -2073,7 +2075,7 @@ func (kl *Kubelet) syncLoopIteration(updates <-chan kubetypes.PodUpdate, handler
|
|||||||
// TODO: Do we want to support this?
|
// TODO: Do we want to support this?
|
||||||
glog.Errorf("Kubelet does not support snapshot update")
|
glog.Errorf("Kubelet does not support snapshot update")
|
||||||
}
|
}
|
||||||
case <-time.After(kl.resyncInterval):
|
case <-kl.resyncTicker.C:
|
||||||
// Periodically syncs all the pods and performs cleanup tasks.
|
// Periodically syncs all the pods and performs cleanup tasks.
|
||||||
glog.V(4).Infof("SyncLoop (periodic sync)")
|
glog.V(4).Infof("SyncLoop (periodic sync)")
|
||||||
handler.HandlePodSyncs(kl.podManager.GetPods())
|
handler.HandlePodSyncs(kl.podManager.GetPods())
|
||||||
|
@ -145,6 +145,7 @@ func newTestKubelet(t *testing.T) *TestKubelet {
|
|||||||
kubelet.backOff = util.NewBackOff(time.Second, time.Minute)
|
kubelet.backOff = util.NewBackOff(time.Second, time.Minute)
|
||||||
kubelet.backOff.Clock = fakeClock
|
kubelet.backOff.Clock = fakeClock
|
||||||
kubelet.podKillingCh = make(chan *kubecontainer.Pod, 20)
|
kubelet.podKillingCh = make(chan *kubecontainer.Pod, 20)
|
||||||
|
kubelet.resyncInterval = 10 * time.Second
|
||||||
return &TestKubelet{kubelet, fakeRuntime, mockCadvisor, fakeKubeClient, fakeMirrorClient}
|
return &TestKubelet{kubelet, fakeRuntime, mockCadvisor, fakeKubeClient, fakeMirrorClient}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,6 +333,9 @@ func TestSyncLoopTimeUpdate(t *testing.T) {
|
|||||||
t.Errorf("Unexpected sync loop time: %s, expected 0", loopTime1)
|
t.Errorf("Unexpected sync loop time: %s, expected 0", loopTime1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start sync ticker.
|
||||||
|
kubelet.resyncTicker = time.NewTicker(time.Millisecond)
|
||||||
|
|
||||||
kubelet.syncLoopIteration(make(chan kubetypes.PodUpdate), kubelet)
|
kubelet.syncLoopIteration(make(chan kubetypes.PodUpdate), kubelet)
|
||||||
loopTime2 := kubelet.LatestLoopEntryTime()
|
loopTime2 := kubelet.LatestLoopEntryTime()
|
||||||
if loopTime2.IsZero() {
|
if loopTime2.IsZero() {
|
||||||
@ -350,9 +354,9 @@ func TestSyncLoopAbort(t *testing.T) {
|
|||||||
kubelet := testKubelet.kubelet
|
kubelet := testKubelet.kubelet
|
||||||
kubelet.lastTimestampRuntimeUp = time.Now()
|
kubelet.lastTimestampRuntimeUp = time.Now()
|
||||||
kubelet.networkConfigured = true
|
kubelet.networkConfigured = true
|
||||||
// The syncLoop waits on time.After(resyncInterval), set it really big so that we don't race for
|
// The syncLoop waits on the resyncTicker, so we stop it immediately to avoid a race.
|
||||||
// the channel close
|
kubelet.resyncTicker = time.NewTicker(time.Second)
|
||||||
kubelet.resyncInterval = time.Second * 30
|
kubelet.resyncTicker.Stop()
|
||||||
|
|
||||||
ch := make(chan kubetypes.PodUpdate)
|
ch := make(chan kubetypes.PodUpdate)
|
||||||
close(ch)
|
close(ch)
|
||||||
|
Loading…
Reference in New Issue
Block a user