Skip to content

Commit

Permalink
Merge pull request #1059 from rphillips/fix_patch_104847
Browse files Browse the repository at this point in the history
Bug 2023779: Fix patch 104847
  • Loading branch information
openshift-merge-robot committed Nov 16, 2021
2 parents 0474f31 + 6dba76d commit c501845
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
10 changes: 5 additions & 5 deletions pkg/kubelet/kubelet_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -1098,12 +1098,12 @@ func (kl *Kubelet) HandlePodCleanups() error {
restartablePods := make(map[types.UID]sets.Empty)
for uid, sync := range workingPods {
switch sync {
case SyncPodWork:
case SyncPod:
runningPods[uid] = struct{}{}
possiblyRunningPods[uid] = struct{}{}
case TerminatingPodWork:
case TerminatingPod:
possiblyRunningPods[uid] = struct{}{}
case TemporarilyTerminatedPodWork:
case TerminatedAndRecreatedPod:
restartablePods[uid] = struct{}{}
}
}
Expand All @@ -1120,8 +1120,8 @@ func (kl *Kubelet) HandlePodCleanups() error {
return err
}
for _, runningPod := range runningRuntimePods {
switch workType, ok := workingPods[runningPod.ID]; {
case ok && workType == SyncPodWork, ok && workType == TerminatingPodWork:
switch workerState, ok := workingPods[runningPod.ID]; {
case ok && workerState == SyncPod, ok && workerState == TerminatingPod:
// if the pod worker is already in charge of this pod, we don't need to do anything
continue
default:
Expand Down
40 changes: 28 additions & 12 deletions pkg/kubelet/pod_workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,34 @@ type UpdatePodOptions struct {
type PodWorkType int

const (
// SyncPodSync is when the pod is expected to be started and running.
// SyncPodWork is when the pod is expected to be started and running.
SyncPodWork PodWorkType = iota
// TerminatingPodWork is when the pod is no longer being set up, but some
// containers may be running and are being torn down.
TerminatingPodWork
// TerminatedPodWork indicates the pod is stopped, can have no more running
// containers, and any foreground cleanup can be executed.
TerminatedPodWork
// TemporarilyTerminatedPodWork is the same as TerminatedPodWork, but indicates
// that a create update was delivered AFTER the pod was terminated, indicating
// that the pod may have been recreated with the same UID.
TemporarilyTerminatedPodWork
)

// PodWorkType classifies the status of pod as seen by the pod worker - setup (sync),
// teardown of containers (terminating), cleanup (terminated), or recreated with the
// same UID (kill -> create while terminating)
type PodWorkerState int

const (
// SyncPod is when the pod is expected to be started and running.
SyncPod PodWorkerState = iota
// TerminatingPod is when the pod is no longer being set up, but some
// containers may be running and are being torn down.
TerminatingPod
// TerminatedPod indicates the pod is stopped, can have no more running
// containers, and any foreground cleanup can be executed.
TerminatedPod
// TerminatedAndRecreatedPod indicates that after the pod was terminating a
// request to recreate the pod was received. The pod is terminated and can
// now be restarted by sending a create event to the pod worker.
TerminatedAndRecreatedPod
)

// podWork is the internal changes
Expand Down Expand Up @@ -133,7 +149,7 @@ type PodWorkers interface {
// has been called once, the workers are assumed to be fully initialized and
// subsequent calls to ShouldPodContentBeRemoved on unknown pods will return
// true. It returns a map describing the state of each known pod worker.
SyncKnownPods(desiredPods []*v1.Pod) map[types.UID]PodWorkType
SyncKnownPods(desiredPods []*v1.Pod) map[types.UID]PodWorkerState

// IsPodKnownTerminated returns true if the provided pod UID is known by the pod
// worker to be terminated. If the pod has been force deleted and the pod worker
Expand Down Expand Up @@ -1020,8 +1036,8 @@ func (p *podWorkers) contextForWorker(uid types.UID) context.Context {
// to UpdatePods for new pods. It returns a map of known workers that are not finished
// with a value of SyncPodTerminated, SyncPodKill, or SyncPodSync depending on whether
// the pod is terminated, terminating, or syncing.
func (p *podWorkers) SyncKnownPods(desiredPods []*v1.Pod) map[types.UID]PodWorkType {
workers := make(map[types.UID]PodWorkType)
func (p *podWorkers) SyncKnownPods(desiredPods []*v1.Pod) map[types.UID]PodWorkerState {
workers := make(map[types.UID]PodWorkerState)
known := make(map[types.UID]struct{})
for _, pod := range desiredPods {
known[pod.UID] = struct{}{}
Expand All @@ -1038,14 +1054,14 @@ func (p *podWorkers) SyncKnownPods(desiredPods []*v1.Pod) map[types.UID]PodWorkT
switch {
case !status.terminatedAt.IsZero():
if status.restartRequested {
workers[uid] = TemporarilyTerminatedPodWork
workers[uid] = TerminatedAndRecreatedPod
} else {
workers[uid] = TerminatedPodWork
workers[uid] = TerminatedPod
}
case !status.terminatingAt.IsZero():
workers[uid] = TerminatingPodWork
workers[uid] = TerminatingPod
default:
workers[uid] = SyncPodWork
workers[uid] = SyncPod
}
}
return workers
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubelet/pod_workers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (f *fakePodWorkers) UpdatePod(options UpdatePodOptions) {
}
}

func (f *fakePodWorkers) SyncKnownPods(desiredPods []*v1.Pod) map[types.UID]PodWorkType {
func (f *fakePodWorkers) SyncKnownPods(desiredPods []*v1.Pod) map[types.UID]PodWorkerState {
return nil
}

Expand Down

0 comments on commit c501845

Please sign in to comment.