Skip to content

Commit

Permalink
OADP-1151: Provide an option to set volsync replicationsource prune i…
Browse files Browse the repository at this point in the history
…nterval (#896)

* OADP-1151: Provide an option to set volsync replicationsource prune interval

* rebase fixes
  • Loading branch information
shubham-pampattiwar committed Feb 6, 2023
1 parent 0264a37 commit 110b33a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/oadp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ type DataMover struct {
// the number of batched volumeSnapshotRestores that can be inProgress at once, default value is 10
// +optional
MaxConcurrentRestoreVolumes string `json:"maxConcurrentRestoreVolumes,omitempty"`
// defines how often (in days) to prune the datamover snapshots from the repository
// +optional
PruneInterval string `json:"pruneInterval,omitempty"`
}

// Features defines the configuration for the DPA to enable the tech preview features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ spec:
maxConcurrentRestoreVolumes:
description: the number of batched volumeSnapshotRestores that can be inProgress at once, default value is 10
type: string
pruneInterval:
description: defines how often (in days) to prune the datamover snapshots from the repository
type: string
timeout:
description: User supplied timeout to be used for VolumeSnapshotBackup and VolumeSnapshotRestore to complete, default value is 10m
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ spec:
maxConcurrentRestoreVolumes:
description: the number of batched volumeSnapshotRestores that can be inProgress at once, default value is 10
type: string
pruneInterval:
description: defines how often (in days) to prune the datamover snapshots from the repository
type: string
timeout:
description: User supplied timeout to be used for VolumeSnapshotBackup and VolumeSnapshotRestore to complete, default value is 10m
type: string
Expand Down
56 changes: 36 additions & 20 deletions controllers/datamover.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
)

const (
ResticPassword = "RESTIC_PASSWORD"
ResticRepository = "RESTIC_REPOSITORY"
ResticsecretName = "dm-credential"
ResticPassword = "RESTIC_PASSWORD"
ResticRepository = "RESTIC_REPOSITORY"
ResticsecretName = "dm-credential"
ResticPruneInterval = "restic-prune-interval"

// batchNumbers vars
DefaultConcurrentBackupVolumes = "10"
Expand Down Expand Up @@ -321,6 +322,12 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
}
repobase = strings.TrimSuffix(repobase, "/")
repo := "s3:" + repobase + "/" + bsl.Spec.ObjectStorage.Bucket
pruneInterval := ""
if len(dpa.Spec.Features.DataMover.PruneInterval) > 0 {
pruneInterval = dpa.Spec.Features.DataMover.PruneInterval
pruneInterval = strings.ReplaceAll(pruneInterval, `"`,"")
pruneInterval = strings.ReplaceAll(pruneInterval, `'`,"")
}
rsecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-volsync-restic", bsl.Name),
Expand All @@ -340,7 +347,7 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
return err
}

return r.buildDataMoverResticSecretForAWS(rsecret, key, secret, bsl.Spec.Config[Region], pass, repo)
return r.buildDataMoverResticSecretForAWS(rsecret, key, secret, bsl.Spec.Config[Region], pass, repo, pruneInterval)
})

if err != nil {
Expand Down Expand Up @@ -387,7 +394,10 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti

// lets construct the repo URL
repo := "azure:" + bsl.Spec.ObjectStorage.Bucket + ":"

pruneInterval := ""
if len(dpa.Spec.Features.DataMover.PruneInterval) > 0 {
pruneInterval = dpa.Spec.Features.DataMover.PruneInterval
}
// We are done with checks no lets create the azure dm secret
rsecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -408,7 +418,7 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
return err
}

return r.buildDataMoverResticSecretForAzure(rsecret, accountName, accountKey, pass, repo)
return r.buildDataMoverResticSecretForAzure(rsecret, accountName, accountKey, pass, repo, pruneInterval)
})

if err != nil {
Expand Down Expand Up @@ -440,7 +450,10 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti

// let's construct the repo URL
repo := "gs:" + bsl.Spec.ObjectStorage.Bucket + ":"

pruneInterval := ""
if len(dpa.Spec.Features.DataMover.PruneInterval) > 0 {
pruneInterval = dpa.Spec.Features.DataMover.PruneInterval
}
// We are done with checks no lets create the gcp dm secret
rsecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -461,7 +474,7 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
return err
}

return r.buildDataMoverResticSecretForGCP(rsecret, gcpcreds.googleApplicationCredentials, pass, repo)
return r.buildDataMoverResticSecretForGCP(rsecret, gcpcreds.googleApplicationCredentials, pass, repo, pruneInterval)
})

if err != nil {
Expand All @@ -482,45 +495,48 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
}

//build data mover restic secret for given aws bsl
func (r *DPAReconciler) buildDataMoverResticSecretForAWS(rsecret *corev1.Secret, key string, secret string, region string, pass []byte, repo string) error {
func (r *DPAReconciler) buildDataMoverResticSecretForAWS(rsecret *corev1.Secret, key string, secret string, region string, pass []byte, repo string, pruneInterval string) error {

// TODO: add gcp, azure support
rData := &corev1.Secret{
Data: map[string][]byte{
AWSAccessKey: []byte(key),
AWSSecretKey: []byte(secret),
AWSDefaultRegion: []byte(region),
ResticPassword: pass,
ResticRepository: []byte(repo),
AWSAccessKey: []byte(key),
AWSSecretKey: []byte(secret),
AWSDefaultRegion: []byte(region),
ResticPassword: pass,
ResticRepository: []byte(repo),
ResticPruneInterval: []byte(pruneInterval),
},
}
rsecret.Data = rData.Data
return nil
}

//build data mover restic secret for given bsl
func (r *DPAReconciler) buildDataMoverResticSecretForAzure(rsecret *corev1.Secret, accountName string, accountKey string, pass []byte, repo string) error {
func (r *DPAReconciler) buildDataMoverResticSecretForAzure(rsecret *corev1.Secret, accountName string, accountKey string, pass []byte, repo string, pruneInterval string) error {

rData := &corev1.Secret{
Data: map[string][]byte{
AzureAccountName: []byte(accountName),
AzureAccountKey: []byte(accountKey),
ResticPassword: pass,
ResticRepository: []byte(repo),
AzureAccountName: []byte(accountName),
AzureAccountKey: []byte(accountKey),
ResticPassword: pass,
ResticRepository: []byte(repo),
ResticPruneInterval: []byte(pruneInterval),
},
}
rsecret.Data = rData.Data
return nil
}

//build data mover restic secret for given gcp bsl
func (r *DPAReconciler) buildDataMoverResticSecretForGCP(rsecret *corev1.Secret, googleApplicationCredentials string, pass []byte, repo string) error {
func (r *DPAReconciler) buildDataMoverResticSecretForGCP(rsecret *corev1.Secret, googleApplicationCredentials string, pass []byte, repo string, pruneInterval string) error {

rData := &corev1.Secret{
Data: map[string][]byte{
GoogleApplicationCredentials: []byte(googleApplicationCredentials),
ResticPassword: pass,
ResticRepository: []byte(repo),
ResticPruneInterval: []byte(pruneInterval),
},
}
rsecret.Data = rData.Data
Expand Down

0 comments on commit 110b33a

Please sign in to comment.