Merge pull request #4897 from ywk253100/220609_gc

Make garbage collection for expired backups configurable
This commit is contained in:
qiuming
2022-05-11 10:46:03 +08:00
committed by GitHub
8 changed files with 39 additions and 2 deletions

View File

@@ -39,7 +39,7 @@ import (
)
const (
GCSyncPeriod = 60 * time.Minute
defaultGCFrequency = 60 * time.Minute
garbageCollectionFailure = "velero.io/gc-failure"
gcFailureBSLNotFound = "BSLNotFound"
gcFailureBSLCannotGet = "BSLCannotGet"
@@ -54,6 +54,7 @@ type gcController struct {
deleteBackupRequestLister velerov1listers.DeleteBackupRequestLister
deleteBackupRequestClient velerov1client.DeleteBackupRequestsGetter
kbClient client.Client
frequency time.Duration
clock clock.Clock
}
@@ -65,6 +66,7 @@ func NewGCController(
deleteBackupRequestLister velerov1listers.DeleteBackupRequestLister,
deleteBackupRequestClient velerov1client.DeleteBackupRequestsGetter,
kbClient client.Client,
frequency time.Duration,
) Interface {
c := &gcController{
genericController: newGenericController(GarbageCollection, logger),
@@ -76,7 +78,11 @@ func NewGCController(
}
c.syncHandler = c.processQueueItem
c.resyncPeriod = GCSyncPeriod
c.resyncPeriod = frequency
if c.resyncPeriod < 0 {
c.resyncPeriod = defaultGCFrequency
}
logger.Infof("Garbage collection frequency: %s", c.resyncPeriod.String())
c.resyncFunc = c.enqueueAllBackups
backupInformer.Informer().AddEventHandler(

View File

@@ -53,6 +53,7 @@ func TestGCControllerEnqueueAllBackups(t *testing.T) {
sharedInformers.Velero().V1().DeleteBackupRequests().Lister(),
client.VeleroV1(),
nil,
defaultGCFrequency,
).(*gcController)
)
@@ -114,6 +115,7 @@ func TestGCControllerHasUpdateFunc(t *testing.T) {
sharedInformers.Velero().V1().DeleteBackupRequests().Lister(),
client.VeleroV1(),
nil,
defaultGCFrequency,
).(*gcController)
keys := make(chan string)
@@ -262,6 +264,7 @@ func TestGCControllerProcessQueueItem(t *testing.T) {
sharedInformers.Velero().V1().DeleteBackupRequests().Lister(),
client.VeleroV1(),
fakeClient,
defaultGCFrequency,
).(*gcController)
controller.clock = fakeClock