Skip to content

Commit

Permalink
Configurable Kopia Maintenance Interval
Browse files Browse the repository at this point in the history
Signed-off-by: Tiger Kaovilai <[email protected]>
  • Loading branch information
kaovilai committed Jan 15, 2025
1 parent 3eaa739 commit bcc6e39
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
2 changes: 2 additions & 0 deletions pkg/repository/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -48,6 +49,7 @@ type JobConfigs struct {

// PodResources is the config for the CPU and memory resources setting.
PodResources *kube.PodResources `json:"podResources,omitempty"`
FullMaintenanceInterval udmrepo.FullMaintenanceIntervalOptions `json:"fullMaintenanceInterval,omitempty"`
}

func GenerateJobName(repo string) string {
Expand Down
11 changes: 10 additions & 1 deletion pkg/repository/udmrepo/kopialib/lib_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 23 additions & 5 deletions pkg/repository/udmrepo/repo_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
)

const (
Expand Down Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 16 additions & 1 deletion site/content/docs/main/repository-maintenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,23 @@ velero install --default-repo-maintain-frequency <DURATION>
```
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 <<EOF > 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
[2]: node-agent-concurrency.md

0 comments on commit bcc6e39

Please sign in to comment.