@@ -654,6 +654,7 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
654
654
}
655
655
klet .containerGC = containerGC
656
656
klet .containerDeletor = newPodContainerDeletor (klet .containerRuntime , integer .IntMax (containerGCPolicy .MaxPerPodContainer , minDeadContainerInPod ))
657
+ klet .sandboxDeleter = newPodSandboxDeleter (klet .containerRuntime )
657
658
658
659
// setup imageManager
659
660
imageManager , err := images .NewImageGCManager (klet .containerRuntime , klet .StatsProvider , kubeDeps .Recorder , nodeRef , imageGCPolicy , crOptions .PodSandboxImage )
@@ -1095,6 +1096,9 @@ type Kubelet struct {
1095
1096
// trigger deleting containers in a pod
1096
1097
containerDeletor * podContainerDeletor
1097
1098
1099
+ // trigger deleting sandboxes in a pod
1100
+ sandboxDeleter * podSandboxDeleter
1101
+
1098
1102
// config iptables util rules
1099
1103
makeIPTablesUtilChains bool
1100
1104
@@ -1866,6 +1870,9 @@ func (kl *Kubelet) syncLoopIteration(configCh <-chan kubetypes.PodUpdate, handle
1866
1870
klog .V (4 ).Infof ("SyncLoop (PLEG): ignore irrelevant event: %#v" , e )
1867
1871
}
1868
1872
}
1873
+ if e .Type == pleg .ContainerRemoved {
1874
+ kl .deletePodSandbox (e .ID )
1875
+ }
1869
1876
1870
1877
if e .Type == pleg .ContainerDied {
1871
1878
if containerID , ok := e .Data .(string ); ok {
@@ -2193,6 +2200,16 @@ func (kl *Kubelet) fastStatusUpdateOnce() {
2193
2200
}
2194
2201
}
2195
2202
2203
+ func (kl * Kubelet ) deletePodSandbox (podID types.UID ) {
2204
+ if podStatus , err := kl .podCache .Get (podID ); err == nil {
2205
+ toKeep := 1
2206
+ if kl .IsPodDeleted (podID ) {
2207
+ toKeep = 0
2208
+ }
2209
+ kl .sandboxDeleter .deleteSandboxesInPod (podStatus , toKeep )
2210
+ }
2211
+ }
2212
+
2196
2213
// isSyncPodWorthy filters out events that are not worthy of pod syncing
2197
2214
func isSyncPodWorthy (event * pleg.PodLifecycleEvent ) bool {
2198
2215
// ContainerRemoved doesn't affect pod state
0 commit comments