mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
kubelet: make sure sync loop is run before performing housekeeping
Otherwise, kubelet may kill the existing pods before having a chance to update the desired pods.
This commit is contained in:
parent
db128ac0f7
commit
8f8541b4cd
@ -1628,13 +1628,6 @@ func (kl *Kubelet) deletePod(uid types.UID) error {
|
|||||||
// should not contain any blocking calls. Re-examine the function and decide
|
// should not contain any blocking calls. Re-examine the function and decide
|
||||||
// whether or not we should move it into a separte goroutine.
|
// whether or not we should move it into a separte goroutine.
|
||||||
func (kl *Kubelet) HandlePodCleanups() error {
|
func (kl *Kubelet) HandlePodCleanups() error {
|
||||||
if !kl.sourcesReady() {
|
|
||||||
// If the sources aren't ready, skip deletion, as we may accidentally delete pods
|
|
||||||
// for sources that haven't reported yet.
|
|
||||||
glog.V(4).Infof("Skipping cleanup, sources aren't ready yet.")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
allPods, mirrorPods := kl.podManager.GetPodsAndMirrorPods()
|
allPods, mirrorPods := kl.podManager.GetPodsAndMirrorPods()
|
||||||
// Pod phase progresses monotonically. Once a pod has reached a final state,
|
// Pod phase progresses monotonically. Once a pod has reached a final state,
|
||||||
// it should never leave regardless of the restart policy. The statuses
|
// it should never leave regardless of the restart policy. The statuses
|
||||||
@ -1878,22 +1871,31 @@ func (kl *Kubelet) syncLoop(updates <-chan PodUpdate, handler SyncHandler) {
|
|||||||
glog.Infof("Skipping pod synchronization, network is not configured")
|
glog.Infof("Skipping pod synchronization, network is not configured")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure we sync first to receive the pods from the sources before
|
||||||
|
// performing housekeeping.
|
||||||
|
if !kl.syncLoopIteration(updates, handler) {
|
||||||
|
break
|
||||||
|
}
|
||||||
// We don't want to perform housekeeping too often, so we set a minimum
|
// We don't want to perform housekeeping too often, so we set a minimum
|
||||||
// period for it. Housekeeping would be performed at least once every
|
// period for it. Housekeeping would be performed at least once every
|
||||||
// kl.resyncInterval, and *no* more than once every
|
// kl.resyncInterval, and *no* more than once every
|
||||||
// housekeepingMinimumPeriod.
|
// housekeepingMinimumPeriod.
|
||||||
// TODO (#13418): Investigate whether we can/should spawn a dedicated
|
// TODO (#13418): Investigate whether we can/should spawn a dedicated
|
||||||
// goroutine for housekeeping
|
// goroutine for housekeeping
|
||||||
if housekeepingTimestamp.IsZero() || time.Since(housekeepingTimestamp) > housekeepingMinimumPeriod {
|
if !kl.sourcesReady() {
|
||||||
|
// If the sources aren't ready, skip housekeeping, as we may
|
||||||
|
// accidentally delete pods from unready sources.
|
||||||
|
glog.V(4).Infof("Skipping cleanup, sources aren't ready yet.")
|
||||||
|
} else if housekeepingTimestamp.IsZero() {
|
||||||
|
housekeepingTimestamp = time.Now()
|
||||||
|
} else if time.Since(housekeepingTimestamp) > housekeepingMinimumPeriod {
|
||||||
glog.V(4).Infof("SyncLoop (housekeeping)")
|
glog.V(4).Infof("SyncLoop (housekeeping)")
|
||||||
if err := handler.HandlePodCleanups(); err != nil {
|
if err := handler.HandlePodCleanups(); err != nil {
|
||||||
glog.Errorf("Failed cleaning pods: %v", err)
|
glog.Errorf("Failed cleaning pods: %v", err)
|
||||||
}
|
}
|
||||||
housekeepingTimestamp = time.Now()
|
housekeepingTimestamp = time.Now()
|
||||||
}
|
}
|
||||||
if !kl.syncLoopIteration(updates, handler) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user