From 026b97352f1c6d4b4b579dfa5bc5816418908603 Mon Sep 17 00:00:00 2001 From: Michal Wozniak Date: Tue, 8 Nov 2022 09:42:59 +0100 Subject: [PATCH] Add comments to clarify the updated logic in kubelet's status_manager --- pkg/kubelet/status/status_manager.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/kubelet/status/status_manager.go b/pkg/kubelet/status/status_manager.go index 5b5f482f1747..219bfc90e6f0 100644 --- a/pkg/kubelet/status/status_manager.go +++ b/pkg/kubelet/status/status_manager.go @@ -894,12 +894,16 @@ func mergePodStatus(oldPodStatus, newPodStatus v1.PodStatus, couldHaveRunningCon if kubetypes.PodConditionByKubelet(c.Type) { podConditions = append(podConditions, c) } else if kubetypes.PodConditionSharedByKubelet(c.Type) { + // we replace or append all the "shared by kubelet" conditions if c.Type == v1.AlphaNoCompatGuaranteeDisruptionTarget { - // update the pod disruption condition only if transitioning to terminal phase. In particular, check if - // there might still be running containers to avoid sending an unnecessary PATCH request if the - // actual transition is delayed (see below) + // guard the update of the DisruptionTarget condition with a check to ensure + // it will only be sent once all containers have terminated and the phase + // is terminal. This avoids sending an unnecessary patch request to add + // the condition if the actual status phase transition is delayed. if transitioningToTerminalPhase && !couldHaveRunningContainers { - // update the LastTransitionTime + // update the LastTransitionTime again here because the older transition + // time set in updateStatusInternal is likely stale as sending of + // the condition was delayed until all pod's containers have terminated. updateLastTransitionTime(&newPodStatus, &oldPodStatus, c.Type) if _, c := podutil.GetPodConditionFromList(newPodStatus.Conditions, c.Type); c != nil { // for shared conditions we update or append in podConditions