From db5d74935eedd9824e5c1301b4ba99e83ba5f504 Mon Sep 17 00:00:00 2001 From: charles-chenzz Date: Thu, 13 Apr 2023 08:51:26 +0800 Subject: [PATCH] optimize evict sandbox logic --- pkg/kubelet/kuberuntime/kuberuntime_gc.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_gc.go b/pkg/kubelet/kuberuntime/kuberuntime_gc.go index a91e190ee75..35a19704b95 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_gc.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_gc.go @@ -293,7 +293,7 @@ func (cgc *containerGC) evictSandboxes(ctx context.Context, evictNonDeletedPods sandboxIDs.Insert(container.PodSandboxId) } - sandboxesByPod := make(sandboxesByPodUID) + sandboxesByPod := make(sandboxesByPodUID, len(sandboxes)) for _, sandbox := range sandboxes { podUID := types.UID(sandbox.Metadata.Uid) sandboxInfo := sandboxGCInfo{ @@ -301,13 +301,8 @@ func (cgc *containerGC) evictSandboxes(ctx context.Context, evictNonDeletedPods createTime: time.Unix(0, sandbox.CreatedAt), } - // Set ready sandboxes to be active. - if sandbox.State == runtimeapi.PodSandboxState_SANDBOX_READY { - sandboxInfo.active = true - } - - // Set sandboxes that still have containers to be active. - if sandboxIDs.Has(sandbox.Id) { + // Set ready sandboxes and sandboxes that still have containers to be active. + if sandbox.State == runtimeapi.PodSandboxState_SANDBOX_READY || sandboxIDs.Has(sandbox.Id) { sandboxInfo.active = true }