const podStatusManagerStateFile … type versionedPodStatus … type manager … type PodManager … type PodStatusProvider … type PodDeletionSafetyProvider … type PodStartupLatencyStateHelper … type Manager … type allocationManager … const syncPeriod … // NewManager returns a functional Manager. func NewManager(kubeClient clientset.Interface, podManager PodManager, podDeletionSafety PodDeletionSafetyProvider, podStartupLatencyHelper PodStartupLatencyStateHelper, stateFileDirectory string) Manager { … } // isPodStatusByKubeletEqual returns true if the given pod statuses are equal when non-kubelet-owned // pod conditions are excluded. // This method normalizes the status before comparing so as to make sure that meaningless // changes will be ignored. func isPodStatusByKubeletEqual(oldStatus, status *v1.PodStatus) bool { … } func (m *manager) Start() { … } // GetContainerResourceAllocation returns the last checkpointed AllocatedResources values // If checkpoint manager has not been initialized, it returns nil, false func (m *manager) GetContainerResourceAllocation(podUID string, containerName string) (v1.ResourceRequirements, bool) { … } // UpdatePodFromAllocation overwrites the pod spec with the allocation. // This function does a deep copy only if updates are needed. func (m *manager) UpdatePodFromAllocation(pod *v1.Pod) (*v1.Pod, bool) { … } func updatePodFromAllocation(pod *v1.Pod, allocs state.PodResourceAllocation) (*v1.Pod, bool) { … } // GetPodResizeStatus returns the last checkpointed ResizeStaus value // If checkpoint manager has not been initialized, it returns nil, false func (m *manager) GetPodResizeStatus(podUID string) (v1.PodResizeStatus, bool) { … } // SetPodAllocation checkpoints the resources allocated to a pod's containers func (m *manager) SetPodAllocation(pod *v1.Pod) error { … } // SetPodResizeStatus checkpoints the last resizing decision for the pod. func (m *manager) SetPodResizeStatus(podUID types.UID, resizeStatus v1.PodResizeStatus) error { … } func (m *manager) GetPodStatus(uid types.UID) (v1.PodStatus, bool) { … } func (m *manager) SetPodStatus(pod *v1.Pod, status v1.PodStatus) { … } func (m *manager) SetContainerReadiness(podUID types.UID, containerID kubecontainer.ContainerID, ready bool) { … } func (m *manager) SetContainerStartup(podUID types.UID, containerID kubecontainer.ContainerID, started bool) { … } func findContainerStatus(status *v1.PodStatus, containerID string) (containerStatus *v1.ContainerStatus, init bool, ok bool) { … } // TerminatePod ensures that the status of containers is properly defaulted at the end of the pod // lifecycle. As the Kubelet must reconcile with the container runtime to observe container status // there is always the possibility we are unable to retrieve one or more container statuses due to // garbage collection, admin action, or loss of temporary data on a restart. This method ensures // that any absent container status is treated as a failure so that we do not incorrectly describe // the pod as successful. If we have not yet initialized the pod in the presence of init containers, // the init container failure status is sufficient to describe the pod as failing, and we do not need // to override waiting containers (unless there is evidence the pod previously started those containers). // It also makes sure that pods are transitioned to a terminal phase (Failed or Succeeded) before // their deletion. func (m *manager) TerminatePod(pod *v1.Pod) { … } // hasPodInitialized returns true if the pod has no evidence of ever starting a regular container, which // implies those containers should not be transitioned to terminated status. func hasPodInitialized(pod *v1.Pod) bool { … } // initializedContainers returns all status except for suffix of containers that are in Waiting // state, which is the set of containers that have attempted to start at least once. If all containers // are Waiting, the first container is always returned. func initializedContainers(containers []v1.ContainerStatus) []v1.ContainerStatus { … } // checkContainerStateTransition ensures that no container is trying to transition // from a terminated to non-terminated state, which is illegal and indicates a // logical error in the kubelet. func checkContainerStateTransition(oldStatuses, newStatuses *v1.PodStatus, podSpec *v1.PodSpec) error { … } // updateStatusInternal updates the internal status cache, and queues an update to the api server if // necessary. // This method IS NOT THREAD SAFE and must be called from a locked function. func (m *manager) updateStatusInternal(pod *v1.Pod, status v1.PodStatus, forceUpdate, podIsFinished bool) { … } // updateLastTransitionTime updates the LastTransitionTime of a pod condition. func updateLastTransitionTime(status, oldStatus *v1.PodStatus, conditionType v1.PodConditionType) { … } // deletePodStatus simply removes the given pod from the status cache. func (m *manager) deletePodStatus(uid types.UID) { … } // TODO(filipg): It'd be cleaner if we can do this without signal from user. func (m *manager) RemoveOrphanedStatuses(podUIDs map[types.UID]bool) { … } // syncBatch syncs pods statuses with the apiserver. Returns the number of syncs // attempted for testing. func (m *manager) syncBatch(all bool) int { … } // syncPod syncs the given status with the API server. The caller must not hold the status lock. func (m *manager) syncPod(uid types.UID, status versionedPodStatus) { … } // needsUpdate returns whether the status is stale for the given pod UID. // This method is not thread safe, and must only be accessed by the sync thread. func (m *manager) needsUpdate(uid types.UID, status versionedPodStatus) bool { … } func (m *manager) canBeDeleted(pod *v1.Pod, status v1.PodStatus, podIsFinished bool) bool { … } // needsReconcile compares the given status with the status in the pod manager (which // in fact comes from apiserver), returns whether the status needs to be reconciled with // the apiserver. Now when pod status is inconsistent between apiserver and kubelet, // kubelet should forcibly send an update to reconcile the inconsistence, because kubelet // should be the source of truth of pod status. // NOTE(random-liu): It's simpler to pass in mirror pod uid and get mirror pod by uid, but // now the pod manager only supports getting mirror pod by static pod, so we have to pass // static pod uid here. // TODO(random-liu): Simplify the logic when mirror pod manager is added. func (m *manager) needsReconcile(uid types.UID, status v1.PodStatus) bool { … } // normalizeStatus normalizes nanosecond precision timestamps in podStatus // down to second precision (*RFC339NANO* -> *RFC3339*). This must be done // before comparing podStatus to the status returned by apiserver because // apiserver does not support RFC339NANO. // Related issue #15262/PR #15263 to move apiserver to RFC339NANO is closed. func normalizeStatus(pod *v1.Pod, status *v1.PodStatus) *v1.PodStatus { … } // mergePodStatus merges oldPodStatus and newPodStatus to preserve where pod conditions // not owned by kubelet and to ensure terminal phase transition only happens after all // running containers have terminated. This method does not modify the old status. func mergePodStatus(oldPodStatus, newPodStatus v1.PodStatus, couldHaveRunningContainers bool) v1.PodStatus { … } // NeedToReconcilePodReadiness returns if the pod "Ready" condition need to be reconcile func NeedToReconcilePodReadiness(pod *v1.Pod) bool { … }