diff --git a/pkg/repository/maintenance.go b/pkg/repository/maintenance.go index 5ea63979f0..87facaab59 100644 --- a/pkg/repository/maintenance.go +++ b/pkg/repository/maintenance.go @@ -34,6 +34,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" + "github.com/vmware-tanzu/velero/pkg/repository/udmrepo" "github.com/vmware-tanzu/velero/pkg/util/kube" ) @@ -48,6 +49,8 @@ type JobConfigs struct { // PodResources is the config for the CPU and memory resources setting. PodResources *kube.PodResources `json:"podResources,omitempty"` + // FullMaintenanceInterval defines how often Full Maintenance Tasks are due on the repository. + FullMaintenanceInterval udmrepo.FullMaintenanceIntervalOptions `json:"fullMaintenanceInterval,omitempty"` } func GenerateJobName(repo string) string { diff --git a/pkg/repository/manager/manager.go b/pkg/repository/manager/manager.go index f590f2b145..d38fafb8e4 100644 --- a/pkg/repository/manager/manager.go +++ b/pkg/repository/manager/manager.go @@ -348,9 +348,21 @@ func (m *manager) assembleRepoParam(repo *velerov1api.BackupRepository) (provide if err := m.client.Get(context.Background(), client.ObjectKey{Namespace: m.namespace, Name: repo.Spec.BackupStorageLocation}, bsl); err != nil { return provider.RepoParam{}, errors.WithStack(err) } + jobConfig, err := repository.GetMaintenanceJobConfig( + context.Background(), + m.client, + m.log, + m.namespace, + m.repoMaintenanceJobConfig, + repo, + ) + if err != nil { + return provider.RepoParam{}, err + } return provider.RepoParam{ - BackupLocation: bsl, - BackupRepo: repo, + BackupLocation: bsl, + BackupRepo: repo, + FullMaintenanceInterval: jobConfig.FullMaintenanceInterval, }, nil } diff --git a/pkg/repository/provider/provider.go b/pkg/repository/provider/provider.go index d27d269da6..058e260e67 100644 --- a/pkg/repository/provider/provider.go +++ b/pkg/repository/provider/provider.go @@ -21,12 +21,14 @@ import ( "time" velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1" + "github.com/vmware-tanzu/velero/pkg/repository/udmrepo" ) // RepoParam includes the parameters to manipulate a backup repository type RepoParam struct { - BackupLocation *velerov1api.BackupStorageLocation - BackupRepo *velerov1api.BackupRepository + BackupLocation *velerov1api.BackupStorageLocation + BackupRepo *velerov1api.BackupRepository + FullMaintenanceInterval udmrepo.FullMaintenanceIntervalOptions } // Provider defines the methods to manipulate a backup repository diff --git a/pkg/repository/provider/unified_repo.go b/pkg/repository/provider/unified_repo.go index 6191c44528..0b9e0eeee4 100644 --- a/pkg/repository/provider/unified_repo.go +++ b/pkg/repository/provider/unified_repo.go @@ -106,6 +106,7 @@ func (urp *unifiedRepoProvider) InitRepo(ctx context.Context, param RepoParam) e ), udmrepo.WithStoreOptions(urp, param), udmrepo.WithDescription(repoConnectDesc), + udmrepo.WithFullMaintenanceInterval(param.FullMaintenanceInterval), ) if err != nil { @@ -142,6 +143,7 @@ func (urp *unifiedRepoProvider) ConnectToRepo(ctx context.Context, param RepoPar ), udmrepo.WithStoreOptions(urp, param), udmrepo.WithDescription(repoConnectDesc), + udmrepo.WithFullMaintenanceInterval(param.FullMaintenanceInterval), ) if err != nil { @@ -178,6 +180,7 @@ func (urp *unifiedRepoProvider) PrepareRepo(ctx context.Context, param RepoParam ), udmrepo.WithStoreOptions(urp, param), udmrepo.WithDescription(repoConnectDesc), + udmrepo.WithFullMaintenanceInterval(param.FullMaintenanceInterval), ) if err != nil { @@ -216,6 +219,7 @@ func (urp *unifiedRepoProvider) BoostRepoConnect(ctx context.Context, param Repo udmrepo.WithPassword(urp, param), udmrepo.WithConfigFile(urp.workPath, string(param.BackupRepo.UID)), udmrepo.WithDescription(repoConnectDesc), + udmrepo.WithFullMaintenanceInterval(param.FullMaintenanceInterval), ) if err != nil { @@ -247,6 +251,7 @@ func (urp *unifiedRepoProvider) PruneRepo(ctx context.Context, param RepoParam) udmrepo.WithPassword(urp, param), udmrepo.WithConfigFile(urp.workPath, string(param.BackupRepo.UID)), udmrepo.WithDescription(repoOpDescMaintain), + udmrepo.WithFullMaintenanceInterval(param.FullMaintenanceInterval), ) if err != nil { @@ -281,6 +286,7 @@ func (urp *unifiedRepoProvider) Forget(ctx context.Context, snapshotID string, p udmrepo.WithPassword(urp, param), udmrepo.WithConfigFile(urp.workPath, string(param.BackupRepo.UID)), udmrepo.WithDescription(repoOpDescForget), + udmrepo.WithFullMaintenanceInterval(param.FullMaintenanceInterval), ) if err != nil { @@ -328,6 +334,7 @@ func (urp *unifiedRepoProvider) BatchForget(ctx context.Context, snapshotIDs []s udmrepo.WithPassword(urp, param), udmrepo.WithConfigFile(urp.workPath, string(param.BackupRepo.UID)), udmrepo.WithDescription(repoOpDescForget), + udmrepo.WithFullMaintenanceInterval(param.FullMaintenanceInterval), ) if err != nil { diff --git a/pkg/repository/udmrepo/kopialib/lib_repo.go b/pkg/repository/udmrepo/kopialib/lib_repo.go index d4e1f88133..6755990b5f 100644 --- a/pkg/repository/udmrepo/kopialib/lib_repo.go +++ b/pkg/repository/udmrepo/kopialib/lib_repo.go @@ -79,6 +79,8 @@ const ( defaultMaintainCheckPeriod = time.Hour overwriteFullMaintainInterval = time.Duration(0) overwriteQuickMaintainInterval = time.Duration(0) + eagerGCFullInterval = time.Duration(12) + eagerGCQuickInterval = time.Duration(6) ) var kopiaRepoOpen = repo.Open @@ -600,7 +602,14 @@ func writeInitParameters(ctx context.Context, repoOption udmrepo.RepoOptions, lo logger.Infof("Quick maintenance interval change from %v to %v", p.QuickCycle.Interval, overwriteQuickMaintainInterval) p.QuickCycle.Interval = overwriteQuickMaintainInterval } - + if repoOption.FullMaintenanceInterval == udmrepo.FastGC { + logger.Infof("Full maintenance interval change from %v to %v", p.FullCycle.Interval, udmrepo.FastGCInterval) + p.FullCycle.Interval = udmrepo.FastGCInterval + } + if repoOption.FullMaintenanceInterval == udmrepo.EagerGC { + logger.Infof("Full maintenance interval change from %v to %v", p.FullCycle.Interval, udmrepo.EagerGCInterval) + p.FullCycle.Interval = udmrepo.EagerGCInterval + } p.Owner = r.ClientOptions().UsernameAtHost() if err := maintenance.SetParams(ctx, w, &p); err != nil { diff --git a/pkg/repository/udmrepo/repo_options.go b/pkg/repository/udmrepo/repo_options.go index 28eadfdb9b..3c96dc8c3c 100644 --- a/pkg/repository/udmrepo/repo_options.go +++ b/pkg/repository/udmrepo/repo_options.go @@ -20,6 +20,7 @@ import ( "os" "path/filepath" "strings" + "time" ) const ( @@ -65,13 +66,19 @@ const ( StoreOptionCacheLimit = "cacheLimitMB" - ThrottleOptionReadOps = "readOPS" - ThrottleOptionWriteOps = "writeOPS" - ThrottleOptionListOps = "listOPS" - ThrottleOptionUploadBytes = "uploadBytes" - ThrottleOptionDownloadBytes = "downloadBytes" + ThrottleOptionReadOps = "readOPS" + ThrottleOptionWriteOps = "writeOPS" + ThrottleOptionListOps = "listOPS" + ThrottleOptionUploadBytes = "uploadBytes" + ThrottleOptionDownloadBytes = "downloadBytes" + FastGC FullMaintenanceIntervalOptions = "fastGC" + FastGCInterval time.Duration = 12 * time.Hour + EagerGC FullMaintenanceIntervalOptions = "eagerGC" + EagerGCInterval time.Duration = 6 * time.Hour ) +type FullMaintenanceIntervalOptions string + const ( defaultUsername = "default" defaultDomain = "default" @@ -88,6 +95,9 @@ type RepoOptions struct { GeneralOptions map[string]string // StorageOptions takes storage specific options StorageOptions map[string]string + // FullMaintenanceInterval will overwrite kopia maintenance interval + // options are fastGC for 12 hours, eagerGC for 6 hours + FullMaintenanceInterval FullMaintenanceIntervalOptions // Description is a description of the backup repository/backup repository operation. // It is for logging/debugging purpose only and doesn't control any behavior of the backup repository. @@ -156,6 +166,14 @@ func WithGenOptions(genOptions map[string]string) func(*RepoOptions) error { } } +// WithFullMaintenanceInterval +func WithFullMaintenanceInterval(interval FullMaintenanceIntervalOptions) func(*RepoOptions) error { + return func(options *RepoOptions) error { + options.FullMaintenanceInterval = interval + return nil + } +} + // WithStoreOptions sets the StorageOptions to RepoOptions, the store options are acquired through // the provided interface func WithStoreOptions(getter StoreOptionsGetter, param interface{}) func(*RepoOptions) error { diff --git a/site/content/docs/main/repository-maintenance.md b/site/content/docs/main/repository-maintenance.md index 8c712a9d7c..5544b7821f 100644 --- a/site/content/docs/main/repository-maintenance.md +++ b/site/content/docs/main/repository-maintenance.md @@ -130,8 +130,23 @@ velero install --default-repo-maintain-frequency ``` For Kopia the default maintenance frequency is 1 hour, and Restic is 7 * 24 hours. +### Full Maintenance Interval customization +The full maintenance interval defaults to kopia defaults of 24 hours. Velero provide two override options under `fullMaintenanceInterval` configuration. +- fastGC: 12 hours +- eagerGC: 6 hours + +Example of the ```repo-maintenance-job-configmap``` ConfigMap for the above scenario is as below: +```bash +cat < repo-maintenance-job-config.json +{ + "global": { + fullMaintenanceInterval: "fastGC" + } +} +``` + ### Others Maintenance jobs will inherit the labels, annotations, toleration, nodeSelector, service account, image, environment variables, cloud-credentials etc. from Velero deployment. [1]: velero-install.md#usage -[2]: node-agent-concurrency.md \ No newline at end of file +[2]: node-agent-concurrency.md