From b2aa368d5410b5486431587fdc4d64074ba3e66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wenkai=20Yin=28=E5=B0=B9=E6=96=87=E5=BC=80=29?= Date: Mon, 8 Jan 2024 13:52:23 +0800 Subject: [PATCH] update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Wenkai Yin(尹文开) --- pkg/cmd/cli/install/install.go | 8 +++---- pkg/cmd/server/server.go | 8 +++---- pkg/controller/restore_controller.go | 26 +++++++++++------------ pkg/controller/restore_controller_test.go | 10 ++++----- pkg/install/deployment.go | 10 ++++----- pkg/install/deployment_test.go | 4 ++-- pkg/install/resources.go | 6 +++--- pkg/restore/request.go | 22 +++++++++---------- pkg/restore/restore.go | 12 +++++------ pkg/restore/restore_test.go | 22 +++++++++---------- 10 files changed, 63 insertions(+), 65 deletions(-) diff --git a/pkg/cmd/cli/install/install.go b/pkg/cmd/cli/install/install.go index cc629d472c..75b61512a1 100644 --- a/pkg/cmd/cli/install/install.go +++ b/pkg/cmd/cli/install/install.go @@ -82,7 +82,7 @@ type Options struct { DefaultVolumesToFsBackup bool UploaderType string DefaultSnapshotMoveData bool - DisableInformerCache bool + EnableInformerCache bool ScheduleSkipImmediately bool } @@ -126,7 +126,7 @@ func (o *Options) BindFlags(flags *pflag.FlagSet) { flags.BoolVar(&o.DefaultVolumesToFsBackup, "default-volumes-to-fs-backup", o.DefaultVolumesToFsBackup, "Bool flag to configure Velero server to use pod volume file system backup by default for all volumes on all backups. Optional.") flags.StringVar(&o.UploaderType, "uploader-type", o.UploaderType, fmt.Sprintf("The type of uploader to transfer the data of pod volumes, the supported values are '%s', '%s'", uploader.ResticType, uploader.KopiaType)) flags.BoolVar(&o.DefaultSnapshotMoveData, "default-snapshot-move-data", o.DefaultSnapshotMoveData, "Bool flag to configure Velero server to move data by default for all snapshots supporting data movement. Optional.") - flags.BoolVar(&o.DisableInformerCache, "disable-informer-cache", o.DisableInformerCache, "Disable informer cache for Get calls on restore. With this enabled, it will speed up restore in cases where there are backup resources which already exist in the cluster, but for very large clusters this will increase velero memory usage. Default is true (disable). Optional.") + flags.BoolVar(&o.EnableInformerCache, "enable-informer-cache", o.EnableInformerCache, "Enable informer cache for Get calls on restore. With this enabled, it will speed up restore in cases where there are backup resources which already exist in the cluster, but for very large clusters this will increase velero memory usage. Default is false (disable). Optional.") flags.BoolVar(&o.ScheduleSkipImmediately, "schedule-skip-immediately", o.ScheduleSkipImmediately, "Skip the first scheduled backup immediately after creating a schedule. Default is false (don't skip).") } @@ -155,7 +155,7 @@ func NewInstallOptions() *Options { DefaultVolumesToFsBackup: false, UploaderType: uploader.KopiaType, DefaultSnapshotMoveData: false, - DisableInformerCache: true, + EnableInformerCache: false, ScheduleSkipImmediately: false, } } @@ -222,7 +222,7 @@ func (o *Options) AsVeleroOptions() (*install.VeleroOptions, error) { DefaultVolumesToFsBackup: o.DefaultVolumesToFsBackup, UploaderType: o.UploaderType, DefaultSnapshotMoveData: o.DefaultSnapshotMoveData, - DisableInformerCache: o.DisableInformerCache, + EnableInformerCache: o.EnableInformerCache, ScheduleSkipImmediately: o.ScheduleSkipImmediately, }, nil } diff --git a/pkg/cmd/server/server.go b/pkg/cmd/server/server.go index 1b5512f295..69fc986eb3 100644 --- a/pkg/cmd/server/server.go +++ b/pkg/cmd/server/server.go @@ -107,7 +107,6 @@ const ( defaultCredentialsDirectory = "/tmp/credentials" defaultMaxConcurrentK8SConnections = 30 - defaultDisableInformerCache = true ) type serverConfig struct { @@ -132,7 +131,7 @@ type serverConfig struct { uploaderType string maxConcurrentK8SConnections int defaultSnapshotMoveData bool - disableInformerCache bool + enableInformerCache bool scheduleSkipImmediately bool } @@ -163,7 +162,6 @@ func NewCommand(f client.Factory) *cobra.Command { uploaderType: uploader.ResticType, maxConcurrentK8SConnections: defaultMaxConcurrentK8SConnections, defaultSnapshotMoveData: false, - disableInformerCache: defaultDisableInformerCache, scheduleSkipImmediately: false, } ) @@ -236,7 +234,7 @@ func NewCommand(f client.Factory) *cobra.Command { command.Flags().DurationVar(&config.resourceTimeout, "resource-timeout", config.resourceTimeout, "How long to wait for resource processes which are not covered by other specific timeout parameters. Default is 10 minutes.") command.Flags().IntVar(&config.maxConcurrentK8SConnections, "max-concurrent-k8s-connections", config.maxConcurrentK8SConnections, "Max concurrent connections number that Velero can create with kube-apiserver. Default is 30.") command.Flags().BoolVar(&config.defaultSnapshotMoveData, "default-snapshot-move-data", config.defaultSnapshotMoveData, "Move data by default for all snapshots supporting data movement.") - command.Flags().BoolVar(&config.disableInformerCache, "disable-informer-cache", config.disableInformerCache, "Disable informer cache for Get calls on restore. With this enabled, it will speed up restore in cases where there are backup resources which already exist in the cluster, but for very large clusters this will increase velero memory usage. Default is true (disable).") + command.Flags().BoolVar(&config.enableInformerCache, "enable-informer-cache", config.enableInformerCache, "Enable informer cache for Get calls on restore. With this enabled, it will speed up restore in cases where there are backup resources which already exist in the cluster, but for very large clusters this will increase velero memory usage. Default is false (disable).") command.Flags().BoolVar(&config.scheduleSkipImmediately, "schedule-skip-immediately", config.scheduleSkipImmediately, "Skip the first scheduled backup immediately after creating a schedule. Default is false (don't skip).") return command @@ -951,7 +949,7 @@ func (s *server) runControllers(defaultVolumeSnapshotLocations map[string]string s.metrics, s.config.formatFlag.Parse(), s.config.defaultItemOperationTimeout, - s.config.disableInformerCache, + s.config.enableInformerCache, ) if err = r.SetupWithManager(s.mgr); err != nil { diff --git a/pkg/controller/restore_controller.go b/pkg/controller/restore_controller.go index bacd351eb5..42da005591 100644 --- a/pkg/controller/restore_controller.go +++ b/pkg/controller/restore_controller.go @@ -103,7 +103,7 @@ type restoreReconciler struct { logFormat logging.Format clock clock.WithTickerAndDelayedExecution defaultItemOperationTimeout time.Duration - disableInformerCache bool + enableInformerCache bool newPluginManager func(logger logrus.FieldLogger) clientmgmt.Manager backupStoreGetter persistence.ObjectBackupStoreGetter @@ -126,7 +126,7 @@ func NewRestoreReconciler( metrics *metrics.ServerMetrics, logFormat logging.Format, defaultItemOperationTimeout time.Duration, - disableInformerCache bool, + enableInformerCache bool, ) *restoreReconciler { r := &restoreReconciler{ ctx: ctx, @@ -139,7 +139,7 @@ func NewRestoreReconciler( logFormat: logFormat, clock: &clock.RealClock{}, defaultItemOperationTimeout: defaultItemOperationTimeout, - disableInformerCache: disableInformerCache, + enableInformerCache: enableInformerCache, // use variables to refer to these functions so they can be // replaced with fakes for testing. @@ -540,16 +540,16 @@ func (r *restoreReconciler) runValidatedRestore(restore *api.Restore, info backu } restoreReq := &pkgrestore.Request{ - Log: restoreLog, - Restore: restore, - Backup: info.backup, - PodVolumeBackups: podVolumeBackups, - VolumeSnapshots: volumeSnapshots, - BackupReader: backupFile, - ResourceModifiers: resourceModifiers, - DisableInformerCache: r.disableInformerCache, - CSIVolumeSnapshots: csiVolumeSnapshots, - VolumeInfoMap: backupVolumeInfoMap, + Log: restoreLog, + Restore: restore, + Backup: info.backup, + PodVolumeBackups: podVolumeBackups, + VolumeSnapshots: volumeSnapshots, + BackupReader: backupFile, + ResourceModifiers: resourceModifiers, + EnableInformerCache: r.enableInformerCache, + CSIVolumeSnapshots: csiVolumeSnapshots, + VolumeInfoMap: backupVolumeInfoMap, } restoreWarnings, restoreErrors := r.restorer.RestoreWithResolvers(restoreReq, actionsResolver, pluginManager) diff --git a/pkg/controller/restore_controller_test.go b/pkg/controller/restore_controller_test.go index 5029c1d6e9..c590b1c816 100644 --- a/pkg/controller/restore_controller_test.go +++ b/pkg/controller/restore_controller_test.go @@ -115,7 +115,7 @@ func TestFetchBackupInfo(t *testing.T) { metrics.NewServerMetrics(), formatFlag, 60*time.Minute, - false, + true, ) if test.backupStoreError == nil { @@ -193,7 +193,7 @@ func TestProcessQueueItemSkips(t *testing.T) { metrics.NewServerMetrics(), formatFlag, 60*time.Minute, - false, + true, ) _, err := r.Reconcile(context.Background(), ctrl.Request{NamespacedName: types.NamespacedName{ @@ -461,7 +461,7 @@ func TestRestoreReconcile(t *testing.T) { metrics.NewServerMetrics(), formatFlag, 60*time.Minute, - false, + true, ) r.clock = clocktesting.NewFakeClock(now) @@ -639,7 +639,7 @@ func TestValidateAndCompleteWhenScheduleNameSpecified(t *testing.T) { metrics.NewServerMetrics(), formatFlag, 60*time.Minute, - false, + true, ) restore := &velerov1api.Restore{ @@ -732,7 +732,7 @@ func TestValidateAndCompleteWithResourceModifierSpecified(t *testing.T) { metrics.NewServerMetrics(), formatFlag, 60*time.Minute, - false, + true, ) restore := &velerov1api.Restore{ diff --git a/pkg/install/deployment.go b/pkg/install/deployment.go index 383b40856a..531d2a2a84 100644 --- a/pkg/install/deployment.go +++ b/pkg/install/deployment.go @@ -49,7 +49,7 @@ type podTemplateConfig struct { uploaderType string defaultSnapshotMoveData bool privilegedNodeAgent bool - disableInformerCache bool + enableInformerCache bool scheduleSkipImmediately bool } @@ -153,9 +153,9 @@ func WithDefaultSnapshotMoveData() podTemplateOption { } } -func WithDisableInformerCache() podTemplateOption { +func WithEnableInformerCache() podTemplateOption { return func(c *podTemplateConfig) { - c.disableInformerCache = true + c.enableInformerCache = true } } @@ -206,8 +206,8 @@ func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment args = append(args, "--default-snapshot-move-data=true") } - if c.disableInformerCache { - args = append(args, "--disable-informer-cache=true") + if c.enableInformerCache { + args = append(args, "--enable-informer-cache=true") } if c.scheduleSkipImmediately { diff --git a/pkg/install/deployment_test.go b/pkg/install/deployment_test.go index 8e9649737d..826ebd7b8d 100644 --- a/pkg/install/deployment_test.go +++ b/pkg/install/deployment_test.go @@ -65,7 +65,7 @@ func TestDeployment(t *testing.T) { deploy = Deployment("velero", WithServiceAccountName("test-sa")) assert.Equal(t, "test-sa", deploy.Spec.Template.Spec.ServiceAccountName) - deploy = Deployment("velero", WithDisableInformerCache()) + deploy = Deployment("velero", WithEnableInformerCache()) assert.Len(t, deploy.Spec.Template.Spec.Containers[0].Args, 2) - assert.Equal(t, "--disable-informer-cache=true", deploy.Spec.Template.Spec.Containers[0].Args[1]) + assert.Equal(t, "--enable-informer-cache=false", deploy.Spec.Template.Spec.Containers[0].Args[1]) } diff --git a/pkg/install/resources.go b/pkg/install/resources.go index 700b7b89c6..6cc661ec7d 100644 --- a/pkg/install/resources.go +++ b/pkg/install/resources.go @@ -254,7 +254,7 @@ type VeleroOptions struct { DefaultVolumesToFsBackup bool UploaderType string DefaultSnapshotMoveData bool - DisableInformerCache bool + EnableInformerCache bool ScheduleSkipImmediately bool } @@ -362,8 +362,8 @@ func AllResources(o *VeleroOptions) *unstructured.UnstructuredList { deployOpts = append(deployOpts, WithDefaultSnapshotMoveData()) } - if o.DisableInformerCache { - deployOpts = append(deployOpts, WithDisableInformerCache()) + if o.EnableInformerCache { + deployOpts = append(deployOpts, WithEnableInformerCache()) } deploy := Deployment(o.Namespace, deployOpts...) diff --git a/pkg/restore/request.go b/pkg/restore/request.go index 5d7f6f9295..855f1e7671 100644 --- a/pkg/restore/request.go +++ b/pkg/restore/request.go @@ -53,17 +53,17 @@ func resourceKey(obj runtime.Object) string { type Request struct { *velerov1api.Restore - Log logrus.FieldLogger - Backup *velerov1api.Backup - PodVolumeBackups []*velerov1api.PodVolumeBackup - VolumeSnapshots []*volume.Snapshot - BackupReader io.Reader - RestoredItems map[itemKey]restoredItemStatus - itemOperationsList *[]*itemoperation.RestoreOperation - ResourceModifiers *resourcemodifiers.ResourceModifiers - DisableInformerCache bool - CSIVolumeSnapshots []*snapshotv1api.VolumeSnapshot - VolumeInfoMap map[string]internalVolume.VolumeInfo + Log logrus.FieldLogger + Backup *velerov1api.Backup + PodVolumeBackups []*velerov1api.PodVolumeBackup + VolumeSnapshots []*volume.Snapshot + BackupReader io.Reader + RestoredItems map[itemKey]restoredItemStatus + itemOperationsList *[]*itemoperation.RestoreOperation + ResourceModifiers *resourcemodifiers.ResourceModifiers + EnableInformerCache bool + CSIVolumeSnapshots []*snapshotv1api.VolumeSnapshot + VolumeInfoMap map[string]internalVolume.VolumeInfo } type restoredItemStatus struct { diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 1e0f1cbfae..96cc897f39 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -324,7 +324,7 @@ func (kr *kubernetesRestorer) RestoreWithResolvers( kbClient: kr.kbClient, itemOperationsList: req.GetItemOperationsList(), resourceModifiers: req.ResourceModifiers, - disableInformerCache: req.DisableInformerCache, + enableInformerCache: req.EnableInformerCache, featureVerifier: kr.featureVerifier, hookTracker: hook.NewHookTracker(), volumeInfoMap: req.VolumeInfoMap, @@ -378,7 +378,7 @@ type restoreContext struct { kbClient crclient.Client itemOperationsList *[]*itemoperation.RestoreOperation resourceModifiers *resourcemodifiers.ResourceModifiers - disableInformerCache bool + enableInformerCache bool featureVerifier features.Verifier hookTracker *hook.HookTracker volumeInfoMap map[string]internalVolume.VolumeInfo @@ -446,7 +446,7 @@ func (ctx *restoreContext) execute() (results.Result, results.Result) { }() // Need to stop all informers if enabled - if !ctx.disableInformerCache { + if ctx.enableInformerCache { defer func() { // Call the cancel func to close the channel for each started informer for _, factory := range ctx.dynamicInformerFactories { @@ -578,7 +578,7 @@ func (ctx *restoreContext) execute() (results.Result, results.Result) { errs.Merge(&e) // initialize informer caches for selected resources if enabled - if !ctx.disableInformerCache { + if ctx.enableInformerCache { // CRD informer will have already been initialized if any CRDs were created, // but already-initialized informers aren't re-initialized because getGenericInformer // looks for an existing one first. @@ -1530,7 +1530,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso // only attempt Get before Create if using informer cache, otherwise this will slow down restore into // new namespace - if !ctx.disableInformerCache { + if ctx.enableInformerCache { ctx.log.Debugf("Checking for existence %s: %v", obj.GroupVersionKind().Kind, name) fromCluster, err = ctx.getResource(groupResource, obj, namespace, name) } @@ -1554,7 +1554,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso // check for the existence of the object that failed creation due to alreadyExist in cluster, if no error then it implies that object exists. // and if err then itemExists remains false as we were not able to confirm the existence of the object via Get call or creation call. // We return the get error as a warning to notify the user that the object could exist in cluster and we were not able to confirm it. - if !ctx.disableInformerCache { + if ctx.enableInformerCache { fromCluster, err = ctx.getResource(groupResource, obj, namespace, name) } else { fromCluster, err = resourceClient.Get(name, metav1.GetOptions{}) diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index 19022bb705..1ccd58f816 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -1059,7 +1059,7 @@ func TestRestoreItems(t *testing.T) { tarball io.Reader want []*test.APIResource expectedRestoreItems map[itemKey]restoredItemStatus - disableInformer bool + enableInformer bool }{ { name: "metadata uid/resourceVersion/etc. gets removed", @@ -1216,7 +1216,7 @@ func TestRestoreItems(t *testing.T) { apiResources: []*test.APIResource{ test.Secrets(builder.ForSecret("ns-1", "sa-1").Data(map[string][]byte{"foo": []byte("bar")}).Result()), }, - disableInformer: true, + enableInformer: false, want: []*test.APIResource{ test.Secrets(builder.ForSecret("ns-1", "sa-1").ObjectMeta(builder.WithLabels("velero.io/backup-name", "backup-1", "velero.io/restore-name", "restore-1")).Data(map[string][]byte{"key-1": []byte("value-1")}).Result()), }, @@ -1235,7 +1235,7 @@ func TestRestoreItems(t *testing.T) { apiResources: []*test.APIResource{ test.Secrets(builder.ForSecret("ns-1", "sa-1").Data(map[string][]byte{"foo": []byte("bar")}).Result()), }, - disableInformer: false, + enableInformer: true, want: []*test.APIResource{ test.Secrets(builder.ForSecret("ns-1", "sa-1").ObjectMeta(builder.WithLabels("velero.io/backup-name", "backup-1", "velero.io/restore-name", "restore-1")).Data(map[string][]byte{"key-1": []byte("value-1")}).Result()), }, @@ -1394,14 +1394,14 @@ func TestRestoreItems(t *testing.T) { } data := &Request{ - Log: h.log, - Restore: tc.restore, - Backup: tc.backup, - PodVolumeBackups: nil, - VolumeSnapshots: nil, - BackupReader: tc.tarball, - RestoredItems: map[itemKey]restoredItemStatus{}, - DisableInformerCache: tc.disableInformer, + Log: h.log, + Restore: tc.restore, + Backup: tc.backup, + PodVolumeBackups: nil, + VolumeSnapshots: nil, + BackupReader: tc.tarball, + RestoredItems: map[itemKey]restoredItemStatus{}, + EnableInformerCache: tc.enableInformer, } warnings, errs := h.restorer.Restore( data,