From 8d27bf2108cca3788ef0b6ca2f4a193a467ebf94 Mon Sep 17 00:00:00 2001 From: Gunju Kim Date: Sun, 2 Feb 2025 17:45:50 +0900 Subject: [PATCH] Leave TODOs in pkg/kubelet/kuberuntime for later removal This leaves TODOs in pkg/kubelet/kuberuntime to remove these redundant code paths later, since they are supposed to be a subset of the new code paths. --- pkg/kubelet/kuberuntime/kuberuntime_container.go | 2 ++ pkg/kubelet/kuberuntime/kuberuntime_manager.go | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go index bd2e01e09d0..2f43ddfe63e 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container.go @@ -929,6 +929,8 @@ func (m *kubeGenericRuntimeManager) purgeInitContainers(ctx context.Context, pod // index of next init container to start, or done if there are no further init containers. // Status is only returned if an init container is failed, in which case next will // point to the current container. +// TODO: Remove this function as this is a subset of the +// computeInitContainerActions. func findNextInitContainerToRun(pod *v1.Pod, podStatus *kubecontainer.PodStatus) (status *kubecontainer.Status, next *v1.Container, done bool) { if len(pod.Spec.InitContainers) == 0 { return nil, nil, true diff --git a/pkg/kubelet/kuberuntime/kuberuntime_manager.go b/pkg/kubelet/kuberuntime/kuberuntime_manager.go index 2988aadc675..f42d97b6e8a 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_manager.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_manager.go @@ -496,6 +496,8 @@ type podActions struct { Attempt uint32 // The next init container to start. + // TODO: Either this or InitContainersToStart will be used. Remove this + // field once it is not needed. NextInitContainerToStart *v1.Container // InitContainersToStart keeps a list of indexes for the init containers to // start, where the index is the index of the specific init container in the @@ -934,6 +936,8 @@ func (m *kubeGenericRuntimeManager) computePodActions(ctx context.Context, pod * // is done and there is no container to start. if len(containersToStart) == 0 { hasInitialized := false + // TODO: Remove this code path as logically it is the subset of the next + // code path. if !handleRestartableInitContainers { _, _, hasInitialized = findNextInitContainerToRun(pod, podStatus) } else { @@ -952,6 +956,8 @@ func (m *kubeGenericRuntimeManager) computePodActions(ctx context.Context, pod * // state. if len(pod.Spec.InitContainers) != 0 { // Pod has init containers, return the first one. + // TODO: Remove this code path as logically it is the subset of the next + // code path. if !handleRestartableInitContainers { changes.NextInitContainerToStart = &pod.Spec.InitContainers[0] } else { @@ -975,6 +981,8 @@ func (m *kubeGenericRuntimeManager) computePodActions(ctx context.Context, pod * } // Check initialization progress. + // TODO: Remove this code path as logically it is the subset of the next + // code path. if !handleRestartableInitContainers { initLastStatus, next, done := findNextInitContainerToRun(pod, podStatus) if !done { @@ -1095,6 +1103,8 @@ func (m *kubeGenericRuntimeManager) computePodActions(ctx context.Context, pod * if keepCount == 0 && len(changes.ContainersToStart) == 0 { changes.KillPod = true + // TODO: Remove this code path as logically it is the subset of the next + // code path. if handleRestartableInitContainers { // To prevent the restartable init containers to keep pod alive, we should // not restart them. @@ -1353,6 +1363,8 @@ func (m *kubeGenericRuntimeManager) SyncPod(ctx context.Context, pod *v1.Pod, po start(ctx, "ephemeral container", metrics.EphemeralContainer, ephemeralContainerStartSpec(&pod.Spec.EphemeralContainers[idx])) } + // TODO: Remove this code path as logically it is the subset of the next + // code path. if !types.HasRestartableInitContainer(pod) { // Step 6: start the init container. if container := podContainerChanges.NextInitContainerToStart; container != nil {