@@ -32,17 +32,17 @@ import (
32
32
33
33
// containerGC is the manager of garbage collection.
34
34
type containerGC struct {
35
- client internalapi.RuntimeService
36
- manager * kubeGenericRuntimeManager
37
- podDeletionProvider podDeletionProvider
35
+ client internalapi.RuntimeService
36
+ manager * kubeGenericRuntimeManager
37
+ podStateProvider podStateProvider
38
38
}
39
39
40
40
// NewContainerGC creates a new containerGC.
41
- func NewContainerGC (client internalapi.RuntimeService , podDeletionProvider podDeletionProvider , manager * kubeGenericRuntimeManager ) * containerGC {
41
+ func NewContainerGC (client internalapi.RuntimeService , podStateProvider podStateProvider , manager * kubeGenericRuntimeManager ) * containerGC {
42
42
return & containerGC {
43
- client : client ,
44
- manager : manager ,
45
- podDeletionProvider : podDeletionProvider ,
43
+ client : client ,
44
+ manager : manager ,
45
+ podStateProvider : podStateProvider ,
46
46
}
47
47
}
48
48
@@ -200,7 +200,7 @@ func (cgc *containerGC) evictableContainers(minAge time.Duration) (containersByE
200
200
}
201
201
202
202
// evict all containers that are evictable
203
- func (cgc * containerGC ) evictContainers (gcPolicy kubecontainer.ContainerGCPolicy , allSourcesReady bool , evictNonDeletedPods bool ) error {
203
+ func (cgc * containerGC ) evictContainers (gcPolicy kubecontainer.ContainerGCPolicy , allSourcesReady bool , evictTerminatedPods bool ) error {
204
204
// Separate containers by evict units.
205
205
evictUnits , err := cgc .evictableContainers (gcPolicy .MinAge )
206
206
if err != nil {
@@ -210,7 +210,7 @@ func (cgc *containerGC) evictContainers(gcPolicy kubecontainer.ContainerGCPolicy
210
210
// Remove deleted pod containers if all sources are ready.
211
211
if allSourcesReady {
212
212
for key , unit := range evictUnits {
213
- if cgc .podDeletionProvider .IsPodDeleted (key .uid ) || evictNonDeletedPods {
213
+ if cgc .podStateProvider .IsPodDeleted (key .uid ) || ( cgc . podStateProvider . IsPodTerminated ( key . uid ) && evictTerminatedPods ) {
214
214
cgc .removeOldestN (unit , len (unit )) // Remove all.
215
215
delete (evictUnits , key )
216
216
}
@@ -252,7 +252,7 @@ func (cgc *containerGC) evictContainers(gcPolicy kubecontainer.ContainerGCPolicy
252
252
// 2. contains no containers.
253
253
// 3. belong to a non-existent (i.e., already removed) pod, or is not the
254
254
// most recently created sandbox for the pod.
255
- func (cgc * containerGC ) evictSandboxes (evictNonDeletedPods bool ) error {
255
+ func (cgc * containerGC ) evictSandboxes (evictTerminatedPods bool ) error {
256
256
containers , err := cgc .manager .getKubeletContainers (true )
257
257
if err != nil {
258
258
return err
@@ -298,7 +298,7 @@ func (cgc *containerGC) evictSandboxes(evictNonDeletedPods bool) error {
298
298
}
299
299
300
300
for podUID , sandboxes := range sandboxesByPod {
301
- if cgc .podDeletionProvider .IsPodDeleted (podUID ) || evictNonDeletedPods {
301
+ if cgc .podStateProvider .IsPodDeleted (podUID ) || ( cgc . podStateProvider . IsPodTerminated ( podUID ) && evictTerminatedPods ) {
302
302
// Remove all evictable sandboxes if the pod has been removed.
303
303
// Note that the latest dead sandbox is also removed if there is
304
304
// already an active one.
@@ -324,7 +324,7 @@ func (cgc *containerGC) evictPodLogsDirectories(allSourcesReady bool) error {
324
324
for _ , dir := range dirs {
325
325
name := dir .Name ()
326
326
podUID := types .UID (name )
327
- if ! cgc .podDeletionProvider .IsPodDeleted (podUID ) {
327
+ if ! cgc .podStateProvider .IsPodDeleted (podUID ) {
328
328
continue
329
329
}
330
330
err := osInterface .RemoveAll (filepath .Join (podLogsRootDirectory , name ))
@@ -358,14 +358,14 @@ func (cgc *containerGC) evictPodLogsDirectories(allSourcesReady bool) error {
358
358
// * removes oldest dead containers by enforcing gcPolicy.MaxContainers.
359
359
// * gets evictable sandboxes which are not ready and contains no containers.
360
360
// * removes evictable sandboxes.
361
- func (cgc * containerGC ) GarbageCollect (gcPolicy kubecontainer.ContainerGCPolicy , allSourcesReady bool , evictNonDeletedPods bool ) error {
361
+ func (cgc * containerGC ) GarbageCollect (gcPolicy kubecontainer.ContainerGCPolicy , allSourcesReady bool , evictTerminatedPods bool ) error {
362
362
// Remove evictable containers
363
- if err := cgc .evictContainers (gcPolicy , allSourcesReady , evictNonDeletedPods ); err != nil {
363
+ if err := cgc .evictContainers (gcPolicy , allSourcesReady , evictTerminatedPods ); err != nil {
364
364
return err
365
365
}
366
366
367
367
// Remove sandboxes with zero containers
368
- if err := cgc .evictSandboxes (evictNonDeletedPods ); err != nil {
368
+ if err := cgc .evictSandboxes (evictTerminatedPods ); err != nil {
369
369
return err
370
370
}
371
371
0 commit comments