Wire default resource modifier through install path and builder

Add --default-resource-modifier-configmap to the install CLI and
deployment builder so administrators can configure it during velero
install. Wire through VeleroOptions and podTemplateConfig following
the existing --backup-repository-configmap pattern.

Add SkipDefaultResourceModifier builder method to RestoreBuilder.

Signed-off-by: Shubham Pampattiwar <spampatt@redhat.com>
This commit is contained in:
Shubham Pampattiwar
2026-08-03 13:19:47 -07:00
parent 34bc3c7e1a
commit c509e5369c
4 changed files with 201 additions and 171 deletions
+6
View File
@@ -181,3 +181,9 @@ func (b *RestoreBuilder) ResourcePoliciesConfigmap(name string) *RestoreBuilder
}
return b
}
// SkipDefaultResourceModifier sets whether to skip the server default resource modifier.
func (b *RestoreBuilder) SkipDefaultResourceModifier(val bool) *RestoreBuilder {
b.object.Spec.SkipDefaultResourceModifier = &val
return b
}
+105 -97
View File
@@ -42,60 +42,61 @@ import (
// Options collects all the options for installing Velero into a Kubernetes cluster.
type Options struct {
Namespace string
Image string
BucketName string
Prefix string
ProviderName string
PodAnnotations flag.Map
PodLabels flag.Map
ServiceAccountAnnotations flag.Map
ServiceAccountName string
VeleroPodCPURequest string
VeleroPodMemRequest string
VeleroPodCPULimit string
VeleroPodMemLimit string
NodeAgentPodCPURequest string
NodeAgentPodMemRequest string
NodeAgentPodCPULimit string
NodeAgentPodMemLimit string
RestoreOnly bool
SecretFile string
NoSecret bool
DryRun bool
BackupStorageConfig flag.Map
VolumeSnapshotConfig flag.Map
UseNodeAgent bool
UseNodeAgentWindows bool
PrivilegedNodeAgent bool
Wait bool
UseVolumeSnapshots bool
DefaultRepoMaintenanceFrequency time.Duration
GarbageCollectionFrequency time.Duration
PodVolumeOperationTimeout time.Duration
Plugins flag.StringArray
NoDefaultBackupLocation bool
CRDsOnly bool
CACertFile string
Features string
DefaultVolumesToFsBackup bool
UploaderType string
DefaultSnapshotMoveData bool
CSISnapshotEarlyFrequentPolling bool
DisableInformerCache bool
ScheduleSkipImmediately bool
PodResources kubeutil.PodResources
KeepLatestMaintenanceJobs int
BackupRepoConfigMap string
RepoMaintenanceJobConfigMap string
NodeAgentConfigMap string
ItemBlockWorkerCount int
ConcurrentBackups int
NodeAgentDisableHostPath bool
kubeletRootDir string
Apply bool
ServerPriorityClassName string
NodeAgentPriorityClassName string
Namespace string
Image string
BucketName string
Prefix string
ProviderName string
PodAnnotations flag.Map
PodLabels flag.Map
ServiceAccountAnnotations flag.Map
ServiceAccountName string
VeleroPodCPURequest string
VeleroPodMemRequest string
VeleroPodCPULimit string
VeleroPodMemLimit string
NodeAgentPodCPURequest string
NodeAgentPodMemRequest string
NodeAgentPodCPULimit string
NodeAgentPodMemLimit string
RestoreOnly bool
SecretFile string
NoSecret bool
DryRun bool
BackupStorageConfig flag.Map
VolumeSnapshotConfig flag.Map
UseNodeAgent bool
UseNodeAgentWindows bool
PrivilegedNodeAgent bool
Wait bool
UseVolumeSnapshots bool
DefaultRepoMaintenanceFrequency time.Duration
GarbageCollectionFrequency time.Duration
PodVolumeOperationTimeout time.Duration
Plugins flag.StringArray
NoDefaultBackupLocation bool
CRDsOnly bool
CACertFile string
Features string
DefaultVolumesToFsBackup bool
UploaderType string
DefaultSnapshotMoveData bool
CSISnapshotEarlyFrequentPolling bool
DisableInformerCache bool
ScheduleSkipImmediately bool
PodResources kubeutil.PodResources
KeepLatestMaintenanceJobs int
BackupRepoConfigMap string
RepoMaintenanceJobConfigMap string
DefaultResourceModifierConfigMap string
NodeAgentConfigMap string
ItemBlockWorkerCount int
ConcurrentBackups int
NodeAgentDisableHostPath bool
kubeletRootDir string
Apply bool
ServerPriorityClassName string
NodeAgentPriorityClassName string
}
// BindFlags adds command line values to the options struct.
@@ -189,6 +190,12 @@ func (o *Options) BindFlags(flags *pflag.FlagSet) {
o.RepoMaintenanceJobConfigMap,
"The name of ConfigMap containing repository maintenance Job configurations.",
)
flags.StringVar(
&o.DefaultResourceModifierConfigMap,
"default-resource-modifier-configmap",
o.DefaultResourceModifierConfigMap,
"The name of a ConfigMap in the Velero namespace containing default resource modifier rules applied to all restores.",
)
flags.StringVar(
&o.NodeAgentConfigMap,
"node-agent-configmap",
@@ -298,49 +305,50 @@ func (o *Options) AsVeleroOptions() (*install.VeleroOptions, error) {
}
return &install.VeleroOptions{
Namespace: o.Namespace,
Image: o.Image,
ProviderName: o.ProviderName,
Bucket: o.BucketName,
Prefix: o.Prefix,
PodAnnotations: o.PodAnnotations.Data(),
PodLabels: o.PodLabels.Data(),
ServiceAccountAnnotations: o.ServiceAccountAnnotations.Data(),
ServiceAccountName: o.ServiceAccountName,
VeleroPodResources: veleroPodResources,
NodeAgentPodResources: nodeAgentPodResources,
SecretData: secretData,
RestoreOnly: o.RestoreOnly,
UseNodeAgent: o.UseNodeAgent,
UseNodeAgentWindows: o.UseNodeAgentWindows,
PrivilegedNodeAgent: o.PrivilegedNodeAgent,
UseVolumeSnapshots: o.UseVolumeSnapshots,
BSLConfig: o.BackupStorageConfig.Data(),
VSLConfig: o.VolumeSnapshotConfig.Data(),
DefaultRepoMaintenanceFrequency: o.DefaultRepoMaintenanceFrequency,
GarbageCollectionFrequency: o.GarbageCollectionFrequency,
PodVolumeOperationTimeout: o.PodVolumeOperationTimeout,
Plugins: o.Plugins,
NoDefaultBackupLocation: o.NoDefaultBackupLocation,
CACertData: caCertData,
Features: strings.Split(o.Features, ","),
DefaultVolumesToFsBackup: o.DefaultVolumesToFsBackup,
UploaderType: o.UploaderType,
DefaultSnapshotMoveData: o.DefaultSnapshotMoveData,
CSISnapshotEarlyFrequentPolling: o.CSISnapshotEarlyFrequentPolling,
DisableInformerCache: o.DisableInformerCache,
ScheduleSkipImmediately: o.ScheduleSkipImmediately,
PodResources: o.PodResources,
KeepLatestMaintenanceJobs: o.KeepLatestMaintenanceJobs,
BackupRepoConfigMap: o.BackupRepoConfigMap,
RepoMaintenanceJobConfigMap: o.RepoMaintenanceJobConfigMap,
NodeAgentConfigMap: o.NodeAgentConfigMap,
ItemBlockWorkerCount: o.ItemBlockWorkerCount,
ConcurrentBackups: o.ConcurrentBackups,
KubeletRootDir: o.kubeletRootDir,
NodeAgentDisableHostPath: o.NodeAgentDisableHostPath,
ServerPriorityClassName: o.ServerPriorityClassName,
NodeAgentPriorityClassName: o.NodeAgentPriorityClassName,
Namespace: o.Namespace,
Image: o.Image,
ProviderName: o.ProviderName,
Bucket: o.BucketName,
Prefix: o.Prefix,
PodAnnotations: o.PodAnnotations.Data(),
PodLabels: o.PodLabels.Data(),
ServiceAccountAnnotations: o.ServiceAccountAnnotations.Data(),
ServiceAccountName: o.ServiceAccountName,
VeleroPodResources: veleroPodResources,
NodeAgentPodResources: nodeAgentPodResources,
SecretData: secretData,
RestoreOnly: o.RestoreOnly,
UseNodeAgent: o.UseNodeAgent,
UseNodeAgentWindows: o.UseNodeAgentWindows,
PrivilegedNodeAgent: o.PrivilegedNodeAgent,
UseVolumeSnapshots: o.UseVolumeSnapshots,
BSLConfig: o.BackupStorageConfig.Data(),
VSLConfig: o.VolumeSnapshotConfig.Data(),
DefaultRepoMaintenanceFrequency: o.DefaultRepoMaintenanceFrequency,
GarbageCollectionFrequency: o.GarbageCollectionFrequency,
PodVolumeOperationTimeout: o.PodVolumeOperationTimeout,
Plugins: o.Plugins,
NoDefaultBackupLocation: o.NoDefaultBackupLocation,
CACertData: caCertData,
Features: strings.Split(o.Features, ","),
DefaultVolumesToFsBackup: o.DefaultVolumesToFsBackup,
UploaderType: o.UploaderType,
DefaultSnapshotMoveData: o.DefaultSnapshotMoveData,
CSISnapshotEarlyFrequentPolling: o.CSISnapshotEarlyFrequentPolling,
DisableInformerCache: o.DisableInformerCache,
ScheduleSkipImmediately: o.ScheduleSkipImmediately,
PodResources: o.PodResources,
KeepLatestMaintenanceJobs: o.KeepLatestMaintenanceJobs,
BackupRepoConfigMap: o.BackupRepoConfigMap,
RepoMaintenanceJobConfigMap: o.RepoMaintenanceJobConfigMap,
DefaultResourceModifierConfigMap: o.DefaultResourceModifierConfigMap,
NodeAgentConfigMap: o.NodeAgentConfigMap,
ItemBlockWorkerCount: o.ItemBlockWorkerCount,
ConcurrentBackups: o.ConcurrentBackups,
KubeletRootDir: o.kubeletRootDir,
NodeAgentDisableHostPath: o.NodeAgentDisableHostPath,
ServerPriorityClassName: o.ServerPriorityClassName,
NodeAgentPriorityClassName: o.NodeAgentPriorityClassName,
}, nil
}
+42 -31
View File
@@ -34,37 +34,38 @@ import (
type podTemplateOption func(*podTemplateConfig)
type podTemplateConfig struct {
image string
envVars []corev1api.EnvVar
restoreOnly bool
annotations map[string]string
labels map[string]string
resources corev1api.ResourceRequirements
withSecret bool
defaultRepoMaintenanceFrequency time.Duration
garbageCollectionFrequency time.Duration
podVolumeOperationTimeout time.Duration
plugins []string
features []string
defaultVolumesToFsBackup bool
serviceAccountName string
uploaderType string
defaultSnapshotMoveData bool
csiSnapshotEarlyFrequentPolling bool
privilegedNodeAgent bool
disableInformerCache bool
scheduleSkipImmediately bool
podResources kube.PodResources
keepLatestMaintenanceJobs int
backupRepoConfigMap string
repoMaintenanceJobConfigMap string
nodeAgentConfigMap string
itemBlockWorkerCount int
concurrentBackups int
forWindows bool
kubeletRootDir string
nodeAgentDisableHostPath bool
priorityClassName string
image string
envVars []corev1api.EnvVar
restoreOnly bool
annotations map[string]string
labels map[string]string
resources corev1api.ResourceRequirements
withSecret bool
defaultRepoMaintenanceFrequency time.Duration
garbageCollectionFrequency time.Duration
podVolumeOperationTimeout time.Duration
plugins []string
features []string
defaultVolumesToFsBackup bool
serviceAccountName string
uploaderType string
defaultSnapshotMoveData bool
csiSnapshotEarlyFrequentPolling bool
privilegedNodeAgent bool
disableInformerCache bool
scheduleSkipImmediately bool
podResources kube.PodResources
keepLatestMaintenanceJobs int
backupRepoConfigMap string
repoMaintenanceJobConfigMap string
defaultResourceModifierConfigMap string
nodeAgentConfigMap string
itemBlockWorkerCount int
concurrentBackups int
forWindows bool
kubeletRootDir string
nodeAgentDisableHostPath bool
priorityClassName string
}
func WithImage(image string) podTemplateOption {
@@ -229,6 +230,12 @@ func WithRepoMaintenanceJobConfigMap(repoMaintenanceJobConfigMap string) podTemp
}
}
func WithDefaultResourceModifierConfigMap(name string) podTemplateOption {
return func(c *podTemplateConfig) {
c.defaultResourceModifierConfigMap = name
}
}
func WithItemBlockWorkerCount(itemBlockWorkerCount int) podTemplateOption {
return func(c *podTemplateConfig) {
c.itemBlockWorkerCount = itemBlockWorkerCount
@@ -350,6 +357,10 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1api.Deployme
args = append(args, fmt.Sprintf("--repo-maintenance-job-configmap=%s", c.repoMaintenanceJobConfigMap))
}
if len(c.defaultResourceModifierConfigMap) > 0 {
args = append(args, fmt.Sprintf("--default-resource-modifier-configmap=%s", c.defaultResourceModifierConfigMap))
}
if c.itemBlockWorkerCount > 0 {
args = append(args, fmt.Sprintf("--item-block-worker-count=%d", c.itemBlockWorkerCount))
}
+48 -43
View File
@@ -234,49 +234,50 @@ func appendUnstructured(list *unstructured.UnstructuredList, obj runtime.Object)
}
type VeleroOptions struct {
Namespace string
Image string
ProviderName string
Bucket string
Prefix string
PodAnnotations map[string]string
PodLabels map[string]string
ServiceAccountAnnotations map[string]string
ServiceAccountName string
VeleroPodResources corev1api.ResourceRequirements
NodeAgentPodResources corev1api.ResourceRequirements
SecretData []byte
RestoreOnly bool
UseNodeAgent bool
UseNodeAgentWindows bool
PrivilegedNodeAgent bool
UseVolumeSnapshots bool
BSLConfig map[string]string
VSLConfig map[string]string
DefaultRepoMaintenanceFrequency time.Duration
GarbageCollectionFrequency time.Duration
PodVolumeOperationTimeout time.Duration
Plugins []string
NoDefaultBackupLocation bool
CACertData []byte
Features []string
DefaultVolumesToFsBackup bool
UploaderType string
DefaultSnapshotMoveData bool
CSISnapshotEarlyFrequentPolling bool
DisableInformerCache bool
ScheduleSkipImmediately bool
PodResources kube.PodResources
KeepLatestMaintenanceJobs int
BackupRepoConfigMap string
RepoMaintenanceJobConfigMap string
NodeAgentConfigMap string
ItemBlockWorkerCount int
ConcurrentBackups int
KubeletRootDir string
NodeAgentDisableHostPath bool
ServerPriorityClassName string
NodeAgentPriorityClassName string
Namespace string
Image string
ProviderName string
Bucket string
Prefix string
PodAnnotations map[string]string
PodLabels map[string]string
ServiceAccountAnnotations map[string]string
ServiceAccountName string
VeleroPodResources corev1api.ResourceRequirements
NodeAgentPodResources corev1api.ResourceRequirements
SecretData []byte
RestoreOnly bool
UseNodeAgent bool
UseNodeAgentWindows bool
PrivilegedNodeAgent bool
UseVolumeSnapshots bool
BSLConfig map[string]string
VSLConfig map[string]string
DefaultRepoMaintenanceFrequency time.Duration
GarbageCollectionFrequency time.Duration
PodVolumeOperationTimeout time.Duration
Plugins []string
NoDefaultBackupLocation bool
CACertData []byte
Features []string
DefaultVolumesToFsBackup bool
UploaderType string
DefaultSnapshotMoveData bool
CSISnapshotEarlyFrequentPolling bool
DisableInformerCache bool
ScheduleSkipImmediately bool
PodResources kube.PodResources
KeepLatestMaintenanceJobs int
BackupRepoConfigMap string
RepoMaintenanceJobConfigMap string
DefaultResourceModifierConfigMap string
NodeAgentConfigMap string
ItemBlockWorkerCount int
ConcurrentBackups int
KubeletRootDir string
NodeAgentDisableHostPath bool
ServerPriorityClassName string
NodeAgentPriorityClassName string
}
func AllCRDs() *unstructured.UnstructuredList {
@@ -407,6 +408,10 @@ func AllResources(o *VeleroOptions) *unstructured.UnstructuredList {
deployOpts = append(deployOpts, WithRepoMaintenanceJobConfigMap(o.RepoMaintenanceJobConfigMap))
}
if len(o.DefaultResourceModifierConfigMap) > 0 {
deployOpts = append(deployOpts, WithDefaultResourceModifierConfigMap(o.DefaultResourceModifierConfigMap))
}
deploy := Deployment(o.Namespace, deployOpts...)
if err := appendUnstructured(resources, deploy); err != nil {