Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/8938-shubham-pampattiwar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for configuring VGS label key
4 changes: 4 additions & 0 deletions config/crd/v1/bases/velero.io_backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ spec:
uploads to perform when using the uploader.
type: integer
type: object
volumeGroupSnapshotLabelKey:
description: VolumeGroupSnapshotLabelKey specifies the label key to
group PVCs under a VGS.
type: string
volumeSnapshotLocations:
description: VolumeSnapshotLocations is a list containing names of
VolumeSnapshotLocations associated with this backup.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/v1/bases/velero.io_schedules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,10 @@ spec:
uploads to perform when using the uploader.
type: integer
type: object
volumeGroupSnapshotLabelKey:
description: VolumeGroupSnapshotLabelKey specifies the label key
to group PVCs under a VGS.
type: string
volumeSnapshotLocations:
description: VolumeSnapshotLocations is a list containing names
of VolumeSnapshotLocations associated with this backup.
Expand Down
4 changes: 2 additions & 2 deletions config/crd/v1/crds/crds.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pkg/apis/velero/v1/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ type BackupSpec struct {
// +optional
TTL metav1.Duration `json:"ttl,omitempty"`

// VolumeGroupSnapshotLabelKey specifies the label key to group PVCs under a VGS.
// +optional
VolumeGroupSnapshotLabelKey string `json:"volumeGroupSnapshotLabelKey,omitempty"`

// IncludeClusterResources specifies whether cluster-scoped resources
// should be included for consideration in the backup.
// +optional
Expand Down
6 changes: 6 additions & 0 deletions pkg/builder/backup_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ func (b *BackupBuilder) TTL(ttl time.Duration) *BackupBuilder {
return b
}

// VolumeGroupSnapshotLabelKey sets the label key to group PVCs for VolumeGroupSnapshot.
func (b *BackupBuilder) VolumeGroupSnapshotLabelKey(labelKey string) *BackupBuilder {
b.object.Spec.VolumeGroupSnapshotLabelKey = labelKey
return b
}

// Expiration sets the Backup's expiration.
func (b *BackupBuilder) Expiration(val time.Time) *BackupBuilder {
b.object.Status.Expiration = &metav1.Time{Time: val}
Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const (
// the default TTL for a backup
defaultBackupTTL = 30 * 24 * time.Hour

// defaultVGSLabelKey is the default label key used to group PVCs under a VolumeGroupSnapshot
defaultVGSLabelKey = "velero.io/volume-group-snapshot"

defaultCSISnapshotTimeout = 10 * time.Minute
defaultItemOperationTimeout = 4 * time.Hour

Expand Down Expand Up @@ -153,6 +156,7 @@ type Config struct {
PodVolumeOperationTimeout time.Duration
ResourceTerminatingTimeout time.Duration
DefaultBackupTTL time.Duration
DefaultVGSLabelKey string
StoreValidationFrequency time.Duration
DefaultCSISnapshotTimeout time.Duration
DefaultItemOperationTimeout time.Duration
Expand Down Expand Up @@ -192,6 +196,7 @@ func GetDefaultConfig() *Config {
DefaultVolumeSnapshotLocations: flag.NewMap().WithKeyValueDelimiter(':'),
BackupSyncPeriod: defaultBackupSyncPeriod,
DefaultBackupTTL: defaultBackupTTL,
DefaultVGSLabelKey: defaultVGSLabelKey,
DefaultCSISnapshotTimeout: defaultCSISnapshotTimeout,
DefaultItemOperationTimeout: defaultItemOperationTimeout,
ResourceTimeout: resourceTimeout,
Expand Down Expand Up @@ -243,6 +248,7 @@ func (c *Config) BindFlags(flags *pflag.FlagSet) {
flags.StringVar(&c.ProfilerAddress, "profiler-address", c.ProfilerAddress, "The address to expose the pprof profiler.")
flags.DurationVar(&c.ResourceTerminatingTimeout, "terminating-resource-timeout", c.ResourceTerminatingTimeout, "How long to wait on persistent volumes and namespaces to terminate during a restore before timing out.")
flags.DurationVar(&c.DefaultBackupTTL, "default-backup-ttl", c.DefaultBackupTTL, "How long to wait by default before backups can be garbage collected.")
flags.StringVar(&c.DefaultVGSLabelKey, "volume-group-snapshot-label-key", c.DefaultVGSLabelKey, "Label key for grouping PVCs into VolumeGroupSnapshot. Default value is 'velero.io/volume-group-snapshot'")
flags.DurationVar(&c.RepoMaintenanceFrequency, "default-repo-maintain-frequency", c.RepoMaintenanceFrequency, "How often 'maintain' is run for backup repositories by default.")
flags.DurationVar(&c.GarbageCollectionFrequency, "garbage-collection-frequency", c.GarbageCollectionFrequency, "How often garbage collection is run for expired backups.")
flags.DurationVar(&c.ItemOperationSyncFrequency, "item-operation-sync-frequency", c.ItemOperationSyncFrequency, "How often to check status on backup/restore operations after backup/restore processing. Default is 10 seconds")
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@
s.config.DefaultBackupLocation,
s.config.DefaultVolumesToFsBackup,
s.config.DefaultBackupTTL,
s.config.DefaultVGSLabelKey,

Check warning on line 637 in pkg/cmd/server/server.go

View check run for this annotation

Codecov / codecov/patch

pkg/cmd/server/server.go#L637

Added line #L637 was not covered by tests
s.config.DefaultCSISnapshotTimeout,
s.config.ResourceTimeout,
s.config.DefaultItemOperationTimeout,
Expand Down
7 changes: 7 additions & 0 deletions pkg/controller/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
defaultBackupLocation string
defaultVolumesToFsBackup bool
defaultBackupTTL time.Duration
defaultVGSLabelKey string
defaultCSISnapshotTimeout time.Duration
resourceTimeout time.Duration
defaultItemOperationTimeout time.Duration
Expand Down Expand Up @@ -102,6 +103,7 @@
defaultBackupLocation string,
defaultVolumesToFsBackup bool,
defaultBackupTTL time.Duration,
defaultVGSLabelKey string,
defaultCSISnapshotTimeout time.Duration,
resourceTimeout time.Duration,
defaultItemOperationTimeout time.Duration,
Expand All @@ -128,6 +130,7 @@
defaultBackupLocation: defaultBackupLocation,
defaultVolumesToFsBackup: defaultVolumesToFsBackup,
defaultBackupTTL: defaultBackupTTL,
defaultVGSLabelKey: defaultVGSLabelKey,

Check warning on line 133 in pkg/controller/backup_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_controller.go#L133

Added line #L133 was not covered by tests
defaultCSISnapshotTimeout: defaultCSISnapshotTimeout,
resourceTimeout: resourceTimeout,
defaultItemOperationTimeout: defaultItemOperationTimeout,
Expand Down Expand Up @@ -347,6 +350,10 @@
request.Spec.TTL.Duration = b.defaultBackupTTL
}

if len(request.Spec.VolumeGroupSnapshotLabelKey) == 0 {
request.Spec.VolumeGroupSnapshotLabelKey = b.defaultVGSLabelKey
}

if request.Spec.CSISnapshotTimeout.Duration == 0 {
// set default CSI VolumeSnapshot timeout
request.Spec.CSISnapshotTimeout.Duration = b.defaultCSISnapshotTimeout
Expand Down
63 changes: 63 additions & 0 deletions pkg/controller/backup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,69 @@ func TestDefaultBackupTTL(t *testing.T) {
}
}

func TestPrepareBackupRequest_SetsVGSLabelKey(t *testing.T) {
now, err := time.Parse(time.RFC1123Z, time.RFC1123Z)
require.NoError(t, err)
now = now.Local()

defaultVGSLabelKey := "velero.io/volume-group-snapshot"

tests := []struct {
name string
backup *velerov1api.Backup
serverFlagKey string
expectedLabelKey string
}{
{
name: "backup with spec label key set",
backup: builder.ForBackup("velero", "backup-1").
VolumeGroupSnapshotLabelKey("spec-key").
Result(),
serverFlagKey: "server-key",
expectedLabelKey: "spec-key",
},
{
name: "backup with no spec key, uses server flag",
backup: builder.ForBackup("velero", "backup-2").Result(),
serverFlagKey: "server-key",
expectedLabelKey: "server-key",
},
{
name: "backup with no spec or server flag, uses default",
backup: builder.ForBackup("velero", "backup-3").Result(),
serverFlagKey: defaultVGSLabelKey,
expectedLabelKey: defaultVGSLabelKey,
},
}

for _, test := range tests {
formatFlag := logging.FormatText
logger := logging.DefaultLogger(logrus.DebugLevel, formatFlag)

t.Run(test.name, func(t *testing.T) {
fakeClient := velerotest.NewFakeControllerRuntimeClient(t, test.backup)
apiServer := velerotest.NewAPIServer(t)
discoveryHelper, err := discovery.NewHelper(apiServer.DiscoveryClient, logger)
require.NoError(t, err)

c := &backupReconciler{
logger: logger,
kbClient: fakeClient,
defaultVGSLabelKey: test.serverFlagKey,
discoveryHelper: discoveryHelper,
clock: testclocks.NewFakeClock(now),
workerPool: pkgbackup.StartItemBlockWorkerPool(context.Background(), 1, logger),
}
defer c.workerPool.Stop()

res := c.prepareBackupRequest(test.backup, logger)
assert.NotNil(t, res)

assert.Equal(t, test.expectedLabelKey, res.Spec.VolumeGroupSnapshotLabelKey)
})
}
}

func TestDefaultVolumesToResticDeprecation(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading