diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index 766c8e732..a99e650e8 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -242,10 +242,6 @@ func (kb *kubernetesBackupper) Backup(log logrus.FieldLogger, backupRequest *Req backupRequest.ResourceIncludesExcludes = getResourceIncludesExcludes(kb.discoveryHelper, backupRequest.Spec.IncludedResources, backupRequest.Spec.ExcludedResources) log.Infof("Including resources: %s", backupRequest.ResourceIncludesExcludes.IncludesString()) log.Infof("Excluding resources: %s", backupRequest.ResourceIncludesExcludes.ExcludesString()) - - if backupRequest.Backup.Spec.DefaultVolumesToRestic == nil { - backupRequest.Backup.Spec.DefaultVolumesToRestic = &kb.defaultVolumesToRestic - } log.Infof("Backing up all pod volumes using restic: %t", *backupRequest.Backup.Spec.DefaultVolumesToRestic) var err error diff --git a/pkg/backup/backup_test.go b/pkg/backup/backup_test.go index 5d9f5c8b2..df9b8c7cd 100644 --- a/pkg/backup/backup_test.go +++ b/pkg/backup/backup_test.go @@ -2752,7 +2752,7 @@ func newSnapshotLocation(ns, name, provider string) *velerov1.VolumeSnapshotLoca } func defaultBackup() *builder.BackupBuilder { - return builder.ForBackup(velerov1.DefaultNamespace, "backup-1") + return builder.ForBackup(velerov1.DefaultNamespace, "backup-1").DefaultVolumesToRestic(false) } func toUnstructuredOrFail(t *testing.T, obj interface{}) map[string]interface{} { diff --git a/pkg/controller/backup_controller_test.go b/pkg/controller/backup_controller_test.go index 7aa3a1ef0..43e479812 100644 --- a/pkg/controller/backup_controller_test.go +++ b/pkg/controller/backup_controller_test.go @@ -610,6 +610,82 @@ func TestProcessBackupCompletions(t *testing.T) { }, }, }, + { + name: "backup specifying no value for 'DefaultVolumesToRestic' gets the default true value", + backupExists: false, + backup: defaultBackup().Result(), + backupLocation: defaultBackupLocation, + // value set in the controller is different from that specified in the backup + defaultVolumesToRestic: true, + expectedResult: &velerov1api.Backup{ + TypeMeta: metav1.TypeMeta{ + Kind: "Backup", + APIVersion: "velero.io/v1", + }, + ObjectMeta: metav1.ObjectMeta{ + Namespace: velerov1api.DefaultNamespace, + Name: "backup-1", + Annotations: map[string]string{ + "velero.io/source-cluster-k8s-major-version": "1", + "velero.io/source-cluster-k8s-minor-version": "16", + "velero.io/source-cluster-k8s-gitversion": "v1.16.4", + }, + Labels: map[string]string{ + "velero.io/storage-location": "loc-1", + }, + }, + Spec: velerov1api.BackupSpec{ + StorageLocation: defaultBackupLocation.Name, + DefaultVolumesToRestic: boolptr.True(), + }, + Status: velerov1api.BackupStatus{ + Phase: velerov1api.BackupPhaseCompleted, + Version: 1, + FormatVersion: "1.1.0", + StartTimestamp: ×tamp, + CompletionTimestamp: ×tamp, + Expiration: ×tamp, + }, + }, + }, + { + name: "backup specifying no value for 'DefaultVolumesToRestic' gets the default false value", + backupExists: false, + backup: defaultBackup().Result(), + backupLocation: defaultBackupLocation, + // value set in the controller is different from that specified in the backup + defaultVolumesToRestic: false, + expectedResult: &velerov1api.Backup{ + TypeMeta: metav1.TypeMeta{ + Kind: "Backup", + APIVersion: "velero.io/v1", + }, + ObjectMeta: metav1.ObjectMeta{ + Namespace: velerov1api.DefaultNamespace, + Name: "backup-1", + Annotations: map[string]string{ + "velero.io/source-cluster-k8s-major-version": "1", + "velero.io/source-cluster-k8s-minor-version": "16", + "velero.io/source-cluster-k8s-gitversion": "v1.16.4", + }, + Labels: map[string]string{ + "velero.io/storage-location": "loc-1", + }, + }, + Spec: velerov1api.BackupSpec{ + StorageLocation: defaultBackupLocation.Name, + DefaultVolumesToRestic: boolptr.False(), + }, + Status: velerov1api.BackupStatus{ + Phase: velerov1api.BackupPhaseCompleted, + Version: 1, + FormatVersion: "1.1.0", + StartTimestamp: ×tamp, + CompletionTimestamp: ×tamp, + Expiration: ×tamp, + }, + }, + }, // Failed {