Add support for configuring VGS label key (#8938)
add changelog file Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>pull/7717/merge
parent
681a874298
commit
d2c6b6bc3e
|
@ -0,0 +1 @@
|
|||
Add support for configuring VGS label key
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -192,6 +196,7 @@ func GetDefaultConfig() *Config {
|
|||
DefaultVolumeSnapshotLocations: flag.NewMap().WithKeyValueDelimiter(':'),
|
||||
BackupSyncPeriod: defaultBackupSyncPeriod,
|
||||
DefaultBackupTTL: defaultBackupTTL,
|
||||
DefaultVGSLabelKey: defaultVGSLabelKey,
|
||||
DefaultCSISnapshotTimeout: defaultCSISnapshotTimeout,
|
||||
DefaultItemOperationTimeout: defaultItemOperationTimeout,
|
||||
ResourceTimeout: resourceTimeout,
|
||||
|
@ -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")
|
||||
|
|
|
@ -634,6 +634,7 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string
|
|||
s.config.DefaultBackupLocation,
|
||||
s.config.DefaultVolumesToFsBackup,
|
||||
s.config.DefaultBackupTTL,
|
||||
s.config.DefaultVGSLabelKey,
|
||||
s.config.DefaultCSISnapshotTimeout,
|
||||
s.config.ResourceTimeout,
|
||||
s.config.DefaultItemOperationTimeout,
|
||||
|
|
|
@ -75,6 +75,7 @@ type backupReconciler struct {
|
|||
defaultBackupLocation string
|
||||
defaultVolumesToFsBackup bool
|
||||
defaultBackupTTL time.Duration
|
||||
defaultVGSLabelKey string
|
||||
defaultCSISnapshotTimeout time.Duration
|
||||
resourceTimeout time.Duration
|
||||
defaultItemOperationTimeout time.Duration
|
||||
|
@ -102,6 +103,7 @@ func NewBackupReconciler(
|
|||
defaultBackupLocation string,
|
||||
defaultVolumesToFsBackup bool,
|
||||
defaultBackupTTL time.Duration,
|
||||
defaultVGSLabelKey string,
|
||||
defaultCSISnapshotTimeout time.Duration,
|
||||
resourceTimeout time.Duration,
|
||||
defaultItemOperationTimeout time.Duration,
|
||||
|
@ -128,6 +130,7 @@ func NewBackupReconciler(
|
|||
defaultBackupLocation: defaultBackupLocation,
|
||||
defaultVolumesToFsBackup: defaultVolumesToFsBackup,
|
||||
defaultBackupTTL: defaultBackupTTL,
|
||||
defaultVGSLabelKey: defaultVGSLabelKey,
|
||||
defaultCSISnapshotTimeout: defaultCSISnapshotTimeout,
|
||||
resourceTimeout: resourceTimeout,
|
||||
defaultItemOperationTimeout: defaultItemOperationTimeout,
|
||||
|
@ -347,6 +350,10 @@ func (b *backupReconciler) prepareBackupRequest(backup *velerov1api.Backup, logg
|
|||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue