Skip to content

Commit d2c6b6b

Browse files
Add support for configuring VGS label key (#8938)
add changelog file Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>
1 parent 681a874 commit d2c6b6b

File tree

10 files changed

+98
-2
lines changed

10 files changed

+98
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add support for configuring VGS label key

config/crd/v1/bases/velero.io_backups.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ spec:
507507
uploads to perform when using the uploader.
508508
type: integer
509509
type: object
510+
volumeGroupSnapshotLabelKey:
511+
description: VolumeGroupSnapshotLabelKey specifies the label key to
512+
group PVCs under a VGS.
513+
type: string
510514
volumeSnapshotLocations:
511515
description: VolumeSnapshotLocations is a list containing names of
512516
VolumeSnapshotLocations associated with this backup.

config/crd/v1/bases/velero.io_schedules.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ spec:
549549
uploads to perform when using the uploader.
550550
type: integer
551551
type: object
552+
volumeGroupSnapshotLabelKey:
553+
description: VolumeGroupSnapshotLabelKey specifies the label key
554+
to group PVCs under a VGS.
555+
type: string
552556
volumeSnapshotLocations:
553557
description: VolumeSnapshotLocations is a list containing names
554558
of VolumeSnapshotLocations associated with this backup.

config/crd/v1/crds/crds.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/velero/v1/backup_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ type BackupSpec struct {
113113
// +optional
114114
TTL metav1.Duration `json:"ttl,omitempty"`
115115

116+
// VolumeGroupSnapshotLabelKey specifies the label key to group PVCs under a VGS.
117+
// +optional
118+
VolumeGroupSnapshotLabelKey string `json:"volumeGroupSnapshotLabelKey,omitempty"`
119+
116120
// IncludeClusterResources specifies whether cluster-scoped resources
117121
// should be included for consideration in the backup.
118122
// +optional

pkg/builder/backup_builder.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ func (b *BackupBuilder) TTL(ttl time.Duration) *BackupBuilder {
240240
return b
241241
}
242242

243+
// VolumeGroupSnapshotLabelKey sets the label key to group PVCs for VolumeGroupSnapshot.
244+
func (b *BackupBuilder) VolumeGroupSnapshotLabelKey(labelKey string) *BackupBuilder {
245+
b.object.Spec.VolumeGroupSnapshotLabelKey = labelKey
246+
return b
247+
}
248+
243249
// Expiration sets the Backup's expiration.
244250
func (b *BackupBuilder) Expiration(val time.Time) *BackupBuilder {
245251
b.object.Status.Expiration = &metav1.Time{Time: val}

pkg/cmd/server/config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ const (
3636
// the default TTL for a backup
3737
defaultBackupTTL = 30 * 24 * time.Hour
3838

39+
// defaultVGSLabelKey is the default label key used to group PVCs under a VolumeGroupSnapshot
40+
defaultVGSLabelKey = "velero.io/volume-group-snapshot"
41+
3942
defaultCSISnapshotTimeout = 10 * time.Minute
4043
defaultItemOperationTimeout = 4 * time.Hour
4144

@@ -153,6 +156,7 @@ type Config struct {
153156
PodVolumeOperationTimeout time.Duration
154157
ResourceTerminatingTimeout time.Duration
155158
DefaultBackupTTL time.Duration
159+
DefaultVGSLabelKey string
156160
StoreValidationFrequency time.Duration
157161
DefaultCSISnapshotTimeout time.Duration
158162
DefaultItemOperationTimeout time.Duration
@@ -192,6 +196,7 @@ func GetDefaultConfig() *Config {
192196
DefaultVolumeSnapshotLocations: flag.NewMap().WithKeyValueDelimiter(':'),
193197
BackupSyncPeriod: defaultBackupSyncPeriod,
194198
DefaultBackupTTL: defaultBackupTTL,
199+
DefaultVGSLabelKey: defaultVGSLabelKey,
195200
DefaultCSISnapshotTimeout: defaultCSISnapshotTimeout,
196201
DefaultItemOperationTimeout: defaultItemOperationTimeout,
197202
ResourceTimeout: resourceTimeout,
@@ -243,6 +248,7 @@ func (c *Config) BindFlags(flags *pflag.FlagSet) {
243248
flags.StringVar(&c.ProfilerAddress, "profiler-address", c.ProfilerAddress, "The address to expose the pprof profiler.")
244249
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.")
245250
flags.DurationVar(&c.DefaultBackupTTL, "default-backup-ttl", c.DefaultBackupTTL, "How long to wait by default before backups can be garbage collected.")
251+
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'")
246252
flags.DurationVar(&c.RepoMaintenanceFrequency, "default-repo-maintain-frequency", c.RepoMaintenanceFrequency, "How often 'maintain' is run for backup repositories by default.")
247253
flags.DurationVar(&c.GarbageCollectionFrequency, "garbage-collection-frequency", c.GarbageCollectionFrequency, "How often garbage collection is run for expired backups.")
248254
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")

pkg/cmd/server/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
634634
s.config.DefaultBackupLocation,
635635
s.config.DefaultVolumesToFsBackup,
636636
s.config.DefaultBackupTTL,
637+
s.config.DefaultVGSLabelKey,
637638
s.config.DefaultCSISnapshotTimeout,
638639
s.config.ResourceTimeout,
639640
s.config.DefaultItemOperationTimeout,

pkg/controller/backup_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type backupReconciler struct {
7575
defaultBackupLocation string
7676
defaultVolumesToFsBackup bool
7777
defaultBackupTTL time.Duration
78+
defaultVGSLabelKey string
7879
defaultCSISnapshotTimeout time.Duration
7980
resourceTimeout time.Duration
8081
defaultItemOperationTimeout time.Duration
@@ -102,6 +103,7 @@ func NewBackupReconciler(
102103
defaultBackupLocation string,
103104
defaultVolumesToFsBackup bool,
104105
defaultBackupTTL time.Duration,
106+
defaultVGSLabelKey string,
105107
defaultCSISnapshotTimeout time.Duration,
106108
resourceTimeout time.Duration,
107109
defaultItemOperationTimeout time.Duration,
@@ -128,6 +130,7 @@ func NewBackupReconciler(
128130
defaultBackupLocation: defaultBackupLocation,
129131
defaultVolumesToFsBackup: defaultVolumesToFsBackup,
130132
defaultBackupTTL: defaultBackupTTL,
133+
defaultVGSLabelKey: defaultVGSLabelKey,
131134
defaultCSISnapshotTimeout: defaultCSISnapshotTimeout,
132135
resourceTimeout: resourceTimeout,
133136
defaultItemOperationTimeout: defaultItemOperationTimeout,
@@ -347,6 +350,10 @@ func (b *backupReconciler) prepareBackupRequest(backup *velerov1api.Backup, logg
347350
request.Spec.TTL.Duration = b.defaultBackupTTL
348351
}
349352

353+
if len(request.Spec.VolumeGroupSnapshotLabelKey) == 0 {
354+
request.Spec.VolumeGroupSnapshotLabelKey = b.defaultVGSLabelKey
355+
}
356+
350357
if request.Spec.CSISnapshotTimeout.Duration == 0 {
351358
// set default CSI VolumeSnapshot timeout
352359
request.Spec.CSISnapshotTimeout.Duration = b.defaultCSISnapshotTimeout

pkg/controller/backup_controller_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,69 @@ func TestDefaultBackupTTL(t *testing.T) {
479479
}
480480
}
481481

482+
func TestPrepareBackupRequest_SetsVGSLabelKey(t *testing.T) {
483+
now, err := time.Parse(time.RFC1123Z, time.RFC1123Z)
484+
require.NoError(t, err)
485+
now = now.Local()
486+
487+
defaultVGSLabelKey := "velero.io/volume-group-snapshot"
488+
489+
tests := []struct {
490+
name string
491+
backup *velerov1api.Backup
492+
serverFlagKey string
493+
expectedLabelKey string
494+
}{
495+
{
496+
name: "backup with spec label key set",
497+
backup: builder.ForBackup("velero", "backup-1").
498+
VolumeGroupSnapshotLabelKey("spec-key").
499+
Result(),
500+
serverFlagKey: "server-key",
501+
expectedLabelKey: "spec-key",
502+
},
503+
{
504+
name: "backup with no spec key, uses server flag",
505+
backup: builder.ForBackup("velero", "backup-2").Result(),
506+
serverFlagKey: "server-key",
507+
expectedLabelKey: "server-key",
508+
},
509+
{
510+
name: "backup with no spec or server flag, uses default",
511+
backup: builder.ForBackup("velero", "backup-3").Result(),
512+
serverFlagKey: defaultVGSLabelKey,
513+
expectedLabelKey: defaultVGSLabelKey,
514+
},
515+
}
516+
517+
for _, test := range tests {
518+
formatFlag := logging.FormatText
519+
logger := logging.DefaultLogger(logrus.DebugLevel, formatFlag)
520+
521+
t.Run(test.name, func(t *testing.T) {
522+
fakeClient := velerotest.NewFakeControllerRuntimeClient(t, test.backup)
523+
apiServer := velerotest.NewAPIServer(t)
524+
discoveryHelper, err := discovery.NewHelper(apiServer.DiscoveryClient, logger)
525+
require.NoError(t, err)
526+
527+
c := &backupReconciler{
528+
logger: logger,
529+
kbClient: fakeClient,
530+
defaultVGSLabelKey: test.serverFlagKey,
531+
discoveryHelper: discoveryHelper,
532+
clock: testclocks.NewFakeClock(now),
533+
workerPool: pkgbackup.StartItemBlockWorkerPool(context.Background(), 1, logger),
534+
}
535+
defer c.workerPool.Stop()
536+
537+
res := c.prepareBackupRequest(test.backup, logger)
538+
assert.NotNil(t, res)
539+
540+
assert.Equal(t, test.expectedLabelKey, res.Spec.VolumeGroupSnapshotLabelKey)
541+
})
542+
}
543+
}
544+
482545
func TestDefaultVolumesToResticDeprecation(t *testing.T) {
483546
tests := []struct {
484547
name string

0 commit comments

Comments
 (0)