Add support for configuring VGS label key (#8938)
add changelog file Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>pull/8998/head
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.
|
uploads to perform when using the uploader.
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
|
volumeGroupSnapshotLabelKey:
|
||||||
|
description: VolumeGroupSnapshotLabelKey specifies the label key to
|
||||||
|
group PVCs under a VGS.
|
||||||
|
type: string
|
||||||
volumeSnapshotLocations:
|
volumeSnapshotLocations:
|
||||||
description: VolumeSnapshotLocations is a list containing names of
|
description: VolumeSnapshotLocations is a list containing names of
|
||||||
VolumeSnapshotLocations associated with this backup.
|
VolumeSnapshotLocations associated with this backup.
|
||||||
|
|
|
@ -549,6 +549,10 @@ spec:
|
||||||
uploads to perform when using the uploader.
|
uploads to perform when using the uploader.
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
|
volumeGroupSnapshotLabelKey:
|
||||||
|
description: VolumeGroupSnapshotLabelKey specifies the label key
|
||||||
|
to group PVCs under a VGS.
|
||||||
|
type: string
|
||||||
volumeSnapshotLocations:
|
volumeSnapshotLocations:
|
||||||
description: VolumeSnapshotLocations is a list containing names
|
description: VolumeSnapshotLocations is a list containing names
|
||||||
of VolumeSnapshotLocations associated with this backup.
|
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
|
// +optional
|
||||||
TTL metav1.Duration `json:"ttl,omitempty"`
|
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
|
// IncludeClusterResources specifies whether cluster-scoped resources
|
||||||
// should be included for consideration in the backup.
|
// should be included for consideration in the backup.
|
||||||
// +optional
|
// +optional
|
||||||
|
|
|
@ -240,6 +240,12 @@ func (b *BackupBuilder) TTL(ttl time.Duration) *BackupBuilder {
|
||||||
return b
|
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.
|
// Expiration sets the Backup's expiration.
|
||||||
func (b *BackupBuilder) Expiration(val time.Time) *BackupBuilder {
|
func (b *BackupBuilder) Expiration(val time.Time) *BackupBuilder {
|
||||||
b.object.Status.Expiration = &metav1.Time{Time: val}
|
b.object.Status.Expiration = &metav1.Time{Time: val}
|
||||||
|
|
|
@ -36,6 +36,9 @@ const (
|
||||||
// the default TTL for a backup
|
// the default TTL for a backup
|
||||||
defaultBackupTTL = 30 * 24 * time.Hour
|
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
|
defaultCSISnapshotTimeout = 10 * time.Minute
|
||||||
defaultItemOperationTimeout = 4 * time.Hour
|
defaultItemOperationTimeout = 4 * time.Hour
|
||||||
|
|
||||||
|
@ -153,6 +156,7 @@ type Config struct {
|
||||||
PodVolumeOperationTimeout time.Duration
|
PodVolumeOperationTimeout time.Duration
|
||||||
ResourceTerminatingTimeout time.Duration
|
ResourceTerminatingTimeout time.Duration
|
||||||
DefaultBackupTTL time.Duration
|
DefaultBackupTTL time.Duration
|
||||||
|
DefaultVGSLabelKey string
|
||||||
StoreValidationFrequency time.Duration
|
StoreValidationFrequency time.Duration
|
||||||
DefaultCSISnapshotTimeout time.Duration
|
DefaultCSISnapshotTimeout time.Duration
|
||||||
DefaultItemOperationTimeout time.Duration
|
DefaultItemOperationTimeout time.Duration
|
||||||
|
@ -192,6 +196,7 @@ func GetDefaultConfig() *Config {
|
||||||
DefaultVolumeSnapshotLocations: flag.NewMap().WithKeyValueDelimiter(':'),
|
DefaultVolumeSnapshotLocations: flag.NewMap().WithKeyValueDelimiter(':'),
|
||||||
BackupSyncPeriod: defaultBackupSyncPeriod,
|
BackupSyncPeriod: defaultBackupSyncPeriod,
|
||||||
DefaultBackupTTL: defaultBackupTTL,
|
DefaultBackupTTL: defaultBackupTTL,
|
||||||
|
DefaultVGSLabelKey: defaultVGSLabelKey,
|
||||||
DefaultCSISnapshotTimeout: defaultCSISnapshotTimeout,
|
DefaultCSISnapshotTimeout: defaultCSISnapshotTimeout,
|
||||||
DefaultItemOperationTimeout: defaultItemOperationTimeout,
|
DefaultItemOperationTimeout: defaultItemOperationTimeout,
|
||||||
ResourceTimeout: resourceTimeout,
|
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.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.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.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.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.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")
|
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.DefaultBackupLocation,
|
||||||
s.config.DefaultVolumesToFsBackup,
|
s.config.DefaultVolumesToFsBackup,
|
||||||
s.config.DefaultBackupTTL,
|
s.config.DefaultBackupTTL,
|
||||||
|
s.config.DefaultVGSLabelKey,
|
||||||
s.config.DefaultCSISnapshotTimeout,
|
s.config.DefaultCSISnapshotTimeout,
|
||||||
s.config.ResourceTimeout,
|
s.config.ResourceTimeout,
|
||||||
s.config.DefaultItemOperationTimeout,
|
s.config.DefaultItemOperationTimeout,
|
||||||
|
|
|
@ -75,6 +75,7 @@ type backupReconciler struct {
|
||||||
defaultBackupLocation string
|
defaultBackupLocation string
|
||||||
defaultVolumesToFsBackup bool
|
defaultVolumesToFsBackup bool
|
||||||
defaultBackupTTL time.Duration
|
defaultBackupTTL time.Duration
|
||||||
|
defaultVGSLabelKey string
|
||||||
defaultCSISnapshotTimeout time.Duration
|
defaultCSISnapshotTimeout time.Duration
|
||||||
resourceTimeout time.Duration
|
resourceTimeout time.Duration
|
||||||
defaultItemOperationTimeout time.Duration
|
defaultItemOperationTimeout time.Duration
|
||||||
|
@ -102,6 +103,7 @@ func NewBackupReconciler(
|
||||||
defaultBackupLocation string,
|
defaultBackupLocation string,
|
||||||
defaultVolumesToFsBackup bool,
|
defaultVolumesToFsBackup bool,
|
||||||
defaultBackupTTL time.Duration,
|
defaultBackupTTL time.Duration,
|
||||||
|
defaultVGSLabelKey string,
|
||||||
defaultCSISnapshotTimeout time.Duration,
|
defaultCSISnapshotTimeout time.Duration,
|
||||||
resourceTimeout time.Duration,
|
resourceTimeout time.Duration,
|
||||||
defaultItemOperationTimeout time.Duration,
|
defaultItemOperationTimeout time.Duration,
|
||||||
|
@ -128,6 +130,7 @@ func NewBackupReconciler(
|
||||||
defaultBackupLocation: defaultBackupLocation,
|
defaultBackupLocation: defaultBackupLocation,
|
||||||
defaultVolumesToFsBackup: defaultVolumesToFsBackup,
|
defaultVolumesToFsBackup: defaultVolumesToFsBackup,
|
||||||
defaultBackupTTL: defaultBackupTTL,
|
defaultBackupTTL: defaultBackupTTL,
|
||||||
|
defaultVGSLabelKey: defaultVGSLabelKey,
|
||||||
defaultCSISnapshotTimeout: defaultCSISnapshotTimeout,
|
defaultCSISnapshotTimeout: defaultCSISnapshotTimeout,
|
||||||
resourceTimeout: resourceTimeout,
|
resourceTimeout: resourceTimeout,
|
||||||
defaultItemOperationTimeout: defaultItemOperationTimeout,
|
defaultItemOperationTimeout: defaultItemOperationTimeout,
|
||||||
|
@ -347,6 +350,10 @@ func (b *backupReconciler) prepareBackupRequest(backup *velerov1api.Backup, logg
|
||||||
request.Spec.TTL.Duration = b.defaultBackupTTL
|
request.Spec.TTL.Duration = b.defaultBackupTTL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(request.Spec.VolumeGroupSnapshotLabelKey) == 0 {
|
||||||
|
request.Spec.VolumeGroupSnapshotLabelKey = b.defaultVGSLabelKey
|
||||||
|
}
|
||||||
|
|
||||||
if request.Spec.CSISnapshotTimeout.Duration == 0 {
|
if request.Spec.CSISnapshotTimeout.Duration == 0 {
|
||||||
// set default CSI VolumeSnapshot timeout
|
// set default CSI VolumeSnapshot timeout
|
||||||
request.Spec.CSISnapshotTimeout.Duration = b.defaultCSISnapshotTimeout
|
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) {
|
func TestDefaultVolumesToResticDeprecation(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
Loading…
Reference in New Issue