From 996461c139aacdc7380bc2d678d0c2c2155691b1 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Fri, 17 Jan 2025 07:51:57 +0100 Subject: [PATCH] chore: enable use-any from revive Signed-off-by: Matthieu MOREL --- .golangci.yaml | 1 - .../actions/csi/volumesnapshot_action.go | 2 +- .../csi/volumesnapshotcontent_action.go | 2 +- internal/hook/wait_exec_hook_handler.go | 6 +- .../resource_modifiers_test.go | 88 ++++++------ .../strategic_merge_patch.go | 8 +- .../resourcepolicies/resource_policies.go | 8 +- .../resource_policies_test.go | 32 ++--- internal/resourcepolicies/volume_resources.go | 4 +- .../resourcepolicies/volume_resources_test.go | 12 +- .../volume_resources_validator.go | 2 +- .../volume_resources_validator_test.go | 102 +++++++------- .../restartabletest/restartable_delegate.go | 16 +-- internal/volumehelper/volume_policy_helper.go | 2 +- .../volumehelper/volume_policy_helper_test.go | 26 ++-- pkg/backup/actions/backup_pv_action_test.go | 18 +-- pkg/backup/actions/csi/pvc_action.go | 2 +- .../actions/csi/volumesnapshot_action.go | 2 +- .../actions/csi/volumesnapshotclass_action.go | 2 +- .../csi/volumesnapshotcontent_action.go | 2 +- .../actions/remap_crd_version_action_test.go | 2 +- pkg/backup/backup.go | 8 +- pkg/backup/backup_test.go | 8 +- pkg/backup/item_backupper.go | 4 +- pkg/client/config.go | 4 +- pkg/client/factory_test.go | 6 +- pkg/cmd/cli/backup/create.go | 6 +- pkg/cmd/cli/datamover/data_mover_test.go | 6 +- pkg/cmd/cli/restore/create.go | 6 +- pkg/cmd/errors.go | 2 +- pkg/cmd/server/plugin/plugin.go | 58 ++++---- .../output/backup_structured_describer.go | 66 ++++----- .../backup_structured_describer_test.go | 128 +++++++++--------- pkg/cmd/util/output/describe.go | 12 +- pkg/cmd/util/output/describe_test.go | 10 +- .../backup_repository_controller.go | 2 +- .../backup_repository_controller_test.go | 2 +- pkg/controller/data_upload_controller.go | 4 +- pkg/controller/data_upload_controller_test.go | 12 +- .../pod_volume_backup_controller.go | 2 +- .../pod_volume_backup_controller_test.go | 4 +- pkg/datamover/backup_micro_service.go | 2 +- pkg/datamover/restore_micro_service.go | 2 +- pkg/datapath/file_system.go | 4 +- pkg/datapath/micro_service_watcher.go | 10 +- pkg/datapath/types.go | 4 +- pkg/exposer/csi_snapshot.go | 4 +- pkg/exposer/snapshot.go | 4 +- pkg/install/install.go | 4 +- pkg/itemblock/actions/pvc_action.go | 2 +- pkg/persistence/object_store.go | 4 +- .../v1/restartable_backup_item_action_test.go | 20 +-- .../v2/restartable_backup_item_action_test.go | 32 ++--- .../v1/restartable_item_block_action_test.go | 18 +-- pkg/plugin/clientmgmt/manager_test.go | 60 ++++---- .../clientmgmt/process/logrus_adapter.go | 22 +-- .../clientmgmt/process/logrus_adapter_test.go | 18 +-- pkg/plugin/clientmgmt/process/process.go | 4 +- pkg/plugin/clientmgmt/process/process_test.go | 6 +- .../clientmgmt/process/restartable_process.go | 14 +- .../restartable_delete_item_action_test.go | 18 +-- .../clientmgmt/restartable_object_store.go | 2 +- .../restartable_object_store_test.go | 40 +++--- .../restartable_restore_item_action_test.go | 20 +-- .../restartable_restore_item_action_test.go | 38 +++--- .../v1/restartable_volume_snapshotter.go | 2 +- .../v1/restartable_volume_snapshotter_test.go | 44 +++--- pkg/plugin/framework/backup_item_action.go | 2 +- .../framework/backup_item_action_client.go | 2 +- .../framework/backup_item_action_test.go | 2 +- .../backupitemaction/v2/backup_item_action.go | 2 +- .../v2/backup_item_action_client.go | 2 +- .../v2/backup_item_action_test.go | 2 +- .../framework/common/client_dispenser.go | 10 +- .../framework/common/client_dispenser_test.go | 4 +- pkg/plugin/framework/common/handle_panic.go | 2 +- pkg/plugin/framework/common/server_mux.go | 8 +- pkg/plugin/framework/delete_item_action.go | 2 +- .../framework/delete_item_action_client.go | 2 +- pkg/plugin/framework/examples_test.go | 4 +- .../itemblockaction/v1/item_block_action.go | 2 +- .../v1/item_block_action_client.go | 2 +- .../v1/item_block_action_test.go | 2 +- pkg/plugin/framework/object_store.go | 2 +- pkg/plugin/framework/object_store_client.go | 2 +- pkg/plugin/framework/plugin_lister.go | 2 +- pkg/plugin/framework/plugin_types_test.go | 2 +- pkg/plugin/framework/restore_item_action.go | 2 +- .../framework/restore_item_action_client.go | 2 +- .../v2/restore_item_action.go | 2 +- .../v2/restore_item_action_client.go | 2 +- pkg/plugin/framework/volume_snapshotter.go | 2 +- .../framework/volume_snapshotter_client.go | 2 +- pkg/podexec/pod_command_executor.go | 4 +- pkg/podexec/pod_command_executor_test.go | 10 +- pkg/podvolume/backupper.go | 4 +- pkg/podvolume/restorer.go | 2 +- pkg/repository/provider/unified_repo.go | 6 +- pkg/repository/provider/unified_repo_test.go | 42 +++--- pkg/repository/udmrepo/repo.go | 2 +- pkg/repository/udmrepo/repo_options.go | 10 +- .../actions/admissionwebhook_config_action.go | 2 +- .../admissionwebhook_config_action_test.go | 2 +- .../actions/change_image_name_action.go | 6 +- .../actions/change_image_name_action_test.go | 4 +- .../actions/change_pvc_node_selector.go | 2 +- .../actions/change_storageclass_action.go | 2 +- .../change_storageclass_action_test.go | 4 +- .../crd_v1_preserve_unknown_fields_action.go | 2 +- pkg/restore/actions/csi/pvc_action.go | 2 +- .../actions/csi/volumesnapshot_action.go | 2 +- .../actions/csi/volumesnapshotclass_action.go | 2 +- .../csi/volumesnapshotcontent_action.go | 2 +- .../dataupload_retrieve_action_test.go | 2 +- .../actions/pod_volume_restore_action_test.go | 2 +- pkg/restore/actions/service_action.go | 12 +- pkg/restore/actions/service_action_test.go | 10 +- pkg/restore/merge_service_account.go | 2 +- pkg/restore/pv_restorer_test.go | 20 +-- pkg/restore/restore.go | 8 +- pkg/restore/restore_test.go | 68 +++++----- pkg/test/comparisons.go | 4 +- pkg/test/helpers.go | 4 +- pkg/test/mock_pod_command_executor.go | 2 +- pkg/test/mocks/VolumeSnapshotLister.go | 10 +- pkg/test/tar_writer.go | 2 +- pkg/uploader/kopia/shim.go | 6 +- pkg/uploader/kopia/snapshot_test.go | 114 ++++++++-------- pkg/uploader/mocks/uploader.go | 4 +- pkg/uploader/provider/kopia.go | 2 +- pkg/util/encode/encode.go | 2 +- pkg/util/logging/error_location_hook_test.go | 24 ++-- .../api-group/enable_api_group_versions.go | 12 +- test/perf/e2e_suite_test.go | 2 +- test/perf/metrics/monitor.go | 6 +- test/pkg/client/config.go | 4 +- test/pkg/client/factory_test.go | 6 +- test/types.go | 4 +- test/util/report/report.go | 2 +- test/util/velero/install.go | 4 +- 140 files changed, 807 insertions(+), 800 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 8d2b6c75d2..cbee554926 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -282,7 +282,6 @@ linters-settings: - name: unused-parameter disabled: true - name: use-any - disabled: true - name: var-declaration disabled: true - name: var-naming diff --git a/internal/delete/actions/csi/volumesnapshot_action.go b/internal/delete/actions/csi/volumesnapshot_action.go index bc6d9a2be8..73f60b06e2 100644 --- a/internal/delete/actions/csi/volumesnapshot_action.go +++ b/internal/delete/actions/csi/volumesnapshot_action.go @@ -106,7 +106,7 @@ func (p *volumeSnapshotDeleteItemAction) Execute( } func NewVolumeSnapshotDeleteItemAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { crClient, err := f.KubebuilderClient() if err != nil { return nil, errors.WithStack(err) diff --git a/internal/delete/actions/csi/volumesnapshotcontent_action.go b/internal/delete/actions/csi/volumesnapshotcontent_action.go index 0ff0bb68db..a3e76437a9 100644 --- a/internal/delete/actions/csi/volumesnapshotcontent_action.go +++ b/internal/delete/actions/csi/volumesnapshotcontent_action.go @@ -112,7 +112,7 @@ func (p *volumeSnapshotContentDeleteItemAction) Execute( func NewVolumeSnapshotContentDeleteItemAction( f client.Factory, ) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { crClient, err := f.KubebuilderClient() if err != nil { return nil, err diff --git a/internal/hook/wait_exec_hook_handler.go b/internal/hook/wait_exec_hook_handler.go index 5c68816375..9e090a9227 100644 --- a/internal/hook/wait_exec_hook_handler.go +++ b/internal/hook/wait_exec_hook_handler.go @@ -116,7 +116,7 @@ func (e *DefaultWaitExecHookHandler) HandleHooks( // not yet been observed to be running. It relies on the Informer not to be called concurrently. // When a container is observed running and its hooks are executed, the container is deleted // from the byContainer map. When the map is empty the watch is ended. - handler := func(newObj interface{}) { + handler := func(newObj any) { newPod, ok := newObj.(*v1.Pod) if !ok { return @@ -217,10 +217,10 @@ func (e *DefaultWaitExecHookHandler) HandleHooks( _, podWatcher := cache.NewInformer(lw, pod, 0, cache.ResourceEventHandlerFuncs{ AddFunc: handler, - UpdateFunc: func(_, newObj interface{}) { + UpdateFunc: func(_, newObj any) { handler(newObj) }, - DeleteFunc: func(obj interface{}) { + DeleteFunc: func(obj any) { err := fmt.Errorf("pod %s deleted before all hooks were executed", kube.NamespaceAndName(pod)) log.Error(err) cancel() diff --git a/internal/resourcemodifiers/resource_modifiers_test.go b/internal/resourcemodifiers/resource_modifiers_test.go index d6aad99fc8..5ecd3bc0e4 100644 --- a/internal/resourcemodifiers/resource_modifiers_test.go +++ b/internal/resourcemodifiers/resource_modifiers_test.go @@ -429,69 +429,69 @@ func TestGetResourceModifiersFromConfig(t *testing.T) { func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) { pvcStandardSc := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "apiVersion": "v1", "kind": "PersistentVolumeClaim", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "name": "test-pvc", "namespace": "foo", }, - "spec": map[string]interface{}{ + "spec": map[string]any{ "storageClassName": "standard", }, }, } pvcPremiumSc := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "apiVersion": "v1", "kind": "PersistentVolumeClaim", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "name": "test-pvc", "namespace": "foo", }, - "spec": map[string]interface{}{ + "spec": map[string]any{ "storageClassName": "premium", }, }, } pvcGoldSc := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "apiVersion": "v1", "kind": "PersistentVolumeClaim", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "name": "test-pvc", "namespace": "foo", }, - "spec": map[string]interface{}{ + "spec": map[string]any{ "storageClassName": "gold", }, }, } deployNginxOneReplica := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "apiVersion": "apps/v1", "kind": "Deployment", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "name": "test-deployment", "namespace": "foo", - "labels": map[string]interface{}{ + "labels": map[string]any{ "app": "nginx", }, }, - "spec": map[string]interface{}{ + "spec": map[string]any{ "replicas": int64(1), - "template": map[string]interface{}{ - "metadata": map[string]interface{}{ - "labels": map[string]interface{}{ + "template": map[string]any{ + "metadata": map[string]any{ + "labels": map[string]any{ "app": "nginx", }, }, - "spec": map[string]interface{}{ - "containers": []interface{}{ - map[string]interface{}{ + "spec": map[string]any{ + "containers": []any{ + map[string]any{ "name": "nginx", "image": "nginx:latest", }, @@ -502,27 +502,27 @@ func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) { }, } deployNginxTwoReplica := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "apiVersion": "apps/v1", "kind": "Deployment", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "name": "test-deployment", "namespace": "foo", - "labels": map[string]interface{}{ + "labels": map[string]any{ "app": "nginx", }, }, - "spec": map[string]interface{}{ + "spec": map[string]any{ "replicas": int64(2), - "template": map[string]interface{}{ - "metadata": map[string]interface{}{ - "labels": map[string]interface{}{ + "template": map[string]any{ + "metadata": map[string]any{ + "labels": map[string]any{ "app": "nginx", }, }, - "spec": map[string]interface{}{ - "containers": []interface{}{ - map[string]interface{}{ + "spec": map[string]any{ + "containers": []any{ + map[string]any{ "name": "nginx", "image": "nginx:latest", }, @@ -533,31 +533,31 @@ func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) { }, } deployNginxMysql := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "apiVersion": "apps/v1", "kind": "Deployment", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "name": "test-deployment", "namespace": "foo", - "labels": map[string]interface{}{ + "labels": map[string]any{ "app": "nginx", }, }, - "spec": map[string]interface{}{ + "spec": map[string]any{ "replicas": int64(1), - "template": map[string]interface{}{ - "metadata": map[string]interface{}{ - "labels": map[string]interface{}{ + "template": map[string]any{ + "metadata": map[string]any{ + "labels": map[string]any{ "app": "nginx", }, }, - "spec": map[string]interface{}{ - "containers": []interface{}{ - map[string]interface{}{ + "spec": map[string]any{ + "containers": []any{ + map[string]any{ "name": "nginx", "image": "nginx:latest", }, - map[string]interface{}{ + map[string]any{ "name": "mysql", "image": "mysql:latest", }, @@ -568,19 +568,19 @@ func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) { }, } cmTrue := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "apiVersion": "v1", "kind": "ConfigMap", - "data": map[string]interface{}{ + "data": map[string]any{ "test": "true", }, }, } cmFalse := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "apiVersion": "v1", "kind": "ConfigMap", - "data": map[string]interface{}{ + "data": map[string]any{ "test": "false", }, }, diff --git a/internal/resourcemodifiers/strategic_merge_patch.go b/internal/resourcemodifiers/strategic_merge_patch.go index 8d3fe4c511..1edebf27ec 100644 --- a/internal/resourcemodifiers/strategic_merge_patch.go +++ b/internal/resourcemodifiers/strategic_merge_patch.go @@ -53,7 +53,7 @@ func (p *StrategicMergePatcher) Patch(u *unstructured.Unstructured, _ logrus.Fie // strategicPatchObject applies a strategic merge patch of `patchBytes` to // `originalObject` and stores the result in `objToUpdate`. -// It additionally returns the map[string]interface{} representation of the +// It additionally returns the map[string]any representation of the // `originalObject` and `patchBytes`. // NOTE: Both `originalObject` and `objToUpdate` are supposed to be versioned. func strategicPatchObject( @@ -67,7 +67,7 @@ func strategicPatchObject( return err } - patchMap := make(map[string]interface{}) + patchMap := make(map[string]any) var strictErrs []error strictErrs, err = kubejson.UnmarshalStrict(patchBytes, &patchMap) if err != nil { @@ -84,8 +84,8 @@ func strategicPatchObject( // and stores the result in . // NOTE: must be a versioned object. func applyPatchToObject( - originalMap map[string]interface{}, - patchMap map[string]interface{}, + originalMap map[string]any, + patchMap map[string]any, objToUpdate runtime.Object, schemaReferenceObj runtime.Object, strictErrs []error, diff --git a/internal/resourcepolicies/resource_policies.go b/internal/resourcepolicies/resource_policies.go index 40f3fae24d..532c8722d0 100644 --- a/internal/resourcepolicies/resource_policies.go +++ b/internal/resourcepolicies/resource_policies.go @@ -46,14 +46,14 @@ type Action struct { // Type defined specific type of action, currently only support 'skip' Type VolumeActionType `yaml:"type"` // Parameters defined map of parameters when executing a specific action - Parameters map[string]interface{} `yaml:"parameters,omitempty"` + Parameters map[string]any `yaml:"parameters,omitempty"` } // volumePolicy defined policy to conditions to match Volumes and related action to handle matched Volumes type VolumePolicy struct { // Conditions defined list of conditions to match Volumes - Conditions map[string]interface{} `yaml:"conditions"` - Action Action `yaml:"action"` + Conditions map[string]any `yaml:"conditions"` + Action Action `yaml:"action"` } // resourcePolicies currently defined slice of volume policies to handle backup @@ -122,7 +122,7 @@ func (p *Policies) match(res *structuredVolume) *Action { return nil } -func (p *Policies) GetMatchAction(res interface{}) (*Action, error) { +func (p *Policies) GetMatchAction(res any) (*Action, error) { volume := &structuredVolume{} switch obj := res.(type) { case *v1.PersistentVolume: diff --git a/internal/resourcepolicies/resource_policies_test.go b/internal/resourcepolicies/resource_policies_test.go index 53e79a1342..c9ddcd16d7 100644 --- a/internal/resourcepolicies/resource_policies_test.go +++ b/internal/resourcepolicies/resource_policies_test.go @@ -138,20 +138,20 @@ func TestGetResourceMatchedAction(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", "storageClass": []string{"gp2", "ebs-sc"}, - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), }, }, { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ - "csi": interface{}( - map[string]interface{}{ + Conditions: map[string]any{ + "csi": any( + map[string]any{ "driver": "files.csi.driver", "volumeAttributes": map[string]string{"protocol": "nfs"}, }), @@ -159,21 +159,21 @@ func TestGetResourceMatchedAction(t *testing.T) { }, { Action: Action{Type: "snapshot"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "10,100Gi", "storageClass": []string{"gp2", "ebs-sc"}, - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), }, }, { Action: Action{Type: "fs-backup"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2", "ebs-sc"}, - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), }, @@ -281,9 +281,9 @@ func TestGetResourcePoliciesFromConfig(t *testing.T) { Version: "v1", VolumePolicies: []VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", - "csi": map[string]interface{}{ + "csi": map[string]any{ "driver": "disks.csi.driver", }, }, @@ -292,8 +292,8 @@ func TestGetResourcePoliciesFromConfig(t *testing.T) { }, }, { - Conditions: map[string]interface{}{ - "csi": map[string]interface{}{ + Conditions: map[string]any{ + "csi": map[string]any{ "driver": "files.csi.driver", "volumeAttributes": map[string]string{"protocol": "nfs"}, }, diff --git a/internal/resourcepolicies/volume_resources.go b/internal/resourcepolicies/volume_resources.go index 6abdb0648e..250ebc8f24 100644 --- a/internal/resourcepolicies/volume_resources.go +++ b/internal/resourcepolicies/volume_resources.go @@ -226,9 +226,9 @@ func (c *capacity) isInRange(y resource.Quantity) bool { return false } -// unmarshalVolConditions parse map[string]interface{} into volumeConditions format +// unmarshalVolConditions parse map[string]any into volumeConditions format // and validate key fields of the map. -func unmarshalVolConditions(con map[string]interface{}) (*volumeConditions, error) { +func unmarshalVolConditions(con map[string]any) (*volumeConditions, error) { volConditons := &volumeConditions{} buffer := new(bytes.Buffer) err := yaml.NewEncoder(buffer).Encode(con) diff --git a/internal/resourcepolicies/volume_resources_test.go b/internal/resourcepolicies/volume_resources_test.go index 9eca07ef75..32dfb2f101 100644 --- a/internal/resourcepolicies/volume_resources_test.go +++ b/internal/resourcepolicies/volume_resources_test.go @@ -256,12 +256,12 @@ func TestCSIConditionMatch(t *testing.T) { func TestUnmarshalVolumeConditions(t *testing.T) { testCases := []struct { name string - input map[string]interface{} + input map[string]any expectedError string }{ { name: "Valid input", - input: map[string]interface{}{ + input: map[string]any{ "capacity": "1Gi,10Gi", "storageClass": []string{ "gp2", @@ -275,28 +275,28 @@ func TestUnmarshalVolumeConditions(t *testing.T) { }, { name: "Invalid input: invalid capacity filed name", - input: map[string]interface{}{ + input: map[string]any{ "Capacity": "1Gi,10Gi", }, expectedError: "field Capacity not found", }, { name: "Invalid input: invalid storage class format", - input: map[string]interface{}{ + input: map[string]any{ "storageClass": "ebs-sc", }, expectedError: "str `ebs-sc` into []string", }, { name: "Invalid input: invalid csi format", - input: map[string]interface{}{ + input: map[string]any{ "csi": "csi.driver", }, expectedError: "str `csi.driver` into resourcepolicies.csiVolumeSource", }, { name: "Invalid input: unknown field", - input: map[string]interface{}{ + input: map[string]any{ "unknown": "foo", }, expectedError: "field unknown not found in type", diff --git a/internal/resourcepolicies/volume_resources_validator.go b/internal/resourcepolicies/volume_resources_validator.go index f2ca97a300..93295e87d4 100644 --- a/internal/resourcepolicies/volume_resources_validator.go +++ b/internal/resourcepolicies/volume_resources_validator.go @@ -78,7 +78,7 @@ func (c *csiCondition) validate() error { } // decodeStruct restric validate the keys in decoded mappings to exist as fields in the struct being decoded into -func decodeStruct(r io.Reader, s interface{}) error { +func decodeStruct(r io.Reader, s any) error { dec := yaml.NewDecoder(r) dec.KnownFields(true) return dec.Decode(s) diff --git a/internal/resourcepolicies/volume_resources_validator_test.go b/internal/resourcepolicies/volume_resources_validator_test.go index a74bbc52fa..c2acf58e85 100644 --- a/internal/resourcepolicies/volume_resources_validator_test.go +++ b/internal/resourcepolicies/volume_resources_validator_test.go @@ -94,12 +94,12 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", "unknown": "", "storageClass": []string{"gp2", "ebs-sc"}, - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), }, @@ -115,11 +115,11 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "10Gi", "storageClass": []string{"gp2", "ebs-sc"}, - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), }, @@ -135,11 +135,11 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", "storageClass": "ebs-sc", - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), }, @@ -155,7 +155,7 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", "storageClass": []string{"gp2", "ebs-sc"}, "csi": "aws.efs.csi.driver", @@ -172,11 +172,11 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", "storageClass": []string{"gp2", "ebs-sc"}, - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": []string{"aws.efs.csi.driver"}, }), }, @@ -192,11 +192,11 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", "storageClass": []string{"gp2", "ebs-sc"}, - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", "volumeAttributes": "test", }), @@ -213,10 +213,10 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), }, @@ -232,10 +232,10 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "unsupported"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), }, @@ -251,7 +251,7 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", "storageClass": []string{"gp2", "ebs-sc"}, "nfs": "aws.efs.csi.driver", @@ -268,9 +268,9 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ - "csi": interface{}( - map[string]interface{}{ + Conditions: map[string]any{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), }, @@ -286,9 +286,9 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ - "csi": interface{}( - map[string]interface{}{ + Conditions: map[string]any{ + "csi": any( + map[string]any{ "volumeAttributes": map[string]string{ "key1": "value1", }, @@ -306,9 +306,9 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ - "csi": interface{}( - map[string]interface{}{ + Conditions: map[string]any{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", "volumeAttributes": map[string]string{ "key1": "value1", @@ -327,15 +327,15 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "skip"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", "storageClass": []string{"gp2", "ebs-sc"}, - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), - "nfs": interface{}( - map[string]interface{}{ + "nfs": any( + map[string]any{ "server": "192.168.20.90", "path": "/mnt/data/", }), @@ -352,15 +352,15 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "snapshot"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", "storageClass": []string{"gp2", "ebs-sc"}, - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), - "nfs": interface{}( - map[string]interface{}{ + "nfs": any( + map[string]any{ "server": "192.168.20.90", "path": "/mnt/data/", }), @@ -377,15 +377,15 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: "fs-backup"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "capacity": "0,10Gi", "storageClass": []string{"gp2", "ebs-sc"}, - "csi": interface{}( - map[string]interface{}{ + "csi": any( + map[string]any{ "driver": "aws.efs.csi.driver", }), - "nfs": interface{}( - map[string]interface{}{ + "nfs": any( + map[string]any{ "server": "192.168.20.90", "path": "/mnt/data/", }), @@ -402,15 +402,15 @@ func TestValidate(t *testing.T) { VolumePolicies: []VolumePolicy{ { Action: Action{Type: Snapshot}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2"}, }, }, { Action: Action{Type: FSBackup}, - Conditions: map[string]interface{}{ - "nfs": interface{}( - map[string]interface{}{ + Conditions: map[string]any{ + "nfs": any( + map[string]any{ "server": "192.168.20.90", "path": "/mnt/data/", }), diff --git a/internal/restartabletest/restartable_delegate.go b/internal/restartabletest/restartable_delegate.go index e97d5fc7c0..d9308572e0 100644 --- a/internal/restartabletest/restartable_delegate.go +++ b/internal/restartabletest/restartable_delegate.go @@ -46,7 +46,7 @@ func (rp *MockRestartableProcess) ResetIfNeeded() error { return args.Error(0) } -func (rp *MockRestartableProcess) GetByKindAndName(key process.KindAndName) (interface{}, error) { +func (rp *MockRestartableProcess) GetByKindAndName(key process.KindAndName) (any, error) { args := rp.Called(key) return args.Get(0), args.Error(1) } @@ -57,21 +57,21 @@ func (rp *MockRestartableProcess) Stop() { type RestartableDelegateTest struct { Function string - Inputs []interface{} - ExpectedErrorOutputs []interface{} - ExpectedDelegateOutputs []interface{} + Inputs []any + ExpectedErrorOutputs []any + ExpectedDelegateOutputs []any } type Mockable interface { Test(t mock.TestingT) - On(method string, args ...interface{}) *mock.Call + On(method string, args ...any) *mock.Call AssertExpectations(t mock.TestingT) bool } func RunRestartableDelegateTests( t *testing.T, kind common.PluginKind, - newRestartable func(key process.KindAndName, p process.RestartableProcess) interface{}, + newRestartable func(key process.KindAndName, p process.RestartableProcess) any, newMock func() Mockable, tests ...RestartableDelegateTest, ) { @@ -92,7 +92,7 @@ func RunRestartableDelegateTests( method := reflect.ValueOf(r).MethodByName(tc.Function) require.NotEmpty(t, method) - // Convert the test case inputs ([]interface{}) to []reflect.Value + // Convert the test case inputs ([]any) to []reflect.Value var inputValues []reflect.Value for i := range tc.Inputs { inputValues = append(inputValues, reflect.ValueOf(tc.Inputs[i])) @@ -102,7 +102,7 @@ func RunRestartableDelegateTests( actual := method.Call(inputValues) // This Function asserts that the actual outputs match the expected outputs - checkOutputs := func(expected []interface{}, actual []reflect.Value) { + checkOutputs := func(expected []any, actual []reflect.Value) { require.Equal(t, len(expected), len(actual)) for i := range actual { diff --git a/internal/volumehelper/volume_policy_helper.go b/internal/volumehelper/volume_policy_helper.go index 5d39972729..b0315d6c50 100644 --- a/internal/volumehelper/volume_policy_helper.go +++ b/internal/volumehelper/volume_policy_helper.go @@ -143,7 +143,7 @@ func (v volumeHelperImpl) ShouldPerformFSBackup(volume corev1api.Volume, pod cor } if v.volumePolicy != nil { - var resource interface{} + var resource any resource = &volume if volume.VolumeSource.PersistentVolumeClaim != nil { pvc, err := kubeutil.GetPVCForPodVolume(&volume, &pod, v.client) diff --git a/internal/volumehelper/volume_policy_helper_test.go b/internal/volumehelper/volume_policy_helper_test.go index 375825e22e..54c2ae780b 100644 --- a/internal/volumehelper/volume_policy_helper_test.go +++ b/internal/volumehelper/volume_policy_helper_test.go @@ -57,7 +57,7 @@ func TestVolumeHelperImpl_ShouldPerformSnapshot(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2-csi"}, }, Action: resourcepolicies.Action{ @@ -78,7 +78,7 @@ func TestVolumeHelperImpl_ShouldPerformSnapshot(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2-csi"}, }, Action: resourcepolicies.Action{ @@ -99,7 +99,7 @@ func TestVolumeHelperImpl_ShouldPerformSnapshot(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2-csi"}, }, Action: resourcepolicies.Action{ @@ -121,7 +121,7 @@ func TestVolumeHelperImpl_ShouldPerformSnapshot(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2-csi"}, }, Action: resourcepolicies.Action{ @@ -152,7 +152,7 @@ func TestVolumeHelperImpl_ShouldPerformSnapshot(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2-csi"}, }, Action: resourcepolicies.Action{ @@ -186,7 +186,7 @@ func TestVolumeHelperImpl_ShouldPerformSnapshot(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2-csi"}, }, Action: resourcepolicies.Action{ @@ -220,7 +220,7 @@ func TestVolumeHelperImpl_ShouldPerformSnapshot(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2-csi"}, }, Action: resourcepolicies.Action{ @@ -253,7 +253,7 @@ func TestVolumeHelperImpl_ShouldPerformSnapshot(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2-csi"}, }, Action: resourcepolicies.Action{ @@ -465,7 +465,7 @@ func TestVolumeHelperImpl_ShouldIncludeVolumeInBackup(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2-csi"}, }, Action: resourcepolicies.Action{ @@ -540,7 +540,7 @@ func TestVolumeHelperImpl_ShouldPerformFSBackup(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2-csi"}, }, Action: resourcepolicies.Action{ @@ -566,7 +566,7 @@ func TestVolumeHelperImpl_ShouldPerformFSBackup(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "volumeTypes": []string{"emptyDir"}, }, Action: resourcepolicies.Action{ @@ -600,7 +600,7 @@ func TestVolumeHelperImpl_ShouldPerformFSBackup(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2-csi"}, }, Action: resourcepolicies.Action{ @@ -635,7 +635,7 @@ func TestVolumeHelperImpl_ShouldPerformFSBackup(t *testing.T) { Version: "v1", VolumePolicies: []resourcepolicies.VolumePolicy{ { - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp3-csi"}, }, Action: resourcepolicies.Action{ diff --git a/pkg/backup/actions/backup_pv_action_test.go b/pkg/backup/actions/backup_pv_action_test.go index b66021132d..e2c19f14aa 100644 --- a/pkg/backup/actions/backup_pv_action_test.go +++ b/pkg/backup/actions/backup_pv_action_test.go @@ -36,9 +36,9 @@ import ( func TestBackupPVAction(t *testing.T) { pvc := &unstructured.Unstructured{ - Object: map[string]interface{}{ - "spec": map[string]interface{}{}, - "status": map[string]interface{}{}, + Object: map[string]any{ + "spec": map[string]any{}, + "status": map[string]any{}, }, } @@ -54,7 +54,7 @@ func TestBackupPVAction(t *testing.T) { // empty spec.volumeName should result in no error // and no additional items - pvc.Object["spec"].(map[string]interface{})["volumeName"] = "" + pvc.Object["spec"].(map[string]any)["volumeName"] = "" _, additional, err = a.Execute(pvc, backup) assert.NoError(t, err) assert.Empty(t, additional) @@ -116,28 +116,28 @@ func TestBackupPVAction(t *testing.T) { // non-empty spec.volumeName when status.phase is empty // should result in no error and no additional items - pvc.Object["spec"].(map[string]interface{})["volumeName"] = "myVolume" + pvc.Object["spec"].(map[string]any)["volumeName"] = "myVolume" _, additional, err = a.Execute(pvc, backup) require.NoError(t, err) require.Empty(t, additional) // non-empty spec.volumeName when status.phase is 'Pending' // should result in no error and no additional items - pvc.Object["status"].(map[string]interface{})["phase"] = corev1api.ClaimPending + pvc.Object["status"].(map[string]any)["phase"] = corev1api.ClaimPending _, additional, err = a.Execute(pvc, backup) require.NoError(t, err) require.Empty(t, additional) // non-empty spec.volumeName when status.phase is 'Lost' // should result in no error and no additional items - pvc.Object["status"].(map[string]interface{})["phase"] = corev1api.ClaimLost + pvc.Object["status"].(map[string]any)["phase"] = corev1api.ClaimLost _, additional, err = a.Execute(pvc, backup) require.NoError(t, err) require.Empty(t, additional) // non-empty spec.volumeName when status.phase is 'Bound' // should result in no error and one additional item for the PV - pvc.Object["status"].(map[string]interface{})["phase"] = corev1api.ClaimBound + pvc.Object["status"].(map[string]any)["phase"] = corev1api.ClaimBound _, additional, err = a.Execute(pvc, backup) require.NoError(t, err) require.Len(t, additional, 1) @@ -145,7 +145,7 @@ func TestBackupPVAction(t *testing.T) { // empty spec.volumeName when status.phase is 'Bound' should // result in no error and no additional items - pvc.Object["spec"].(map[string]interface{})["volumeName"] = "" + pvc.Object["spec"].(map[string]any)["volumeName"] = "" _, additional, err = a.Execute(pvc, backup) assert.NoError(t, err) assert.Empty(t, additional) diff --git a/pkg/backup/actions/csi/pvc_action.go b/pkg/backup/actions/csi/pvc_action.go index 589cd61d78..ffe31d90ac 100644 --- a/pkg/backup/actions/csi/pvc_action.go +++ b/pkg/backup/actions/csi/pvc_action.go @@ -552,7 +552,7 @@ func cancelDataUpload( } func NewPvcBackupItemAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { crClient, err := f.KubebuilderClient() if err != nil { return nil, errors.WithStack(err) diff --git a/pkg/backup/actions/csi/volumesnapshot_action.go b/pkg/backup/actions/csi/volumesnapshot_action.go index 8be46ea40c..728280fb86 100644 --- a/pkg/backup/actions/csi/volumesnapshot_action.go +++ b/pkg/backup/actions/csi/volumesnapshot_action.go @@ -372,7 +372,7 @@ func (p *volumeSnapshotBackupItemAction) Cancel( func NewVolumeSnapshotBackupItemAction( f client.Factory, ) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { crClient, err := f.KubebuilderClient() if err != nil { return nil, errors.WithStack(err) diff --git a/pkg/backup/actions/csi/volumesnapshotclass_action.go b/pkg/backup/actions/csi/volumesnapshotclass_action.go index f67c5d718a..83b2b1c795 100644 --- a/pkg/backup/actions/csi/volumesnapshotclass_action.go +++ b/pkg/backup/actions/csi/volumesnapshotclass_action.go @@ -119,6 +119,6 @@ func (p *volumeSnapshotClassBackupItemAction) Cancel( // NewVolumeSnapshotClassBackupItemAction returns a // VolumeSnapshotClassBackupItemAction instance. -func NewVolumeSnapshotClassBackupItemAction(logger logrus.FieldLogger) (interface{}, error) { +func NewVolumeSnapshotClassBackupItemAction(logger logrus.FieldLogger) (any, error) { return &volumeSnapshotClassBackupItemAction{log: logger}, nil } diff --git a/pkg/backup/actions/csi/volumesnapshotcontent_action.go b/pkg/backup/actions/csi/volumesnapshotcontent_action.go index f40f0787dd..ccdcc9df00 100644 --- a/pkg/backup/actions/csi/volumesnapshotcontent_action.go +++ b/pkg/backup/actions/csi/volumesnapshotcontent_action.go @@ -136,6 +136,6 @@ func (p *volumeSnapshotContentBackupItemAction) Cancel( // VolumeSnapshotContentBackupItemAction instance. func NewVolumeSnapshotContentBackupItemAction( logger logrus.FieldLogger, -) (interface{}, error) { +) (any, error) { return &volumeSnapshotContentBackupItemAction{log: logger}, nil } diff --git a/pkg/backup/actions/remap_crd_version_action_test.go b/pkg/backup/actions/remap_crd_version_action_test.go index f5bf5542db..cd7296be18 100644 --- a/pkg/backup/actions/remap_crd_version_action_test.go +++ b/pkg/backup/actions/remap_crd_version_action_test.go @@ -208,7 +208,7 @@ func TestRemapCRDVersionActionData(t *testing.T) { // For ElasticSearch and Kibana, problems manifested when additionalPrinterColumns was moved from the top-level spec down to the // versions slice. if test.expectAdditionalColumns { - _, ok := item.UnstructuredContent()["spec"].(map[string]interface{})["additionalPrinterColumns"] + _, ok := item.UnstructuredContent()["spec"].(map[string]any)["additionalPrinterColumns"] assert.True(t, ok) } diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index 280164cc40..59b1e6a0ff 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -446,7 +446,7 @@ func (kb *kubernetesBackupper) BackupWithResolvers( var itemBlock *BackupItemBlock for i := range items { - log.WithFields(map[string]interface{}{ + log.WithFields(map[string]any{ "progress": "", "resource": items[i].groupResource.String(), "namespace": items[i].namespace, @@ -507,7 +507,7 @@ func (kb *kubernetesBackupper) BackupWithResolvers( itemsBackedUp: backedUpItems, } - log.WithFields(map[string]interface{}{ + log.WithFields(map[string]any{ "progress": "", "resource": items[i].groupResource.String(), "namespace": items[i].namespace, @@ -973,7 +973,7 @@ func (kb *kubernetesBackupper) FinalizeBackup( unstructuredDataUploads := make([]unstructured.Unstructured, 0) for i, item := range items { - log.WithFields(map[string]interface{}{ + log.WithFields(map[string]any{ "progress": "", "resource": item.groupResource.String(), "namespace": item.namespace, @@ -1016,7 +1016,7 @@ func (kb *kubernetesBackupper) FinalizeBackup( backedUpItems := backupRequest.BackedUpItems.Len() totalItems := backedUpItems + (len(items) - (i + 1)) - log.WithFields(map[string]interface{}{ + log.WithFields(map[string]any{ "progress": "", "resource": item.groupResource.String(), "namespace": item.namespace, diff --git a/pkg/backup/backup_test.go b/pkg/backup/backup_test.go index 425fa827c5..eb420e3176 100644 --- a/pkg/backup/backup_test.go +++ b/pkg/backup/backup_test.go @@ -1364,7 +1364,7 @@ func TestBackupItemActionsForSkippedPV(t *testing.T) { VolumePolicies: []resourcepolicies.VolumePolicy{ { Action: resourcepolicies.Action{Type: "snapshot"}, - Conditions: map[string]interface{}{ + Conditions: map[string]any{ "storageClass": []string{"gp2"}, }, }, @@ -1849,7 +1849,7 @@ func TestBackupActionModifications(t *testing.T) { }, actions: []biav2.BackupItemAction{ modifyingActionGetter(func(item *unstructured.Unstructured) { - item.Object["spec"].(map[string]interface{})["nodeName"] = "foo" + item.Object["spec"].(map[string]any)["nodeName"] = "foo" }), }, want: map[string]unstructuredObject{ @@ -4282,7 +4282,7 @@ func defaultBackup() *builder.BackupBuilder { return builder.ForBackup(velerov1.DefaultNamespace, "backup-1").DefaultVolumesToFsBackup(false) } -func toUnstructuredOrFail(t *testing.T, obj interface{}) map[string]interface{} { +func toUnstructuredOrFail(t *testing.T, obj any) map[string]any { t.Helper() res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj) @@ -4318,7 +4318,7 @@ func assertTarballContents(t *testing.T, backupFile io.Reader, items ...string) } // unstructuredObject is a type alias to improve readability. -type unstructuredObject map[string]interface{} +type unstructuredObject map[string]any // assertTarballFileContents verifies that the gzipped tarball stored in the provided // backupFile contains the files specified as keys in 'want', and for each of those diff --git a/pkg/backup/item_backupper.go b/pkg/backup/item_backupper.go index 9e5caef0ed..ea851f81b0 100644 --- a/pkg/backup/item_backupper.go +++ b/pkg/backup/item_backupper.go @@ -159,7 +159,7 @@ func (ib *itemBackupper) backupItemInternal(logger logrus.FieldLogger, obj runti namespace := metadata.GetNamespace() name := metadata.GetName() - log := logger.WithFields(map[string]interface{}{ + log := logger.WithFields(map[string]any{ "name": name, "resource": groupResource.String(), "namespace": namespace, @@ -218,7 +218,7 @@ func (ib *itemBackupper) backupItemInternal(logger logrus.FieldLogger, obj runti ib.podVolumeSnapshotTracker.Track(pod, volume.Name) if found, pvcName := ib.podVolumeSnapshotTracker.TakenForPodVolume(pod, volume.Name); found { - log.WithFields(map[string]interface{}{ + log.WithFields(map[string]any{ "podVolume": volume, "pvcName": pvcName, }).Info("Pod volume uses a persistent volume claim which has already been backed up from another pod, skipping.") diff --git a/pkg/client/config.go b/pkg/client/config.go index 7546a0ac4c..687c303e7b 100644 --- a/pkg/client/config.go +++ b/pkg/client/config.go @@ -33,9 +33,9 @@ const ( ConfigKeyColorized = "colorized" ) -// VeleroConfig is a map of strings to interface{} for deserializing Velero client config options. +// VeleroConfig is a map of strings to any for deserializing Velero client config options. // The alias is a way to attach type-asserting convenience methods. -type VeleroConfig map[string]interface{} +type VeleroConfig map[string]any // LoadConfig loads the Velero client configuration file and returns it as a VeleroConfig. If the // file does not exist, an empty map is returned. diff --git a/pkg/client/factory_test.go b/pkg/client/factory_test.go index 316808c327..e7ca1d153f 100644 --- a/pkg/client/factory_test.go +++ b/pkg/client/factory_test.go @@ -36,14 +36,14 @@ func TestFactory(t *testing.T) { // Env variable should set the namespace if no config or argument are used os.Setenv("VELERO_NAMESPACE", "env-velero") - f := NewFactory("velero", make(map[string]interface{})) + f := NewFactory("velero", make(map[string]any)) assert.Equal(t, "env-velero", f.Namespace()) os.Unsetenv("VELERO_NAMESPACE") // Argument should change the namespace - f = NewFactory("velero", make(map[string]interface{})) + f = NewFactory("velero", make(map[string]any)) s := "flag-velero" flags := new(flag.FlagSet) @@ -55,7 +55,7 @@ func TestFactory(t *testing.T) { // An argument overrides the env variable if both are set. os.Setenv("VELERO_NAMESPACE", "env-velero") - f = NewFactory("velero", make(map[string]interface{})) + f = NewFactory("velero", make(map[string]any)) flags = new(flag.FlagSet) f.BindFlags(flags) diff --git a/pkg/cmd/cli/backup/create.go b/pkg/cmd/cli/backup/create.go index 6daacef7d8..03fb74938a 100644 --- a/pkg/cmd/cli/backup/create.go +++ b/pkg/cmd/cli/backup/create.go @@ -257,7 +257,7 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { backupInformer := cache.NewSharedInformer(&lw, &velerov1api.Backup{}, time.Second) _, _ = backupInformer.AddEventHandler( cache.FilteringResourceEventHandler{ - FilterFunc: func(obj interface{}) bool { + FilterFunc: func(obj any) bool { backup, ok := obj.(*velerov1api.Backup) if !ok { @@ -266,14 +266,14 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { return backup.Name == o.Name }, Handler: cache.ResourceEventHandlerFuncs{ - UpdateFunc: func(_, obj interface{}) { + UpdateFunc: func(_, obj any) { backup, ok := obj.(*velerov1api.Backup) if !ok { return } updates <- backup }, - DeleteFunc: func(obj interface{}) { + DeleteFunc: func(obj any) { backup, ok := obj.(*velerov1api.Backup) if !ok { return diff --git a/pkg/cmd/cli/datamover/data_mover_test.go b/pkg/cmd/cli/datamover/data_mover_test.go index 51d9376d31..206ba36eef 100644 --- a/pkg/cmd/cli/datamover/data_mover_test.go +++ b/pkg/cmd/cli/datamover/data_mover_test.go @@ -56,7 +56,7 @@ func TestExitWithMessage(t *testing.T) { name string message string succeed bool - args []interface{} + args []any createErr error writeFail bool expectedExitCode int @@ -77,7 +77,7 @@ func TestExitWithMessage(t *testing.T) { { name: "not succeed", message: "fake-message-1, arg-1 %s, arg-2 %v, arg-3 %v", - args: []interface{}{ + args: []any{ "arg-1-1", 10, false, @@ -88,7 +88,7 @@ func TestExitWithMessage(t *testing.T) { { name: "not succeed", message: "fake-message-2, arg-1 %s, arg-2 %v, arg-3 %v", - args: []interface{}{ + args: []any{ "arg-1-2", 20, true, diff --git a/pkg/cmd/cli/restore/create.go b/pkg/cmd/cli/restore/create.go index 17446f6983..dd0019672f 100644 --- a/pkg/cmd/cli/restore/create.go +++ b/pkg/cmd/cli/restore/create.go @@ -369,7 +369,7 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { _, _ = restoreInformer.AddEventHandler( cache.FilteringResourceEventHandler{ - FilterFunc: func(obj interface{}) bool { + FilterFunc: func(obj any) bool { restore, ok := obj.(*api.Restore) if !ok { return false @@ -377,14 +377,14 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { return restore.Name == o.RestoreName }, Handler: cache.ResourceEventHandlerFuncs{ - UpdateFunc: func(_, obj interface{}) { + UpdateFunc: func(_, obj any) { restore, ok := obj.(*api.Restore) if !ok { return } updates <- restore }, - DeleteFunc: func(obj interface{}) { + DeleteFunc: func(obj any) { restore, ok := obj.(*api.Restore) if !ok { return diff --git a/pkg/cmd/errors.go b/pkg/cmd/errors.go index 2ba4420a81..4f374c8aff 100644 --- a/pkg/cmd/errors.go +++ b/pkg/cmd/errors.go @@ -34,7 +34,7 @@ func CheckError(err error) { } // Exit prints msg (with optional args), plus a newline, to stderr and exits with code 1. -func Exit(msg string, args ...interface{}) { +func Exit(msg string, args ...any) { fmt.Fprintf(os.Stderr, msg+"\n", args...) os.Exit(1) } diff --git a/pkg/cmd/server/plugin/plugin.go b/pkg/cmd/server/plugin/plugin.go index 3fa174d81e..f85431b368 100644 --- a/pkg/cmd/server/plugin/plugin.go +++ b/pkg/cmd/server/plugin/plugin.go @@ -209,16 +209,16 @@ func NewCommand(f client.Factory) *cobra.Command { return c } -func newPVBackupItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newPVBackupItemAction(logger logrus.FieldLogger) (any, error) { return bia.NewPVCAction(logger), nil } -func newPodBackupItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newPodBackupItemAction(logger logrus.FieldLogger) (any, error) { return bia.NewPodAction(logger), nil } func newServiceAccountBackupItemAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { // TODO(ncdc): consider a k8s style WantsKubernetesClientSet initialization approach clientset, err := f.KubeClient() if err != nil { @@ -248,7 +248,7 @@ func newServiceAccountBackupItemAction(f client.Factory) plugincommon.HandlerIni } func newRemapCRDVersionAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { config, err := f.ClientConfig() if err != nil { return nil, err @@ -272,20 +272,20 @@ func newRemapCRDVersionAction(f client.Factory) plugincommon.HandlerInitializer } } -func newJobRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newJobRestoreItemAction(logger logrus.FieldLogger) (any, error) { return ria.NewJobAction(logger), nil } -func newPodRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newPodRestoreItemAction(logger logrus.FieldLogger) (any, error) { return ria.NewPodAction(logger), nil } -func newInitRestoreHookPodAction(logger logrus.FieldLogger) (interface{}, error) { +func newInitRestoreHookPodAction(logger logrus.FieldLogger) (any, error) { return ria.NewInitRestoreHookPodAction(logger), nil } func newPodVolumeRestoreItemAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { client, err := f.KubeClient() if err != nil { return nil, err @@ -300,28 +300,28 @@ func newPodVolumeRestoreItemAction(f client.Factory) plugincommon.HandlerInitial } } -func newServiceRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newServiceRestoreItemAction(logger logrus.FieldLogger) (any, error) { return ria.NewServiceAction(logger), nil } -func newServiceAccountRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newServiceAccountRestoreItemAction(logger logrus.FieldLogger) (any, error) { return ria.NewServiceAccountAction(logger), nil } -func newAddPVCFromPodRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newAddPVCFromPodRestoreItemAction(logger logrus.FieldLogger) (any, error) { return ria.NewAddPVCFromPodAction(logger), nil } -func newAddPVFromPVCRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newAddPVFromPVCRestoreItemAction(logger logrus.FieldLogger) (any, error) { return ria.NewAddPVFromPVCAction(logger), nil } -func newCRDV1PreserveUnknownFieldsItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newCRDV1PreserveUnknownFieldsItemAction(logger logrus.FieldLogger) (any, error) { return ria.NewCRDV1PreserveUnknownFieldsAction(logger), nil } func newChangeStorageClassRestoreItemAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { client, err := f.KubeClient() if err != nil { return nil, err @@ -336,7 +336,7 @@ func newChangeStorageClassRestoreItemAction(f client.Factory) plugincommon.Handl } func newChangeImageNameRestoreItemAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { client, err := f.KubeClient() if err != nil { return nil, err @@ -348,16 +348,16 @@ func newChangeImageNameRestoreItemAction(f client.Factory) plugincommon.HandlerI ), nil } } -func newRoleBindingItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newRoleBindingItemAction(logger logrus.FieldLogger) (any, error) { return ria.NewRoleBindingAction(logger), nil } -func newClusterRoleBindingItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newClusterRoleBindingItemAction(logger logrus.FieldLogger) (any, error) { return ria.NewClusterRoleBindingAction(logger), nil } func newChangePVCNodeSelectorItemAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { client, err := f.KubeClient() if err != nil { return nil, err @@ -371,16 +371,16 @@ func newChangePVCNodeSelectorItemAction(f client.Factory) plugincommon.HandlerIn } } -func newAPIServiceRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newAPIServiceRestoreItemAction(logger logrus.FieldLogger) (any, error) { return ria.NewAPIServiceAction(logger), nil } -func newAdmissionWebhookConfigurationAction(logger logrus.FieldLogger) (interface{}, error) { +func newAdmissionWebhookConfigurationAction(logger logrus.FieldLogger) (any, error) { return ria.NewAdmissionWebhookConfigurationAction(logger), nil } func newSecretRestoreItemAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { client, err := f.KubebuilderClient() if err != nil { return nil, err @@ -390,7 +390,7 @@ func newSecretRestoreItemAction(f client.Factory) plugincommon.HandlerInitialize } func newDataUploadRetrieveAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { client, err := f.KubebuilderClient() if err != nil { return nil, err @@ -401,7 +401,7 @@ func newDataUploadRetrieveAction(f client.Factory) plugincommon.HandlerInitializ } func newDateUploadDeleteItemAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { client, err := f.KubebuilderClient() if err != nil { return nil, err @@ -422,11 +422,11 @@ func newVolumeSnapshotBackupItemAction(f client.Factory) plugincommon.HandlerIni return csibia.NewVolumeSnapshotBackupItemAction(f) } -func newVolumeSnapshotContentBackupItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newVolumeSnapshotContentBackupItemAction(logger logrus.FieldLogger) (any, error) { return csibia.NewVolumeSnapshotContentBackupItemAction(logger) } -func newVolumeSnapshotClassBackupItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newVolumeSnapshotClassBackupItemAction(logger logrus.FieldLogger) (any, error) { return csibia.NewVolumeSnapshotClassBackupItemAction(logger) } @@ -450,11 +450,11 @@ func newVolumeSnapshotRestoreItemAction(f client.Factory) plugincommon.HandlerIn return csiria.NewVolumeSnapshotRestoreItemAction(f) } -func newVolumeSnapshotContentRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newVolumeSnapshotContentRestoreItemAction(logger logrus.FieldLogger) (any, error) { return csiria.NewVolumeSnapshotContentRestoreItemAction(logger) } -func newVolumeSnapshotClassRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newVolumeSnapshotClassRestoreItemAction(logger logrus.FieldLogger) (any, error) { return csiria.NewVolumeSnapshotClassRestoreItemAction(logger) } @@ -464,12 +464,12 @@ func newPVCItemBlockAction(f client.Factory) plugincommon.HandlerInitializer { return iba.NewPVCAction(f) } -func newPodItemBlockAction(logger logrus.FieldLogger) (interface{}, error) { +func newPodItemBlockAction(logger logrus.FieldLogger) (any, error) { return iba.NewPodAction(logger), nil } func newServiceAccountItemBlockAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { // TODO(ncdc): consider a k8s style WantsKubernetesClientSet initialization approach clientset, err := f.KubeClient() if err != nil { diff --git a/pkg/cmd/util/output/backup_structured_describer.go b/pkg/cmd/util/output/backup_structured_describer.go index 63bfbbd5ba..2065b669c5 100644 --- a/pkg/cmd/util/output/backup_structured_describer.go +++ b/pkg/cmd/util/output/backup_structured_describer.go @@ -74,11 +74,11 @@ func DescribeBackupInSF( // DescribeBackupSpecInSF describes a backup spec in structured format. func DescribeBackupSpecInSF(d *StructuredDescriber, spec velerov1api.BackupSpec) { - backupSpecInfo := make(map[string]interface{}) + backupSpecInfo := make(map[string]any) var s string // describe namespaces - namespaceInfo := make(map[string]interface{}) + namespaceInfo := make(map[string]any) if len(spec.IncludedNamespaces) == 0 { s = "*" } else { @@ -140,10 +140,10 @@ func DescribeBackupSpecInSF(d *StructuredDescriber, spec velerov1api.BackupSpec) backupSpecInfo["CSISnapshotTimeout"] = spec.CSISnapshotTimeout.Duration.String() // describe hooks - hooksInfo := make(map[string]interface{}) - hooksResources := make(map[string]interface{}) + hooksInfo := make(map[string]any) + hooksResources := make(map[string]any) for _, backupResourceHookSpec := range spec.Hooks.Resources { - ResourceDetails := make(map[string]interface{}) + ResourceDetails := make(map[string]any) var s string namespaceInfo := make(map[string]string) if len(backupResourceHookSpec.IncludedNamespaces) == 0 { @@ -181,10 +181,10 @@ func DescribeBackupSpecInSF(d *StructuredDescriber, spec velerov1api.BackupSpec) } ResourceDetails["labelSelector"] = s - preHooks := make([]map[string]interface{}, 0) + preHooks := make([]map[string]any, 0) for _, hook := range backupResourceHookSpec.PreHooks { if hook.Exec != nil { - preExecHook := make(map[string]interface{}) + preExecHook := make(map[string]any) preExecHook["container"] = hook.Exec.Container preExecHook["command"] = strings.Join(hook.Exec.Command, " ") preExecHook["onError:"] = hook.Exec.OnError @@ -194,10 +194,10 @@ func DescribeBackupSpecInSF(d *StructuredDescriber, spec velerov1api.BackupSpec) } ResourceDetails["preExecHook"] = preHooks - postHooks := make([]map[string]interface{}, 0) + postHooks := make([]map[string]any, 0) for _, hook := range backupResourceHookSpec.PostHooks { if hook.Exec != nil { - postExecHook := make(map[string]interface{}) + postExecHook := make(map[string]any) postExecHook["container"] = hook.Exec.Container postExecHook["command"] = strings.Join(hook.Exec.Command, " ") postExecHook["onError:"] = hook.Exec.OnError @@ -225,7 +225,7 @@ func DescribeBackupSpecInSF(d *StructuredDescriber, spec velerov1api.BackupSpec) func DescribeBackupStatusInSF(ctx context.Context, kbClient kbclient.Client, d *StructuredDescriber, backup *velerov1api.Backup, details bool, insecureSkipTLSVerify bool, caCertPath string, podVolumeBackups []velerov1api.PodVolumeBackup) { status := backup.Status - backupStatusInfo := make(map[string]interface{}) + backupStatusInfo := make(map[string]any) // Status.Version has been deprecated, use Status.FormatVersion backupStatusInfo["backupFormatVersion"] = status.FormatVersion @@ -271,7 +271,7 @@ func DescribeBackupStatusInSF(ctx context.Context, kbClient kbclient.Client, d * } } -func describeBackupResourceListInSF(ctx context.Context, kbClient kbclient.Client, backupStatusInfo map[string]interface{}, backup *velerov1api.Backup, insecureSkipTLSVerify bool, caCertPath string) { +func describeBackupResourceListInSF(ctx context.Context, kbClient kbclient.Client, backupStatusInfo map[string]any, backup *velerov1api.Backup, insecureSkipTLSVerify bool, caCertPath string) { // In consideration of decoding structured output conveniently, the two separate fields were created here(in func describeBackupResourceList, there is only one field describing either error message or resource list) // the field of 'errorGettingResourceList' gives specific error message when it fails to get resources list // the field of 'resourceList' lists the rearranged resources @@ -299,8 +299,8 @@ func describeBackupResourceListInSF(ctx context.Context, kbClient kbclient.Clien } func describeBackupVolumesInSF(ctx context.Context, kbClient kbclient.Client, backup *velerov1api.Backup, details bool, - insecureSkipTLSVerify bool, caCertPath string, podVolumeBackupCRs []velerov1api.PodVolumeBackup, backupStatusInfo map[string]interface{}) { - backupVolumes := make(map[string]interface{}) + insecureSkipTLSVerify bool, caCertPath string, podVolumeBackupCRs []velerov1api.PodVolumeBackup, backupStatusInfo map[string]any) { + backupVolumes := make(map[string]any) nativeSnapshots := []*volume.BackupVolumeInfo{} csiSnapshots := []*volume.BackupVolumeInfo{} @@ -351,20 +351,20 @@ func describeBackupVolumesInSF(ctx context.Context, kbClient kbclient.Client, ba backupStatusInfo["backupVolumes"] = backupVolumes } -func describeNativeSnapshotsInSF(details bool, infos []*volume.BackupVolumeInfo, backupVolumes map[string]interface{}) { +func describeNativeSnapshotsInSF(details bool, infos []*volume.BackupVolumeInfo, backupVolumes map[string]any) { if len(infos) == 0 { backupVolumes["nativeSnapshots"] = "" return } - snapshotDetails := make(map[string]interface{}) + snapshotDetails := make(map[string]any) for _, info := range infos { describNativeSnapshotInSF(details, info, snapshotDetails) } backupVolumes["nativeSnapshots"] = snapshotDetails } -func describNativeSnapshotInSF(details bool, info *volume.BackupVolumeInfo, snapshotDetails map[string]interface{}) { +func describNativeSnapshotInSF(details bool, info *volume.BackupVolumeInfo, snapshotDetails map[string]any) { if details { snapshotInfo := make(map[string]string) snapshotInfo["snapshotID"] = info.NativeSnapshotInfo.SnapshotHandle @@ -379,7 +379,7 @@ func describNativeSnapshotInSF(details bool, info *volume.BackupVolumeInfo, snap } } -func describeCSISnapshotsInSF(details bool, infos []*volume.BackupVolumeInfo, backupVolumes map[string]interface{}, legacyInfoSource bool) { +func describeCSISnapshotsInSF(details bool, infos []*volume.BackupVolumeInfo, backupVolumes map[string]any, legacyInfoSource bool) { if len(infos) == 0 { if legacyInfoSource { backupVolumes["csiSnapshots"] = "" @@ -389,15 +389,15 @@ func describeCSISnapshotsInSF(details bool, infos []*volume.BackupVolumeInfo, ba return } - snapshotDetails := make(map[string]interface{}) + snapshotDetails := make(map[string]any) for _, info := range infos { describeCSISnapshotInSF(details, info, snapshotDetails) } backupVolumes["csiSnapshots"] = snapshotDetails } -func describeCSISnapshotInSF(details bool, info *volume.BackupVolumeInfo, snapshotDetails map[string]interface{}) { - snapshotDetail := make(map[string]interface{}) +func describeCSISnapshotInSF(details bool, info *volume.BackupVolumeInfo, snapshotDetails map[string]any) { + snapshotDetail := make(map[string]any) describeLocalSnapshotInSF(details, info, snapshotDetail) describeDataMovementInSF(details, info, snapshotDetail) @@ -406,13 +406,13 @@ func describeCSISnapshotInSF(details bool, info *volume.BackupVolumeInfo, snapsh } // describeLocalSnapshotInSF describes CSI volume snapshot contents in structured format. -func describeLocalSnapshotInSF(details bool, info *volume.BackupVolumeInfo, snapshotDetail map[string]interface{}) { +func describeLocalSnapshotInSF(details bool, info *volume.BackupVolumeInfo, snapshotDetail map[string]any) { if !info.PreserveLocalSnapshot { return } if details { - localSnapshot := make(map[string]interface{}) + localSnapshot := make(map[string]any) if !info.SnapshotDataMoved { localSnapshot["operationID"] = info.CSISnapshotInfo.OperationID @@ -430,13 +430,13 @@ func describeLocalSnapshotInSF(details bool, info *volume.BackupVolumeInfo, snap } } -func describeDataMovementInSF(details bool, info *volume.BackupVolumeInfo, snapshotDetail map[string]interface{}) { +func describeDataMovementInSF(details bool, info *volume.BackupVolumeInfo, snapshotDetail map[string]any) { if !info.SnapshotDataMoved { return } if details { - dataMovement := make(map[string]interface{}) + dataMovement := make(map[string]any) dataMovement["operationID"] = info.SnapshotDataMovementInfo.OperationID dataMover := "velero" @@ -456,14 +456,14 @@ func describeDataMovementInSF(details bool, info *volume.BackupVolumeInfo, snaps // DescribeDeleteBackupRequestsInSF describes delete backup requests in structured format. func DescribeDeleteBackupRequestsInSF(d *StructuredDescriber, requests []velerov1api.DeleteBackupRequest) { - deletionAttempts := make(map[string]interface{}) + deletionAttempts := make(map[string]any) if count := failedDeletionCount(requests); count > 0 { deletionAttempts["failed"] = count } - deletionRequests := make([]map[string]interface{}, 0) + deletionRequests := make([]map[string]any, 0) for _, req := range requests { - deletionReq := make(map[string]interface{}) + deletionReq := make(map[string]any) deletionReq["creationTimestamp"] = req.CreationTimestamp.String() deletionReq["phase"] = req.Status.Phase @@ -477,8 +477,8 @@ func DescribeDeleteBackupRequestsInSF(d *StructuredDescriber, requests []velerov } // describePodVolumeBackupsInSF describes pod volume backups in structured format. -func describePodVolumeBackupsInSF(backups []velerov1api.PodVolumeBackup, details bool, backupVolumes map[string]interface{}) { - podVolumeBackupsInfo := make(map[string]interface{}) +func describePodVolumeBackupsInSF(backups []velerov1api.PodVolumeBackup, details bool, backupVolumes map[string]any) { + podVolumeBackupsInfo := make(map[string]any) // Get the type of pod volume uploader. Since the uploader only comes from a single source, we can // take the uploader type from the first element of the array. var uploaderType string @@ -491,7 +491,7 @@ func describePodVolumeBackupsInSF(backups []velerov1api.PodVolumeBackup, details // type display the type of pod volume backups podVolumeBackupsInfo["uploderType"] = uploaderType - podVolumeBackupsDetails := make(map[string]interface{}) + podVolumeBackupsDetails := make(map[string]any) // separate backups by phase (combining and New into a single group) backupsByPhase := groupByPhase(backups) @@ -537,7 +537,7 @@ func DescribeBackupResultsInSF(ctx context.Context, kbClient kbclient.Client, d var buf bytes.Buffer var resultMap map[string]results.Result - errors, warnings := make(map[string]interface{}), make(map[string]interface{}) + errors, warnings := make(map[string]any), make(map[string]any) defer func() { d.Describe("errors", errors) d.Describe("warnings", warnings) @@ -572,13 +572,13 @@ func DescribeBackupResultsInSF(ctx context.Context, kbClient kbclient.Client, d // DescribeResourcePoliciesInSF describes resource policies in structured format. func DescribeResourcePoliciesInSF(d *StructuredDescriber, resPolicies *v1.TypedLocalObjectReference) { - policiesInfo := make(map[string]interface{}) + policiesInfo := make(map[string]any) policiesInfo["type"] = resPolicies.Kind policiesInfo["name"] = resPolicies.Name d.Describe("resourcePolicies", policiesInfo) } -func describeResultInSF(m map[string]interface{}, result results.Result) { +func describeResultInSF(m map[string]any, result results.Result) { m["velero"], m["cluster"], m["namespace"] = []string{}, []string{}, []string{} if len(result.Velero) > 0 { diff --git a/pkg/cmd/util/output/backup_structured_describer_test.go b/pkg/cmd/util/output/backup_structured_describer_test.go index 1ac32830c2..c635836ce8 100644 --- a/pkg/cmd/util/output/backup_structured_describer_test.go +++ b/pkg/cmd/util/output/backup_structured_describer_test.go @@ -33,7 +33,7 @@ import ( func TestDescribeBackupInSF(t *testing.T) { sd := &StructuredDescriber{ - output: make(map[string]interface{}), + output: make(map[string]any), format: "", } backupBuilder1 := builder.ForBackup("test-ns", "test-backup") @@ -75,9 +75,9 @@ func TestDescribeBackupInSF(t *testing.T) { }, }) - expect1 := map[string]interface{}{ - "spec": map[string]interface{}{ - "namespaces": map[string]interface{}{ + expect1 := map[string]any{ + "spec": map[string]any{ + "namespaces": map[string]any{ "included": "inc-ns-1, inc-ns-2", "excluded": "exc-ns-1, exc-ns-2", }, @@ -93,15 +93,15 @@ func TestDescribeBackupInSF(t *testing.T) { "TTL": "72h0m0s", "CSISnapshotTimeout": "10m0s", "veleroSnapshotMoveData": "auto", - "hooks": map[string]interface{}{ - "resources": map[string]interface{}{ - "hook-1": map[string]interface{}{ + "hooks": map[string]any{ + "resources": map[string]any{ + "hook-1": map[string]any{ "labelSelector": emptyDisplay, "namespaces": map[string]string{ "included": "hook-inc-ns-1, hook-inc-ns-2", "excluded": "hook-exc-ns-1, hook-exc-ns-2", }, - "preExecHook": []map[string]interface{}{ + "preExecHook": []map[string]any{ { "container": "hook-container-1", "command": "pre", @@ -109,7 +109,7 @@ func TestDescribeBackupInSF(t *testing.T) { "timeout": "0s", }, }, - "postExecHook": []map[string]interface{}{ + "postExecHook": []map[string]any{ { "container": "hook-container-1", "command": "post", @@ -160,9 +160,9 @@ func TestDescribeBackupInSF(t *testing.T) { }, }) - expect2 := map[string]interface{}{ - "spec": map[string]interface{}{ - "namespaces": map[string]interface{}{ + expect2 := map[string]any{ + "spec": map[string]any{ + "namespaces": map[string]any{ "included": "*", "excluded": emptyDisplay, }, @@ -178,15 +178,15 @@ func TestDescribeBackupInSF(t *testing.T) { "TTL": "0s", "CSISnapshotTimeout": "0s", "veleroSnapshotMoveData": "auto", - "hooks": map[string]interface{}{ - "resources": map[string]interface{}{ - "hook-1": map[string]interface{}{ + "hooks": map[string]any{ + "resources": map[string]any{ + "hook-1": map[string]any{ "labelSelector": emptyDisplay, "namespaces": map[string]string{ "included": "*", "excluded": emptyDisplay, }, - "preExecHook": []map[string]interface{}{ + "preExecHook": []map[string]any{ { "container": "hook-container-1", "command": "pre", @@ -194,7 +194,7 @@ func TestDescribeBackupInSF(t *testing.T) { "timeout": "0s", }, }, - "postExecHook": []map[string]interface{}{ + "postExecHook": []map[string]any{ { "container": "hook-container-1", "command": "post", @@ -244,21 +244,21 @@ func TestDescribePodVolumeBackupsInSF(t *testing.T) { name string inputPVBList []velerov1api.PodVolumeBackup inputDetails bool - expect map[string]interface{} + expect map[string]any }{ { name: "empty list", inputPVBList: []velerov1api.PodVolumeBackup{}, inputDetails: false, - expect: map[string]interface{}{"podVolumeBackups": ""}, + expect: map[string]any{"podVolumeBackups": ""}, }, { name: "2 completed pvbs", inputPVBList: []velerov1api.PodVolumeBackup{*pvb1, *pvb2}, inputDetails: true, - expect: map[string]interface{}{ - "podVolumeBackups": map[string]interface{}{ - "podVolumeBackupsDetails": map[string]interface{}{ + expect: map[string]any{ + "podVolumeBackups": map[string]any{ + "podVolumeBackupsDetails": map[string]any{ "Completed": []map[string]string{ {"pod-ns-1/pod-1": "vol-1"}, {"pod-ns-1/pod-2": "vol-2"}, @@ -271,7 +271,7 @@ func TestDescribePodVolumeBackupsInSF(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(tt *testing.T) { - output := make(map[string]interface{}) + output := make(map[string]any) describePodVolumeBackupsInSF(tc.inputPVBList, tc.inputDetails, output) assert.True(tt, reflect.DeepEqual(output, tc.expect)) }) @@ -283,7 +283,7 @@ func TestDescribeNativeSnapshotsInSF(t *testing.T) { name string volumeInfo []*volume.BackupVolumeInfo inputDetails bool - expect map[string]interface{} + expect map[string]any }{ { name: "no details", @@ -299,8 +299,8 @@ func TestDescribeNativeSnapshotsInSF(t *testing.T) { }, }, }, - expect: map[string]interface{}{ - "nativeSnapshots": map[string]interface{}{ + expect: map[string]any{ + "nativeSnapshots": map[string]any{ "pv-1": "specify --details for more information", }, }, @@ -321,8 +321,8 @@ func TestDescribeNativeSnapshotsInSF(t *testing.T) { }, }, inputDetails: true, - expect: map[string]interface{}{ - "nativeSnapshots": map[string]interface{}{ + expect: map[string]any{ + "nativeSnapshots": map[string]any{ "pv-1": map[string]string{ "snapshotID": "snapshot-1", "type": "ebs", @@ -337,7 +337,7 @@ func TestDescribeNativeSnapshotsInSF(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(tt *testing.T) { - output := make(map[string]interface{}) + output := make(map[string]any) describeNativeSnapshotsInSF(tc.inputDetails, tc.volumeInfo, output) assert.True(tt, reflect.DeepEqual(output, tc.expect)) }) @@ -349,13 +349,13 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { name string volumeInfo []*volume.BackupVolumeInfo inputDetails bool - expect map[string]interface{} + expect map[string]any legacyInfoSource bool }{ { name: "empty info, not legacy", volumeInfo: []*volume.BackupVolumeInfo{}, - expect: map[string]interface{}{ + expect: map[string]any{ "csiSnapshots": "", }, }, @@ -363,7 +363,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { name: "empty info, legacy", volumeInfo: []*volume.BackupVolumeInfo{}, legacyInfoSource: true, - expect: map[string]interface{}{ + expect: map[string]any{ "csiSnapshots": "", }, }, @@ -384,9 +384,9 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { }, }, }, - expect: map[string]interface{}{ - "csiSnapshots": map[string]interface{}{ - "pvc-ns-1/pvc-1": map[string]interface{}{ + expect: map[string]any{ + "csiSnapshots": map[string]any{ + "pvc-ns-1/pvc-1": map[string]any{ "snapshot": "included, specify --details for more information", }, }, @@ -411,10 +411,10 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { }, }, inputDetails: true, - expect: map[string]interface{}{ - "csiSnapshots": map[string]interface{}{ - "pvc-ns-2/pvc-2": map[string]interface{}{ - "snapshot": map[string]interface{}{ + expect: map[string]any{ + "csiSnapshots": map[string]any{ + "pvc-ns-2/pvc-2": map[string]any{ + "snapshot": map[string]any{ "operationID": "fake-operation-2", "snapshotContentName": "vsc-2", "storageSnapshotID": "snapshot-2", @@ -442,9 +442,9 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { }, }, }, - expect: map[string]interface{}{ - "csiSnapshots": map[string]interface{}{ - "pvc-ns-3/pvc-3": map[string]interface{}{ + expect: map[string]any{ + "csiSnapshots": map[string]any{ + "pvc-ns-3/pvc-3": map[string]any{ "dataMovement": "included, specify --details for more information", }, }, @@ -468,10 +468,10 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { }, }, inputDetails: true, - expect: map[string]interface{}{ - "csiSnapshots": map[string]interface{}{ - "pvc-ns-4/pvc-4": map[string]interface{}{ - "dataMovement": map[string]interface{}{ + expect: map[string]any{ + "csiSnapshots": map[string]any{ + "pvc-ns-4/pvc-4": map[string]any{ + "dataMovement": map[string]any{ "operationID": "fake-operation-4", "dataMover": "velero", "uploaderType": "fake-uploader", @@ -498,10 +498,10 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { }, }, inputDetails: true, - expect: map[string]interface{}{ - "csiSnapshots": map[string]interface{}{ - "pvc-ns-4/pvc-4": map[string]interface{}{ - "dataMovement": map[string]interface{}{ + expect: map[string]any{ + "csiSnapshots": map[string]any{ + "pvc-ns-4/pvc-4": map[string]any{ + "dataMovement": map[string]any{ "operationID": "fake-operation-4", "dataMover": "velero", "uploaderType": "fake-uploader", @@ -515,7 +515,7 @@ func TestDescribeCSISnapshotsInSF(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(tt *testing.T) { - output := make(map[string]interface{}) + output := make(map[string]any) describeCSISnapshotsInSF(tc.inputDetails, tc.volumeInfo, output, tc.legacyInfoSource) assert.True(tt, reflect.DeepEqual(output, tc.expect)) }) @@ -527,14 +527,14 @@ func TestDescribeResourcePoliciesInSF(t *testing.T) { Kind: "configmap", Name: "resource-policy-1", } - expect := map[string]interface{}{ - "resourcePolicies": map[string]interface{}{ + expect := map[string]any{ + "resourcePolicies": map[string]any{ "type": "configmap", "name": "resource-policy-1", }, } sd := &StructuredDescriber{ - output: make(map[string]interface{}), + output: make(map[string]any), format: "", } DescribeResourcePoliciesInSF(sd, input) @@ -549,8 +549,8 @@ func TestDescribeBackupResultInSF(t *testing.T) { "ns-1": {"ns-1-msg-1", "ns-1-msg-2"}, }, } - got := map[string]interface{}{} - expect := map[string]interface{}{ + got := map[string]any{} + expect := map[string]any{ "velero": []string{"msg-1", "msg-2"}, "cluster": []string{"cluster-1", "cluster-2"}, "namespace": map[string][]string{ @@ -579,24 +579,24 @@ func TestDescribeDeleteBackupRequestsInSF(t *testing.T) { testcases := []struct { name string input []velerov1api.DeleteBackupRequest - expect map[string]interface{} + expect map[string]any }{ { name: "empty list", input: []velerov1api.DeleteBackupRequest{}, - expect: map[string]interface{}{ - "deletionAttempts": map[string]interface{}{ - "deleteBackupRequests": []map[string]interface{}{}, + expect: map[string]any{ + "deletionAttempts": map[string]any{ + "deleteBackupRequests": []map[string]any{}, }, }, }, { name: "list with one failed and one in-progress request", input: []velerov1api.DeleteBackupRequest{*dbr1, *dbr2}, - expect: map[string]interface{}{ - "deletionAttempts": map[string]interface{}{ + expect: map[string]any{ + "deletionAttempts": map[string]any{ "failed": int(1), - "deleteBackupRequests": []map[string]interface{}{ + "deleteBackupRequests": []map[string]any{ { "creationTimestamp": t1.String(), "phase": velerov1api.DeleteBackupRequestPhaseProcessed, @@ -616,7 +616,7 @@ func TestDescribeDeleteBackupRequestsInSF(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(tt *testing.T) { sd := &StructuredDescriber{ - output: make(map[string]interface{}), + output: make(map[string]any), format: "", } DescribeDeleteBackupRequestsInSF(sd, tc.input) diff --git a/pkg/cmd/util/output/describe.go b/pkg/cmd/util/output/describe.go index c0ec080281..049308a035 100644 --- a/pkg/cmd/util/output/describe.go +++ b/pkg/cmd/util/output/describe.go @@ -47,12 +47,12 @@ func Describe(fn func(d *Describer)) string { return d.buf.String() } -func (d *Describer) Printf(msg string, args ...interface{}) { +func (d *Describer) Printf(msg string, args ...any) { fmt.Fprint(d.out, d.Prefix) fmt.Fprintf(d.out, msg, args...) } -func (d *Describer) Println(args ...interface{}) { +func (d *Describer) Println(args ...any) { fmt.Fprint(d.out, d.Prefix) fmt.Fprintln(d.out, args...) } @@ -122,14 +122,14 @@ func BoolPointerString(b *bool, falseString, trueString, nilString string) strin } type StructuredDescriber struct { - output map[string]interface{} + output map[string]any format string } // NewStructuredDescriber creates a StructuredDescriber. func NewStructuredDescriber(format string) *StructuredDescriber { return &StructuredDescriber{ - output: make(map[string]interface{}), + output: make(map[string]any), format: format, } } @@ -144,13 +144,13 @@ func DescribeInSF(fn func(d *StructuredDescriber), format string) string { } // Describe adds all types of argument to d.output. -func (d *StructuredDescriber) Describe(name string, arg interface{}) { +func (d *StructuredDescriber) Describe(name string, arg any) { d.output[name] = arg } // DescribeMetadata describes standard object metadata. func (d *StructuredDescriber) DescribeMetadata(metadata metav1.ObjectMeta) { - metadataInfo := make(map[string]interface{}) + metadataInfo := make(map[string]any) metadataInfo["name"] = metadata.Name metadataInfo["namespace"] = metadata.Namespace metadataInfo["labels"] = metadata.Labels diff --git a/pkg/cmd/util/output/describe_test.go b/pkg/cmd/util/output/describe_test.go index 45becf8733..02e8cd53ee 100644 --- a/pkg/cmd/util/output/describe_test.go +++ b/pkg/cmd/util/output/describe_test.go @@ -106,17 +106,17 @@ func TestDescriber_DescribeSlice(t *testing.T) { func TestStructuredDescriber_JSONEncode(t *testing.T) { testcases := []struct { name string - inputMap map[string]interface{} + inputMap map[string]any expect string }{ { name: "invalid json", - inputMap: map[string]interface{}{}, + inputMap: map[string]any{}, expect: "{}\n", }, { name: "valid json", - inputMap: map[string]interface{}{"k1": "v1"}, + inputMap: map[string]any{"k1": "v1"}, expect: `{ "k1": "v1" } @@ -148,8 +148,8 @@ func TestStructuredDescriber_DescribeMetadata(t *testing.T) { "annotation-2": "v2", }, } - expect := map[string]interface{}{ - "metadata": map[string]interface{}{ + expect := map[string]any{ + "metadata": map[string]any{ "name": "test", "namespace": "test-ns", "labels": map[string]string{ diff --git a/pkg/controller/backup_repository_controller.go b/pkg/controller/backup_repository_controller.go index fe59529d48..f76e1de91b 100644 --- a/pkg/controller/backup_repository_controller.go +++ b/pkg/controller/backup_repository_controller.go @@ -548,7 +548,7 @@ func getBackupRepositoryConfig(ctx context.Context, ctrlClient client.Client, co return nil, nil } - var unmarshalled map[string]interface{} + var unmarshalled map[string]any if err := json.Unmarshal([]byte(jsonData), &unmarshalled); err != nil { return nil, errors.Wrapf(err, "error unmarshalling config data from %s for repo %s, repo type %s", configName, repoName, repoType) } diff --git a/pkg/controller/backup_repository_controller_test.go b/pkg/controller/backup_repository_controller_test.go index cb763fb8f7..f0fdebbf5a 100644 --- a/pkg/controller/backup_repository_controller_test.go +++ b/pkg/controller/backup_repository_controller_test.go @@ -46,7 +46,7 @@ import ( const testMaintenanceFrequency = 10 * time.Minute -func mockBackupRepoReconciler(t *testing.T, mockOn string, arg interface{}, ret ...interface{}) *BackupRepoReconciler { +func mockBackupRepoReconciler(t *testing.T, mockOn string, arg any, ret ...any) *BackupRepoReconciler { t.Helper() mgr := &repomokes.Manager{} if mockOn != "" { diff --git a/pkg/controller/data_upload_controller.go b/pkg/controller/data_upload_controller.go index 3185373c14..182d9da8c6 100644 --- a/pkg/controller/data_upload_controller.go +++ b/pkg/controller/data_upload_controller.go @@ -796,7 +796,7 @@ func (r *DataUploadReconciler) closeDataPath(ctx context.Context, duName string) r.dataPathMgr.RemoveAsyncBR(duName) } -func (r *DataUploadReconciler) setupExposeParam(du *velerov2alpha1api.DataUpload) (interface{}, error) { +func (r *DataUploadReconciler) setupExposeParam(du *velerov2alpha1api.DataUpload) (any, error) { log := r.logger.WithField("dataupload", du.Name) if du.Spec.SnapshotType == velerov2alpha1api.SnapshotTypeCSI { @@ -854,7 +854,7 @@ func (r *DataUploadReconciler) setupExposeParam(du *velerov2alpha1api.DataUpload return nil, nil } -func (r *DataUploadReconciler) setupWaitExposePara(du *velerov2alpha1api.DataUpload) interface{} { +func (r *DataUploadReconciler) setupWaitExposePara(du *velerov2alpha1api.DataUpload) any { if du.Spec.SnapshotType == velerov2alpha1api.SnapshotTypeCSI { return &exposer.CSISnapshotExposeWaitParam{ NodeClient: r.client, diff --git a/pkg/controller/data_upload_controller_test.go b/pkg/controller/data_upload_controller_test.go index 0a02108692..379b876b5d 100644 --- a/pkg/controller/data_upload_controller_test.go +++ b/pkg/controller/data_upload_controller_test.go @@ -272,7 +272,7 @@ type fakeSnapshotExposer struct { peekErr error } -func (f *fakeSnapshotExposer) Expose(ctx context.Context, ownerObject corev1.ObjectReference, param interface{}) error { +func (f *fakeSnapshotExposer) Expose(ctx context.Context, ownerObject corev1.ObjectReference, param any) error { du := velerov2alpha1api.DataUpload{} err := f.kubeClient.Get(ctx, kbclient.ObjectKey{ Name: dataUploadName, @@ -289,7 +289,7 @@ func (f *fakeSnapshotExposer) Expose(ctx context.Context, ownerObject corev1.Obj return nil } -func (f *fakeSnapshotExposer) GetExposed(ctx context.Context, du corev1.ObjectReference, tm time.Duration, para interface{}) (*exposer.ExposeResult, error) { +func (f *fakeSnapshotExposer) GetExposed(ctx context.Context, du corev1.ObjectReference, tm time.Duration, para any) (*exposer.ExposeResult, error) { pod := &corev1.Pod{} err := f.kubeClient.Get(ctx, kbclient.ObjectKey{ Name: dataUploadName, @@ -326,11 +326,11 @@ type fakeDataUploadFSBR struct { startErr error } -func (f *fakeDataUploadFSBR) Init(ctx context.Context, param interface{}) error { +func (f *fakeDataUploadFSBR) Init(ctx context.Context, param any) error { return f.initErr } -func (f *fakeDataUploadFSBR) StartBackup(source datapath.AccessPoint, uploaderConfigs map[string]string, param interface{}) error { +func (f *fakeDataUploadFSBR) StartBackup(source datapath.AccessPoint, uploaderConfigs map[string]string, param any) error { return f.startErr } @@ -1087,11 +1087,11 @@ func (dt *duResumeTestHelper) resumeCancellableDataPath(_ *DataUploadReconciler, return dt.resumeErr } -func (dt *duResumeTestHelper) Expose(context.Context, corev1.ObjectReference, interface{}) error { +func (dt *duResumeTestHelper) Expose(context.Context, corev1.ObjectReference, any) error { return nil } -func (dt *duResumeTestHelper) GetExposed(context.Context, corev1.ObjectReference, time.Duration, interface{}) (*exposer.ExposeResult, error) { +func (dt *duResumeTestHelper) GetExposed(context.Context, corev1.ObjectReference, time.Duration, any) (*exposer.ExposeResult, error) { return dt.exposeResult, dt.getExposeErr } diff --git a/pkg/controller/pod_volume_backup_controller.go b/pkg/controller/pod_volume_backup_controller.go index dad1593032..53f7129b8a 100644 --- a/pkg/controller/pod_volume_backup_controller.go +++ b/pkg/controller/pod_volume_backup_controller.go @@ -348,7 +348,7 @@ func (r *PodVolumeBackupReconciler) getParentSnapshot(ctx context.Context, log l return "" } - log.WithFields(map[string]interface{}{ + log.WithFields(map[string]any{ "parentPodVolumeBackup": mostRecentPVB.Name, "parentSnapshotID": mostRecentPVB.Status.SnapshotID, }).Info("Found most recent completed PodVolumeBackup for PVC") diff --git a/pkg/controller/pod_volume_backup_controller_test.go b/pkg/controller/pod_volume_backup_controller_test.go index 1b4d408e4a..0affc406fa 100644 --- a/pkg/controller/pod_volume_backup_controller_test.go +++ b/pkg/controller/pod_volume_backup_controller_test.go @@ -97,11 +97,11 @@ type fakeFSBR struct { clock clock.WithTickerAndDelayedExecution } -func (b *fakeFSBR) Init(ctx context.Context, param interface{}) error { +func (b *fakeFSBR) Init(ctx context.Context, param any) error { return nil } -func (b *fakeFSBR) StartBackup(source datapath.AccessPoint, uploaderConfigs map[string]string, param interface{}) error { +func (b *fakeFSBR) StartBackup(source datapath.AccessPoint, uploaderConfigs map[string]string, param any) error { pvb := b.pvb original := b.pvb.DeepCopy() diff --git a/pkg/datamover/backup_micro_service.go b/pkg/datamover/backup_micro_service.go index de77204a84..3c6601cbf5 100644 --- a/pkg/datamover/backup_micro_service.go +++ b/pkg/datamover/backup_micro_service.go @@ -99,7 +99,7 @@ func (r *BackupMicroService) Init() error { handler, err := r.duInformer.AddEventHandler( cachetool.ResourceEventHandlerFuncs{ - UpdateFunc: func(oldObj interface{}, newObj interface{}) { + UpdateFunc: func(oldObj any, newObj any) { oldDu := oldObj.(*velerov2alpha1api.DataUpload) newDu := newObj.(*velerov2alpha1api.DataUpload) diff --git a/pkg/datamover/restore_micro_service.go b/pkg/datamover/restore_micro_service.go index 1746366c9d..25a3f3ff38 100644 --- a/pkg/datamover/restore_micro_service.go +++ b/pkg/datamover/restore_micro_service.go @@ -88,7 +88,7 @@ func (r *RestoreMicroService) Init() error { handler, err := r.ddInformer.AddEventHandler( cachetool.ResourceEventHandlerFuncs{ - UpdateFunc: func(oldObj interface{}, newObj interface{}) { + UpdateFunc: func(oldObj any, newObj any) { oldDd := oldObj.(*velerov2alpha1api.DataDownload) newDd := newObj.(*velerov2alpha1api.DataDownload) diff --git a/pkg/datapath/file_system.go b/pkg/datapath/file_system.go index 277012e9a4..7e8b292dff 100644 --- a/pkg/datapath/file_system.go +++ b/pkg/datapath/file_system.go @@ -85,7 +85,7 @@ func newFileSystemBR(jobName string, requestorType string, client client.Client, return fs } -func (fs *fileSystemBR) Init(ctx context.Context, param interface{}) error { +func (fs *fileSystemBR) Init(ctx context.Context, param any) error { initParam := param.(*FSBRInitParam) var err error @@ -164,7 +164,7 @@ func (fs *fileSystemBR) close(ctx context.Context) { } } -func (fs *fileSystemBR) StartBackup(source AccessPoint, uploaderConfig map[string]string, param interface{}) error { +func (fs *fileSystemBR) StartBackup(source AccessPoint, uploaderConfig map[string]string, param any) error { if !fs.initialized { return errors.New("file system data path is not initialized") } diff --git a/pkg/datapath/micro_service_watcher.go b/pkg/datapath/micro_service_watcher.go index 02c99299c4..dbe3bd0954 100644 --- a/pkg/datapath/micro_service_watcher.go +++ b/pkg/datapath/micro_service_watcher.go @@ -104,7 +104,7 @@ func newMicroServiceBRWatcher(client client.Client, kubeClient kubernetes.Interf return ms } -func (ms *microServiceBRWatcher) Init(ctx context.Context, param interface{}) error { +func (ms *microServiceBRWatcher) Init(ctx context.Context, param any) error { eventInformer, err := ms.mgr.GetCache().GetInformer(ctx, &v1.Event{}) if err != nil { return errors.Wrap(err, "error getting event informer") @@ -117,7 +117,7 @@ func (ms *microServiceBRWatcher) Init(ctx context.Context, param interface{}) er eventHandler, err := eventInformer.AddEventHandler( cache.ResourceEventHandlerFuncs{ - AddFunc: func(obj interface{}) { + AddFunc: func(obj any) { evt := obj.(*v1.Event) if evt.InvolvedObject.Namespace != ms.namespace || evt.InvolvedObject.Name != ms.associatedObject { return @@ -125,7 +125,7 @@ func (ms *microServiceBRWatcher) Init(ctx context.Context, param interface{}) er ms.eventCh <- evt }, - UpdateFunc: func(_, obj interface{}) { + UpdateFunc: func(_, obj any) { evt := obj.(*v1.Event) if evt.InvolvedObject.Namespace != ms.namespace || evt.InvolvedObject.Name != ms.associatedObject { return @@ -141,7 +141,7 @@ func (ms *microServiceBRWatcher) Init(ctx context.Context, param interface{}) er podHandler, err := podInformer.AddEventHandler( cache.ResourceEventHandlerFuncs{ - UpdateFunc: func(_, obj interface{}) { + UpdateFunc: func(_, obj any) { pod := obj.(*v1.Pod) if pod.Namespace != ms.namespace || pod.Name != ms.thisPod { return @@ -213,7 +213,7 @@ func (ms *microServiceBRWatcher) close() { } } -func (ms *microServiceBRWatcher) StartBackup(source AccessPoint, uploaderConfig map[string]string, param interface{}) error { +func (ms *microServiceBRWatcher) StartBackup(source AccessPoint, uploaderConfig map[string]string, param any) error { ms.log.Infof("Start watching backup ms for source %v", source.ByPath) ms.startWatch() diff --git a/pkg/datapath/types.go b/pkg/datapath/types.go index f4315b4472..52b9bddd6a 100644 --- a/pkg/datapath/types.go +++ b/pkg/datapath/types.go @@ -59,10 +59,10 @@ type AccessPoint struct { // AsyncBR is the interface for asynchronous data path methods type AsyncBR interface { // Init initializes an asynchronous data path instance - Init(ctx context.Context, param interface{}) error + Init(ctx context.Context, param any) error // StartBackup starts an asynchronous data path instance for backup - StartBackup(source AccessPoint, dataMoverConfig map[string]string, param interface{}) error + StartBackup(source AccessPoint, dataMoverConfig map[string]string, param any) error // StartRestore starts an asynchronous data path instance for restore StartRestore(snapshotID string, target AccessPoint, dataMoverConfig map[string]string) error diff --git a/pkg/exposer/csi_snapshot.go b/pkg/exposer/csi_snapshot.go index cfc34cc926..ae74c76eee 100644 --- a/pkg/exposer/csi_snapshot.go +++ b/pkg/exposer/csi_snapshot.go @@ -100,7 +100,7 @@ type csiSnapshotExposer struct { log logrus.FieldLogger } -func (e *csiSnapshotExposer) Expose(ctx context.Context, ownerObject corev1.ObjectReference, param interface{}) error { +func (e *csiSnapshotExposer) Expose(ctx context.Context, ownerObject corev1.ObjectReference, param any) error { csiExposeParam := param.(*CSISnapshotExposeParam) curLog := e.log.WithFields(logrus.Fields{ @@ -232,7 +232,7 @@ func (e *csiSnapshotExposer) Expose(ctx context.Context, ownerObject corev1.Obje return nil } -func (e *csiSnapshotExposer) GetExposed(ctx context.Context, ownerObject corev1.ObjectReference, timeout time.Duration, param interface{}) (*ExposeResult, error) { +func (e *csiSnapshotExposer) GetExposed(ctx context.Context, ownerObject corev1.ObjectReference, timeout time.Duration, param any) (*ExposeResult, error) { exposeWaitParam := param.(*CSISnapshotExposeWaitParam) backupPodName := ownerObject.Name diff --git a/pkg/exposer/snapshot.go b/pkg/exposer/snapshot.go index a4a6bd7df2..257ba34318 100644 --- a/pkg/exposer/snapshot.go +++ b/pkg/exposer/snapshot.go @@ -26,11 +26,11 @@ import ( // SnapshotExposer is the interfaces for a snapshot exposer type SnapshotExposer interface { // Expose starts the process to expose a snapshot, the expose process may take long time - Expose(context.Context, corev1.ObjectReference, interface{}) error + Expose(context.Context, corev1.ObjectReference, any) error // GetExposed polls the status of the expose. // If the expose is accessible by the current caller, it waits the expose ready and returns the expose result. // Otherwise, it returns nil as the expose result without an error. - GetExposed(context.Context, corev1.ObjectReference, time.Duration, interface{}) (*ExposeResult, error) + GetExposed(context.Context, corev1.ObjectReference, time.Duration, any) (*ExposeResult, error) // PeekExposed tests the status of the expose. // If the expose is incomplete but not recoverable, it returns an error. diff --git a/pkg/install/install.go b/pkg/install/install.go index 391b97ec1b..942761b21f 100644 --- a/pkg/install/install.go +++ b/pkg/install/install.go @@ -284,7 +284,7 @@ func createResource(r *unstructured.Unstructured, factory client.DynamicFactory, id := fmt.Sprintf("%s/%s", r.GetKind(), r.GetName()) // Helper to reduce boilerplate message about the same object - log := func(f string, a ...interface{}) { + log := func(f string, a ...any) { format := strings.Join([]string{id, ": ", f, "\n"}, "") fmt.Fprintf(w, format, a...) } @@ -310,7 +310,7 @@ func CreateClient(r *unstructured.Unstructured, factory client.DynamicFactory, w id := fmt.Sprintf("%s/%s", r.GetKind(), r.GetName()) // Helper to reduce boilerplate message about the same object - log := func(f string, a ...interface{}) { + log := func(f string, a ...any) { format := strings.Join([]string{id, ": ", f, "\n"}, "") fmt.Fprintf(w, format, a...) } diff --git a/pkg/itemblock/actions/pvc_action.go b/pkg/itemblock/actions/pvc_action.go index 4ec99d03b9..eee4e2fb35 100644 --- a/pkg/itemblock/actions/pvc_action.go +++ b/pkg/itemblock/actions/pvc_action.go @@ -42,7 +42,7 @@ type PVCAction struct { } func NewPVCAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { crClient, err := f.KubebuilderClient() if err != nil { return nil, errors.WithStack(err) diff --git a/pkg/persistence/object_store.go b/pkg/persistence/object_store.go index 5cdb36b6f0..bfdc8fbdc1 100644 --- a/pkg/persistence/object_store.go +++ b/pkg/persistence/object_store.go @@ -187,7 +187,7 @@ func (b *objectBackupStoreGetter) Get(location *velerov1api.BackupStorageLocatio return nil, err } - log := logger.WithFields(logrus.Fields(map[string]interface{}{ + log := logger.WithFields(logrus.Fields(map[string]any{ "bucket": bucket, "prefix": prefix, })) @@ -410,7 +410,7 @@ func tryGet(objectStore velero.ObjectStore, bucket, key string) (io.ReadCloser, // decode extracts a .json.gz file reader into the object pointed to // by 'into'. -func decode(jsongzReader io.Reader, into interface{}) error { +func decode(jsongzReader io.Reader, into any) error { gzr, err := gzip.NewReader(jsongzReader) if err != nil { return errors.WithStack(err) diff --git a/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action_test.go b/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action_test.go index ce8d072614..0064280353 100644 --- a/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action_test.go +++ b/pkg/plugin/clientmgmt/backupitemaction/v1/restartable_backup_item_action_test.go @@ -36,7 +36,7 @@ import ( func TestRestartableGetBackupItemAction(t *testing.T) { tests := []struct { name string - plugin interface{} + plugin any getError error expectedError string }{ @@ -105,13 +105,13 @@ func TestRestartableBackupItemActionDelegatedFunctions(t *testing.T) { b := new(v1.Backup) pv := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "blue", }, } pvToReturn := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "green", }, } @@ -125,7 +125,7 @@ func TestRestartableBackupItemActionDelegatedFunctions(t *testing.T) { restartabletest.RunRestartableDelegateTests( t, common.PluginKindBackupItemAction, - func(key process.KindAndName, p process.RestartableProcess) interface{} { + func(key process.KindAndName, p process.RestartableProcess) any { return &RestartableBackupItemAction{ Key: key, SharedPluginProcess: p, @@ -136,15 +136,15 @@ func TestRestartableBackupItemActionDelegatedFunctions(t *testing.T) { }, restartabletest.RestartableDelegateTest{ Function: "AppliesTo", - Inputs: []interface{}{}, - ExpectedErrorOutputs: []interface{}{velero.ResourceSelector{}, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, + Inputs: []any{}, + ExpectedErrorOutputs: []any{velero.ResourceSelector{}, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "Execute", - Inputs: []interface{}{pv, b}, - ExpectedErrorOutputs: []interface{}{nil, ([]velero.ResourceIdentifier)(nil), errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{pvToReturn, additionalItems, errors.Errorf("delegate error")}, + Inputs: []any{pv, b}, + ExpectedErrorOutputs: []any{nil, ([]velero.ResourceIdentifier)(nil), errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{pvToReturn, additionalItems, errors.Errorf("delegate error")}, }, ) } diff --git a/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action_test.go b/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action_test.go index efcb94927c..77cdea74c1 100644 --- a/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action_test.go +++ b/pkg/plugin/clientmgmt/backupitemaction/v2/restartable_backup_item_action_test.go @@ -36,7 +36,7 @@ import ( func TestRestartableGetBackupItemAction(t *testing.T) { tests := []struct { name string - plugin interface{} + plugin any getError error expectedError string }{ @@ -105,7 +105,7 @@ func TestRestartableBackupItemActionDelegatedFunctions(t *testing.T) { b := new(v1.Backup) pv := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "blue", }, } @@ -113,7 +113,7 @@ func TestRestartableBackupItemActionDelegatedFunctions(t *testing.T) { oid := "operation1" pvToReturn := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "green", }, } @@ -127,7 +127,7 @@ func TestRestartableBackupItemActionDelegatedFunctions(t *testing.T) { restartabletest.RunRestartableDelegateTests( t, common.PluginKindBackupItemAction, - func(key process.KindAndName, p process.RestartableProcess) interface{} { + func(key process.KindAndName, p process.RestartableProcess) any { return &RestartableBackupItemAction{ Key: key, SharedPluginProcess: p, @@ -138,27 +138,27 @@ func TestRestartableBackupItemActionDelegatedFunctions(t *testing.T) { }, restartabletest.RestartableDelegateTest{ Function: "AppliesTo", - Inputs: []interface{}{}, - ExpectedErrorOutputs: []interface{}{velero.ResourceSelector{}, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, + Inputs: []any{}, + ExpectedErrorOutputs: []any{velero.ResourceSelector{}, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "Execute", - Inputs: []interface{}{pv, b}, - ExpectedErrorOutputs: []interface{}{nil, ([]velero.ResourceIdentifier)(nil), "", ([]velero.ResourceIdentifier)(nil), errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{pvToReturn, additionalItems, "", ([]velero.ResourceIdentifier)(nil), errors.Errorf("delegate error")}, + Inputs: []any{pv, b}, + ExpectedErrorOutputs: []any{nil, ([]velero.ResourceIdentifier)(nil), "", ([]velero.ResourceIdentifier)(nil), errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{pvToReturn, additionalItems, "", ([]velero.ResourceIdentifier)(nil), errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "Progress", - Inputs: []interface{}{oid, b}, - ExpectedErrorOutputs: []interface{}{velero.OperationProgress{}, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{velero.OperationProgress{}, errors.Errorf("delegate error")}, + Inputs: []any{oid, b}, + ExpectedErrorOutputs: []any{velero.OperationProgress{}, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{velero.OperationProgress{}, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "Cancel", - Inputs: []interface{}{oid, b}, - ExpectedErrorOutputs: []interface{}{errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{errors.Errorf("delegate error")}, + Inputs: []any{oid, b}, + ExpectedErrorOutputs: []any{errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{errors.Errorf("delegate error")}, }, ) } diff --git a/pkg/plugin/clientmgmt/itemblockaction/v1/restartable_item_block_action_test.go b/pkg/plugin/clientmgmt/itemblockaction/v1/restartable_item_block_action_test.go index eeec9c74c5..80bb5aeaf5 100644 --- a/pkg/plugin/clientmgmt/itemblockaction/v1/restartable_item_block_action_test.go +++ b/pkg/plugin/clientmgmt/itemblockaction/v1/restartable_item_block_action_test.go @@ -36,7 +36,7 @@ import ( func TestRestartableGetItemBlockAction(t *testing.T) { tests := []struct { name string - plugin interface{} + plugin any getError error expectedError string }{ @@ -105,7 +105,7 @@ func TestRestartableItemBlockActionDelegatedFunctions(t *testing.T) { b := new(v1.Backup) pv := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "blue", }, } @@ -119,7 +119,7 @@ func TestRestartableItemBlockActionDelegatedFunctions(t *testing.T) { restartabletest.RunRestartableDelegateTests( t, common.PluginKindItemBlockAction, - func(key process.KindAndName, p process.RestartableProcess) interface{} { + func(key process.KindAndName, p process.RestartableProcess) any { return &RestartableItemBlockAction{ Key: key, SharedPluginProcess: p, @@ -130,15 +130,15 @@ func TestRestartableItemBlockActionDelegatedFunctions(t *testing.T) { }, restartabletest.RestartableDelegateTest{ Function: "AppliesTo", - Inputs: []interface{}{}, - ExpectedErrorOutputs: []interface{}{velero.ResourceSelector{}, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, + Inputs: []any{}, + ExpectedErrorOutputs: []any{velero.ResourceSelector{}, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "GetRelatedItems", - Inputs: []interface{}{pv, b}, - ExpectedErrorOutputs: []interface{}{([]velero.ResourceIdentifier)(nil), errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{relatedItems, errors.Errorf("delegate error")}, + Inputs: []any{pv, b}, + ExpectedErrorOutputs: []any{([]velero.ResourceIdentifier)(nil), errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{relatedItems, errors.Errorf("delegate error")}, }, ) } diff --git a/pkg/plugin/clientmgmt/manager_test.go b/pkg/plugin/clientmgmt/manager_test.go index 8e15bbf503..e3e9e41c13 100644 --- a/pkg/plugin/clientmgmt/manager_test.go +++ b/pkg/plugin/clientmgmt/manager_test.go @@ -159,10 +159,10 @@ func TestGetObjectStore(t *testing.T) { getPluginTest(t, common.PluginKindObjectStore, "velero.io/aws", - func(m Manager, name string) (interface{}, error) { + func(m Manager, name string) (any, error) { return m.GetObjectStore(name) }, - func(name string, sharedPluginProcess process.RestartableProcess) interface{} { + func(name string, sharedPluginProcess process.RestartableProcess) any { return &restartableObjectStore{ key: process.KindAndName{Kind: common.PluginKindObjectStore, Name: name}, sharedPluginProcess: sharedPluginProcess, @@ -176,10 +176,10 @@ func TestGetVolumeSnapshotter(t *testing.T) { getPluginTest(t, common.PluginKindVolumeSnapshotter, "velero.io/aws", - func(m Manager, name string) (interface{}, error) { + func(m Manager, name string) (any, error) { return m.GetVolumeSnapshotter(name) }, - func(name string, sharedPluginProcess process.RestartableProcess) interface{} { + func(name string, sharedPluginProcess process.RestartableProcess) any { return &vsv1cli.RestartableVolumeSnapshotter{ Key: process.KindAndName{Kind: common.PluginKindVolumeSnapshotter, Name: name}, SharedPluginProcess: sharedPluginProcess, @@ -193,10 +193,10 @@ func TestGetBackupItemAction(t *testing.T) { getPluginTest(t, common.PluginKindBackupItemAction, "velero.io/pod", - func(m Manager, name string) (interface{}, error) { + func(m Manager, name string) (any, error) { return m.GetBackupItemAction(name) }, - func(name string, sharedPluginProcess process.RestartableProcess) interface{} { + func(name string, sharedPluginProcess process.RestartableProcess) any { return &biav1cli.RestartableBackupItemAction{ Key: process.KindAndName{Kind: common.PluginKindBackupItemAction, Name: name}, SharedPluginProcess: sharedPluginProcess, @@ -210,10 +210,10 @@ func TestGetBackupItemActionV2(t *testing.T) { getPluginTest(t, common.PluginKindBackupItemActionV2, "velero.io/pod", - func(m Manager, name string) (interface{}, error) { + func(m Manager, name string) (any, error) { return m.GetBackupItemActionV2(name) }, - func(name string, sharedPluginProcess process.RestartableProcess) interface{} { + func(name string, sharedPluginProcess process.RestartableProcess) any { return &biav2cli.RestartableBackupItemAction{ Key: process.KindAndName{Kind: common.PluginKindBackupItemActionV2, Name: name}, SharedPluginProcess: sharedPluginProcess, @@ -227,10 +227,10 @@ func TestGetRestoreItemAction(t *testing.T) { getPluginTest(t, common.PluginKindRestoreItemAction, "velero.io/pod", - func(m Manager, name string) (interface{}, error) { + func(m Manager, name string) (any, error) { return m.GetRestoreItemAction(name) }, - func(name string, sharedPluginProcess process.RestartableProcess) interface{} { + func(name string, sharedPluginProcess process.RestartableProcess) any { return &riav1cli.RestartableRestoreItemAction{ Key: process.KindAndName{Kind: common.PluginKindRestoreItemAction, Name: name}, SharedPluginProcess: sharedPluginProcess, @@ -244,10 +244,10 @@ func TestGetRestoreItemActionV2(t *testing.T) { getPluginTest(t, common.PluginKindRestoreItemActionV2, "velero.io/pod", - func(m Manager, name string) (interface{}, error) { + func(m Manager, name string) (any, error) { return m.GetRestoreItemActionV2(name) }, - func(name string, sharedPluginProcess process.RestartableProcess) interface{} { + func(name string, sharedPluginProcess process.RestartableProcess) any { return &riav2cli.RestartableRestoreItemAction{ Key: process.KindAndName{Kind: common.PluginKindRestoreItemActionV2, Name: name}, SharedPluginProcess: sharedPluginProcess, @@ -261,10 +261,10 @@ func TestGetItemBlockAction(t *testing.T) { getPluginTest(t, common.PluginKindItemBlockAction, "velero.io/pod", - func(m Manager, name string) (interface{}, error) { + func(m Manager, name string) (any, error) { return m.GetItemBlockAction(name) }, - func(name string, sharedPluginProcess process.RestartableProcess) interface{} { + func(name string, sharedPluginProcess process.RestartableProcess) any { return &ibav1cli.RestartableItemBlockAction{ Key: process.KindAndName{Kind: common.PluginKindItemBlockAction, Name: name}, SharedPluginProcess: sharedPluginProcess, @@ -278,8 +278,8 @@ func getPluginTest( t *testing.T, kind common.PluginKind, name string, - getPluginFunc func(m Manager, name string) (interface{}, error), - expectedResultFunc func(name string, sharedPluginProcess process.RestartableProcess) interface{}, + getPluginFunc func(m Manager, name string) (any, error), + expectedResultFunc func(name string, sharedPluginProcess process.RestartableProcess) any, reinitializable bool, ) { t.Helper() @@ -373,7 +373,7 @@ func TestGetBackupItemActions(t *testing.T) { } registry.On("List", pluginKind).Return(pluginIDs) - var expectedActions []interface{} + var expectedActions []any for i := range pluginIDs { pluginID := pluginIDs[i] pluginName := pluginID.Name @@ -408,7 +408,7 @@ func TestGetBackupItemActions(t *testing.T) { assert.EqualError(t, err, "NewRestartableProcess") } else { require.NoError(t, err) - var actual []interface{} + var actual []any for i := range backupItemActions { actual = append(actual, backupItemActions[i]) } @@ -465,7 +465,7 @@ func TestGetBackupItemActionsV2(t *testing.T) { } registry.On("List", pluginKind).Return(pluginIDs) - var expectedActions []interface{} + var expectedActions []any for i := range pluginIDs { pluginID := pluginIDs[i] pluginName := pluginID.Name @@ -500,7 +500,7 @@ func TestGetBackupItemActionsV2(t *testing.T) { assert.EqualError(t, err, "NewRestartableProcess") } else { require.NoError(t, err) - var actual []interface{} + var actual []any for i := range backupItemActions { actual = append(actual, backupItemActions[i]) } @@ -557,7 +557,7 @@ func TestGetRestoreItemActions(t *testing.T) { } registry.On("List", pluginKind).Return(pluginIDs) - var expectedActions []interface{} + var expectedActions []any for i := range pluginIDs { pluginID := pluginIDs[i] pluginName := pluginID.Name @@ -592,7 +592,7 @@ func TestGetRestoreItemActions(t *testing.T) { assert.EqualError(t, err, "NewRestartableProcess") } else { require.NoError(t, err) - var actual []interface{} + var actual []any for i := range restoreItemActions { actual = append(actual, restoreItemActions[i]) } @@ -649,7 +649,7 @@ func TestGetRestoreItemActionsV2(t *testing.T) { } registry.On("List", pluginKind).Return(pluginIDs) - var expectedActions []interface{} + var expectedActions []any for i := range pluginIDs { pluginID := pluginIDs[i] pluginName := pluginID.Name @@ -684,7 +684,7 @@ func TestGetRestoreItemActionsV2(t *testing.T) { assert.EqualError(t, err, "NewRestartableProcess") } else { require.NoError(t, err) - var actual []interface{} + var actual []any for i := range restoreItemActions { actual = append(actual, restoreItemActions[i]) } @@ -698,10 +698,10 @@ func TestGetDeleteItemAction(t *testing.T) { getPluginTest(t, common.PluginKindDeleteItemAction, "velero.io/deleter", - func(m Manager, name string) (interface{}, error) { + func(m Manager, name string) (any, error) { return m.GetDeleteItemAction(name) }, - func(name string, sharedPluginProcess process.RestartableProcess) interface{} { + func(name string, sharedPluginProcess process.RestartableProcess) any { return &restartableDeleteItemAction{ key: process.KindAndName{Kind: common.PluginKindDeleteItemAction, Name: name}, sharedPluginProcess: sharedPluginProcess, @@ -758,7 +758,7 @@ func TestGetDeleteItemActions(t *testing.T) { } registry.On("List", pluginKind).Return(pluginIDs) - var expectedActions []interface{} + var expectedActions []any for i := range pluginIDs { pluginID := pluginIDs[i] pluginName := pluginID.Name @@ -793,7 +793,7 @@ func TestGetDeleteItemActions(t *testing.T) { assert.EqualError(t, err, "NewRestartableProcess") } else { require.NoError(t, err) - var actual []interface{} + var actual []any for i := range deleteItemActions { actual = append(actual, deleteItemActions[i]) } @@ -850,7 +850,7 @@ func TestGetItemBlockActions(t *testing.T) { } registry.On("List", pluginKind).Return(pluginIDs) - var expectedActions []interface{} + var expectedActions []any for i := range pluginIDs { pluginID := pluginIDs[i] pluginName := pluginID.Name @@ -885,7 +885,7 @@ func TestGetItemBlockActions(t *testing.T) { assert.EqualError(t, err, "NewRestartableProcess") } else { require.NoError(t, err) - var actual []interface{} + var actual []any for i := range itemBlockActions { actual = append(actual, itemBlockActions[i]) } diff --git a/pkg/plugin/clientmgmt/process/logrus_adapter.go b/pkg/plugin/clientmgmt/process/logrus_adapter.go index b8a8fb0247..da573284a7 100644 --- a/pkg/plugin/clientmgmt/process/logrus_adapter.go +++ b/pkg/plugin/clientmgmt/process/logrus_adapter.go @@ -37,8 +37,8 @@ type logrusAdapter struct { // args are alternating key, value pairs, where the keys // are expected to be strings, and values can be any type. -func argsToFields(args ...interface{}) logrus.Fields { - fields := make(map[string]interface{}) +func argsToFields(args ...any) logrus.Fields { + fields := make(map[string]any) for i := 0; i < len(args); i += 2 { switch args[i] { @@ -52,7 +52,7 @@ func argsToFields(args ...interface{}) logrus.Fields { // to log at based on the hclog-compatible `@level` field which // we're adding via HcLogLevelHook). default: - var val interface{} + var val any if i+1 < len(args) { val = args[i+1] } @@ -66,27 +66,27 @@ func argsToFields(args ...interface{}) logrus.Fields { // Trace emits a message and key/value pairs at the DEBUG level // (logrus doesn't have a TRACE level) -func (l *logrusAdapter) Trace(msg string, args ...interface{}) { +func (l *logrusAdapter) Trace(msg string, args ...any) { l.Debug(msg, args...) } // Debug emits a message and key/value pairs at the DEBUG level -func (l *logrusAdapter) Debug(msg string, args ...interface{}) { +func (l *logrusAdapter) Debug(msg string, args ...any) { l.impl.WithFields(argsToFields(args...)).Debug(msg) } // Info emits a message and key/value pairs at the INFO level -func (l *logrusAdapter) Info(msg string, args ...interface{}) { +func (l *logrusAdapter) Info(msg string, args ...any) { l.impl.WithFields(argsToFields(args...)).Info(msg) } // Warn emits a message and key/value pairs at the WARN level -func (l *logrusAdapter) Warn(msg string, args ...interface{}) { +func (l *logrusAdapter) Warn(msg string, args ...any) { l.impl.WithFields(argsToFields(args...)).Warn(msg) } // Error emits a message and key/value pairs at the ERROR level -func (l *logrusAdapter) Error(msg string, args ...interface{}) { +func (l *logrusAdapter) Error(msg string, args ...any) { l.impl.WithFields(argsToFields(args...)).Error(msg) } @@ -121,7 +121,7 @@ func (l *logrusAdapter) IsError() bool { } // With creates a sublogger that will always have the given key/value pairs -func (l *logrusAdapter) With(args ...interface{}) hclog.Logger { +func (l *logrusAdapter) With(args ...any) hclog.Logger { return &logrusAdapter{ impl: l.impl.WithFields(argsToFields(args...)), level: l.level, @@ -164,7 +164,7 @@ func (l *logrusAdapter) SetLevel(_ hclog.Level) { } // ImpliedArgs returns With key/value pairs -func (l *logrusAdapter) ImpliedArgs() []interface{} { +func (l *logrusAdapter) ImpliedArgs() []any { panic("not implemented") } @@ -172,7 +172,7 @@ func (l *logrusAdapter) ImpliedArgs() []interface{} { // keys must be strings // vals can be any type, but display is implementation specific // Emit a message and key/value pairs at a provided log level -func (l *logrusAdapter) Log(level hclog.Level, msg string, args ...interface{}) { +func (l *logrusAdapter) Log(level hclog.Level, msg string, args ...any) { switch level { case hclog.Trace: l.Trace(msg, args...) diff --git a/pkg/plugin/clientmgmt/process/logrus_adapter_test.go b/pkg/plugin/clientmgmt/process/logrus_adapter_test.go index 76fbc4f1c6..cf4ff77a1b 100644 --- a/pkg/plugin/clientmgmt/process/logrus_adapter_test.go +++ b/pkg/plugin/clientmgmt/process/logrus_adapter_test.go @@ -26,34 +26,34 @@ import ( func TestArgsToFields(t *testing.T) { tests := []struct { name string - args []interface{} + args []any expectedFields logrus.Fields }{ { name: "empty args results in empty map of fields", - args: []interface{}{}, - expectedFields: logrus.Fields(map[string]interface{}{}), + args: []any{}, + expectedFields: logrus.Fields(map[string]any{}), }, { name: "matching string keys/values are correctly set as fields", - args: []interface{}{"key-1", "value-1", "key-2", "value-2"}, - expectedFields: logrus.Fields(map[string]interface{}{ + args: []any{"key-1", "value-1", "key-2", "value-2"}, + expectedFields: logrus.Fields(map[string]any{ "key-1": "value-1", "key-2": "value-2", }), }, { name: "time/timestamp/level entries are removed", - args: []interface{}{"time", time.Now(), "key-1", "value-1", "timestamp", time.Now(), "key-2", "value-2", "level", "WARN"}, - expectedFields: logrus.Fields(map[string]interface{}{ + args: []any{"time", time.Now(), "key-1", "value-1", "timestamp", time.Now(), "key-2", "value-2", "level", "WARN"}, + expectedFields: logrus.Fields(map[string]any{ "key-1": "value-1", "key-2": "value-2", }), }, { name: "odd number of args adds the last arg as a field with a nil value", - args: []interface{}{"key-1", "value-1", "key-2", "value-2", "key-3"}, - expectedFields: logrus.Fields(map[string]interface{}{ + args: []any{"key-1", "value-1", "key-2", "value-2", "key-3"}, + expectedFields: logrus.Fields(map[string]any{ "key-1": "value-1", "key-2": "value-2", "key-3": nil, diff --git a/pkg/plugin/clientmgmt/process/process.go b/pkg/plugin/clientmgmt/process/process.go index 5ebb4a7a18..4d20a17847 100644 --- a/pkg/plugin/clientmgmt/process/process.go +++ b/pkg/plugin/clientmgmt/process/process.go @@ -40,7 +40,7 @@ func (pf *processFactory) newProcess(command string, logger logrus.FieldLogger, } type Process interface { - dispense(key KindAndName) (interface{}, error) + dispense(key KindAndName) (any, error) exited() bool kill() } @@ -97,7 +97,7 @@ func removeFeaturesFlag(args []string) []string { return commandArgs } -func (r *process) dispense(key KindAndName) (interface{}, error) { +func (r *process) dispense(key KindAndName) (any, error) { // This calls GRPCClient(clientConn) on the plugin instance registered for key.name. dispensed, err := r.protocolClient.Dispense(key.Kind.String()) if err != nil { diff --git a/pkg/plugin/clientmgmt/process/process_test.go b/pkg/plugin/clientmgmt/process/process_test.go index e65c890511..e67de8db9c 100644 --- a/pkg/plugin/clientmgmt/process/process_test.go +++ b/pkg/plugin/clientmgmt/process/process_test.go @@ -36,7 +36,7 @@ func (cp *mockClientProtocol) Close() error { return args.Error(0) } -func (cp *mockClientProtocol) Dispense(name string) (interface{}, error) { +func (cp *mockClientProtocol) Dispense(name string) (any, error) { args := cp.Called(name) return args.Get(0), args.Error(1) } @@ -50,7 +50,7 @@ type mockClientDispenser struct { mock.Mock } -func (cd *mockClientDispenser) ClientFor(name string) interface{} { +func (cd *mockClientDispenser) ClientFor(name string) any { args := cd.Called(name) return args.Get(0) } @@ -93,7 +93,7 @@ func TestDispense(t *testing.T) { clientDispenser := new(mockClientDispenser) defer clientDispenser.AssertExpectations(t) - var client interface{} + var client any key := KindAndName{} if tc.clientDispenser { diff --git a/pkg/plugin/clientmgmt/process/restartable_process.go b/pkg/plugin/clientmgmt/process/restartable_process.go index 21ed810225..e285f82daa 100644 --- a/pkg/plugin/clientmgmt/process/restartable_process.go +++ b/pkg/plugin/clientmgmt/process/restartable_process.go @@ -42,7 +42,7 @@ type RestartableProcess interface { AddReinitializer(key KindAndName, r Reinitializer) Reset() error ResetIfNeeded() error - GetByKindAndName(key KindAndName) (interface{}, error) + GetByKindAndName(key KindAndName) (any, error) Stop() } @@ -57,7 +57,7 @@ type restartableProcess struct { // lock guards all of the fields below lock sync.RWMutex process Process - plugins map[KindAndName]interface{} + plugins map[KindAndName]any reinitializers map[KindAndName]Reinitializer resetFailures int } @@ -65,7 +65,7 @@ type restartableProcess struct { // reinitializer is capable of reinitializing a restartable plugin instance using the newly dispensed plugin. type Reinitializer interface { // reinitialize reinitializes a restartable plugin instance using the newly dispensed plugin. - Reinitialize(dispensed interface{}) error + Reinitialize(dispensed any) error } // newRestartableProcess creates a new restartableProcess for the given command and options. @@ -74,7 +74,7 @@ func newRestartableProcess(command string, logger logrus.FieldLogger, logLevel l command: command, logger: logger, logLevel: logLevel, - plugins: make(map[KindAndName]interface{}), + plugins: make(map[KindAndName]any), reinitializers: make(map[KindAndName]Reinitializer), } @@ -118,7 +118,7 @@ func (p *restartableProcess) resetLH() error { // Redispense any previously dispensed plugins, reinitializing if necessary. // Start by creating a new map to hold the newly dispensed plugins. - newPlugins := make(map[KindAndName]interface{}) + newPlugins := make(map[KindAndName]any) for key := range p.plugins { // Re-dispense dispensed, err := p.process.dispense(key) @@ -160,7 +160,7 @@ func (p *restartableProcess) ResetIfNeeded() error { } // GetByKindAndName acquires the lock and calls getByKindAndNameLH. -func (p *restartableProcess) GetByKindAndName(key KindAndName) (interface{}, error) { +func (p *restartableProcess) GetByKindAndName(key KindAndName) (any, error) { p.lock.Lock() defer p.lock.Unlock() @@ -169,7 +169,7 @@ func (p *restartableProcess) GetByKindAndName(key KindAndName) (interface{}, err // getByKindAndNameLH returns the dispensed plugin for key. If the plugin hasn't been dispensed before, it dispenses a // new one. -func (p *restartableProcess) getByKindAndNameLH(key KindAndName) (interface{}, error) { +func (p *restartableProcess) getByKindAndNameLH(key KindAndName) (any, error) { dispensed, found := p.plugins[key] if found { return dispensed, nil diff --git a/pkg/plugin/clientmgmt/restartable_delete_item_action_test.go b/pkg/plugin/clientmgmt/restartable_delete_item_action_test.go index b6cf8d8366..98516c2e46 100644 --- a/pkg/plugin/clientmgmt/restartable_delete_item_action_test.go +++ b/pkg/plugin/clientmgmt/restartable_delete_item_action_test.go @@ -35,7 +35,7 @@ import ( func TestRestartableGetDeleteItemAction(t *testing.T) { tests := []struct { name string - plugin interface{} + plugin any getError error expectedError string }{ @@ -103,7 +103,7 @@ func TestRestartableDeleteItemActionGetDelegate(t *testing.T) { func TestRestartableDeleteItemActionDelegatedFunctions(t *testing.T) { pv := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "blue", }, } @@ -118,7 +118,7 @@ func TestRestartableDeleteItemActionDelegatedFunctions(t *testing.T) { restartabletest.RunRestartableDelegateTests( t, common.PluginKindDeleteItemAction, - func(key process.KindAndName, p process.RestartableProcess) interface{} { + func(key process.KindAndName, p process.RestartableProcess) any { return &restartableDeleteItemAction{ key: key, sharedPluginProcess: p, @@ -130,15 +130,15 @@ func TestRestartableDeleteItemActionDelegatedFunctions(t *testing.T) { }, restartabletest.RestartableDelegateTest{ Function: "AppliesTo", - Inputs: []interface{}{}, - ExpectedErrorOutputs: []interface{}{velero.ResourceSelector{}, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, + Inputs: []any{}, + ExpectedErrorOutputs: []any{velero.ResourceSelector{}, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "Execute", - Inputs: []interface{}{input}, - ExpectedErrorOutputs: []interface{}{errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{errors.Errorf("delegate error")}, + Inputs: []any{input}, + ExpectedErrorOutputs: []any{errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{errors.Errorf("delegate error")}, }, ) } diff --git a/pkg/plugin/clientmgmt/restartable_object_store.go b/pkg/plugin/clientmgmt/restartable_object_store.go index ac9ae4b875..6e66d4b3e8 100644 --- a/pkg/plugin/clientmgmt/restartable_object_store.go +++ b/pkg/plugin/clientmgmt/restartable_object_store.go @@ -54,7 +54,7 @@ func NewRestartableObjectStore(name string, sharedPluginProcess process.Restarta } // reinitialize reinitializes a re-dispensed plugin using the initial data passed to Init(). -func (r *restartableObjectStore) Reinitialize(dispensed interface{}) error { +func (r *restartableObjectStore) Reinitialize(dispensed any) error { objectStore, ok := dispensed.(velero.ObjectStore) if !ok { return errors.Errorf("plugin %T is not a ObjectStore", dispensed) diff --git a/pkg/plugin/clientmgmt/restartable_object_store_test.go b/pkg/plugin/clientmgmt/restartable_object_store_test.go index 04cdedda0e..38b92d9a06 100644 --- a/pkg/plugin/clientmgmt/restartable_object_store_test.go +++ b/pkg/plugin/clientmgmt/restartable_object_store_test.go @@ -35,7 +35,7 @@ import ( func TestRestartableGetObjectStore(t *testing.T) { tests := []struct { name string - plugin interface{} + plugin any getError error expectedError string }{ @@ -189,7 +189,7 @@ func TestRestartableObjectStoreDelegatedFunctions(t *testing.T) { restartabletest.RunRestartableDelegateTests( t, common.PluginKindObjectStore, - func(key process.KindAndName, p process.RestartableProcess) interface{} { + func(key process.KindAndName, p process.RestartableProcess) any { return &restartableObjectStore{ key: key, sharedPluginProcess: p, @@ -200,39 +200,39 @@ func TestRestartableObjectStoreDelegatedFunctions(t *testing.T) { }, restartabletest.RestartableDelegateTest{ Function: "PutObject", - Inputs: []interface{}{"bucket", "key", strings.NewReader("body")}, - ExpectedErrorOutputs: []interface{}{errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{errors.Errorf("delegate error")}, + Inputs: []any{"bucket", "key", strings.NewReader("body")}, + ExpectedErrorOutputs: []any{errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "GetObject", - Inputs: []interface{}{"bucket", "key"}, - ExpectedErrorOutputs: []interface{}{nil, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{io.NopCloser(strings.NewReader("object")), errors.Errorf("delegate error")}, + Inputs: []any{"bucket", "key"}, + ExpectedErrorOutputs: []any{nil, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{io.NopCloser(strings.NewReader("object")), errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "ListCommonPrefixes", - Inputs: []interface{}{"bucket", "prefix", "delimiter"}, - ExpectedErrorOutputs: []interface{}{([]string)(nil), errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{[]string{"a", "b"}, errors.Errorf("delegate error")}, + Inputs: []any{"bucket", "prefix", "delimiter"}, + ExpectedErrorOutputs: []any{([]string)(nil), errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{[]string{"a", "b"}, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "ListObjects", - Inputs: []interface{}{"bucket", "prefix"}, - ExpectedErrorOutputs: []interface{}{([]string)(nil), errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{[]string{"a", "b"}, errors.Errorf("delegate error")}, + Inputs: []any{"bucket", "prefix"}, + ExpectedErrorOutputs: []any{([]string)(nil), errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{[]string{"a", "b"}, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "DeleteObject", - Inputs: []interface{}{"bucket", "key"}, - ExpectedErrorOutputs: []interface{}{errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{errors.Errorf("delegate error")}, + Inputs: []any{"bucket", "key"}, + ExpectedErrorOutputs: []any{errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "CreateSignedURL", - Inputs: []interface{}{"bucket", "key", 30 * time.Minute}, - ExpectedErrorOutputs: []interface{}{"", errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{"signedURL", errors.Errorf("delegate error")}, + Inputs: []any{"bucket", "key", 30 * time.Minute}, + ExpectedErrorOutputs: []any{"", errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{"signedURL", errors.Errorf("delegate error")}, }, ) } diff --git a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go index e00a6fddae..1cc5f24d84 100644 --- a/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go +++ b/pkg/plugin/clientmgmt/restoreitemaction/v1/restartable_restore_item_action_test.go @@ -35,7 +35,7 @@ import ( func TestRestartableGetRestoreItemAction(t *testing.T) { tests := []struct { name string - plugin interface{} + plugin any getError error expectedError string }{ @@ -102,7 +102,7 @@ func TestRestartableRestoreItemActionGetDelegate(t *testing.T) { func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) { pv := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "blue", }, } @@ -115,7 +115,7 @@ func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) { output := &velero.RestoreItemActionExecuteOutput{ UpdatedItem: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "green", }, }, @@ -124,7 +124,7 @@ func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) { restartabletest.RunRestartableDelegateTests( t, common.PluginKindRestoreItemAction, - func(key process.KindAndName, p process.RestartableProcess) interface{} { + func(key process.KindAndName, p process.RestartableProcess) any { return &RestartableRestoreItemAction{ Key: key, SharedPluginProcess: p, @@ -135,15 +135,15 @@ func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) { }, restartabletest.RestartableDelegateTest{ Function: "AppliesTo", - Inputs: []interface{}{}, - ExpectedErrorOutputs: []interface{}{velero.ResourceSelector{}, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, + Inputs: []any{}, + ExpectedErrorOutputs: []any{velero.ResourceSelector{}, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "Execute", - Inputs: []interface{}{input}, - ExpectedErrorOutputs: []interface{}{nil, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{output, errors.Errorf("delegate error")}, + Inputs: []any{input}, + ExpectedErrorOutputs: []any{nil, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{output, errors.Errorf("delegate error")}, }, ) } diff --git a/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action_test.go b/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action_test.go index 73d4f81455..cc36e4f644 100644 --- a/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action_test.go +++ b/pkg/plugin/clientmgmt/restoreitemaction/v2/restartable_restore_item_action_test.go @@ -35,7 +35,7 @@ import ( func TestRestartableGetRestoreItemAction(t *testing.T) { tests := []struct { name string - plugin interface{} + plugin any getError error expectedError string }{ @@ -102,7 +102,7 @@ func TestRestartableRestoreItemActionGetDelegate(t *testing.T) { func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) { pv := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "blue", }, } @@ -115,7 +115,7 @@ func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) { output := &velero.RestoreItemActionExecuteOutput{ UpdatedItem: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "green", }, }, @@ -127,7 +127,7 @@ func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) { restartabletest.RunRestartableDelegateTests( t, common.PluginKindRestoreItemActionV2, - func(key process.KindAndName, p process.RestartableProcess) interface{} { + func(key process.KindAndName, p process.RestartableProcess) any { return &RestartableRestoreItemAction{ Key: key, SharedPluginProcess: p, @@ -138,33 +138,33 @@ func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) { }, restartabletest.RestartableDelegateTest{ Function: "AppliesTo", - Inputs: []interface{}{}, - ExpectedErrorOutputs: []interface{}{velero.ResourceSelector{}, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, + Inputs: []any{}, + ExpectedErrorOutputs: []any{velero.ResourceSelector{}, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "Execute", - Inputs: []interface{}{input}, - ExpectedErrorOutputs: []interface{}{nil, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{output, errors.Errorf("delegate error")}, + Inputs: []any{input}, + ExpectedErrorOutputs: []any{nil, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{output, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "Progress", - Inputs: []interface{}{oid, r}, - ExpectedErrorOutputs: []interface{}{velero.OperationProgress{}, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{velero.OperationProgress{}, errors.Errorf("delegate error")}, + Inputs: []any{oid, r}, + ExpectedErrorOutputs: []any{velero.OperationProgress{}, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{velero.OperationProgress{}, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "Cancel", - Inputs: []interface{}{oid, r}, - ExpectedErrorOutputs: []interface{}{errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{errors.Errorf("delegate error")}, + Inputs: []any{oid, r}, + ExpectedErrorOutputs: []any{errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "AreAdditionalItemsReady", - Inputs: []interface{}{additionalItems, r}, - ExpectedErrorOutputs: []interface{}{false, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{true, errors.Errorf("delegate error")}, + Inputs: []any{additionalItems, r}, + ExpectedErrorOutputs: []any{false, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{true, errors.Errorf("delegate error")}, }, ) } diff --git a/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter.go b/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter.go index a7d2b4223e..7aec39872c 100644 --- a/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter.go +++ b/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter.go @@ -69,7 +69,7 @@ func NewRestartableVolumeSnapshotter(name string, sharedPluginProcess process.Re } // reinitialize reinitializes a re-dispensed plugin using the initial data passed to Init(). -func (r *RestartableVolumeSnapshotter) Reinitialize(dispensed interface{}) error { +func (r *RestartableVolumeSnapshotter) Reinitialize(dispensed any) error { volumeSnapshotter, ok := dispensed.(vsv1.VolumeSnapshotter) if !ok { return errors.Errorf("plugin %T is not a VolumeSnapshotter", dispensed) diff --git a/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter_test.go b/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter_test.go index eaa3862896..d090daeb70 100644 --- a/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter_test.go +++ b/pkg/plugin/clientmgmt/volumesnapshotter/v1/restartable_volume_snapshotter_test.go @@ -34,7 +34,7 @@ import ( func TestRestartableGetVolumeSnapshotter(t *testing.T) { tests := []struct { name string - plugin interface{} + plugin any getError error expectedError string }{ @@ -186,13 +186,13 @@ func TestRestartableVolumeSnapshotterInit(t *testing.T) { func TestRestartableVolumeSnapshotterDelegatedFunctions(t *testing.T) { pv := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "blue", }, } pvToReturn := &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "color": "green", }, } @@ -200,7 +200,7 @@ func TestRestartableVolumeSnapshotterDelegatedFunctions(t *testing.T) { restartabletest.RunRestartableDelegateTests( t, common.PluginKindVolumeSnapshotter, - func(key process.KindAndName, p process.RestartableProcess) interface{} { + func(key process.KindAndName, p process.RestartableProcess) any { return &RestartableVolumeSnapshotter{ Key: key, SharedPluginProcess: p, @@ -211,39 +211,39 @@ func TestRestartableVolumeSnapshotterDelegatedFunctions(t *testing.T) { }, restartabletest.RestartableDelegateTest{ Function: "CreateVolumeFromSnapshot", - Inputs: []interface{}{"snapshotID", "volumeID", "volumeAZ", to.Ptr(int64(10000))}, - ExpectedErrorOutputs: []interface{}{"", errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{"volumeID", errors.Errorf("delegate error")}, + Inputs: []any{"snapshotID", "volumeID", "volumeAZ", to.Ptr(int64(10000))}, + ExpectedErrorOutputs: []any{"", errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{"volumeID", errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "GetVolumeID", - Inputs: []interface{}{pv}, - ExpectedErrorOutputs: []interface{}{"", errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{"volumeID", errors.Errorf("delegate error")}, + Inputs: []any{pv}, + ExpectedErrorOutputs: []any{"", errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{"volumeID", errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "SetVolumeID", - Inputs: []interface{}{pv, "volumeID"}, - ExpectedErrorOutputs: []interface{}{nil, errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{pvToReturn, errors.Errorf("delegate error")}, + Inputs: []any{pv, "volumeID"}, + ExpectedErrorOutputs: []any{nil, errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{pvToReturn, errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "GetVolumeInfo", - Inputs: []interface{}{"volumeID", "volumeAZ"}, - ExpectedErrorOutputs: []interface{}{"", (*int64)(nil), errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{"volumeType", to.Ptr(int64(10000)), errors.Errorf("delegate error")}, + Inputs: []any{"volumeID", "volumeAZ"}, + ExpectedErrorOutputs: []any{"", (*int64)(nil), errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{"volumeType", to.Ptr(int64(10000)), errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "CreateSnapshot", - Inputs: []interface{}{"volumeID", "volumeAZ", map[string]string{"a": "b"}}, - ExpectedErrorOutputs: []interface{}{"", errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{"snapshotID", errors.Errorf("delegate error")}, + Inputs: []any{"volumeID", "volumeAZ", map[string]string{"a": "b"}}, + ExpectedErrorOutputs: []any{"", errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{"snapshotID", errors.Errorf("delegate error")}, }, restartabletest.RestartableDelegateTest{ Function: "DeleteSnapshot", - Inputs: []interface{}{"snapshotID"}, - ExpectedErrorOutputs: []interface{}{errors.Errorf("reset error")}, - ExpectedDelegateOutputs: []interface{}{errors.Errorf("delegate error")}, + Inputs: []any{"snapshotID"}, + ExpectedErrorOutputs: []any{errors.Errorf("reset error")}, + ExpectedDelegateOutputs: []any{errors.Errorf("delegate error")}, }, ) } diff --git a/pkg/plugin/framework/backup_item_action.go b/pkg/plugin/framework/backup_item_action.go index 8f6bc7554a..00f3cc0ea5 100644 --- a/pkg/plugin/framework/backup_item_action.go +++ b/pkg/plugin/framework/backup_item_action.go @@ -34,7 +34,7 @@ type BackupItemActionPlugin struct { } // GRPCClient returns a clientDispenser for BackupItemAction gRPC clients. -func (p *BackupItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { +func (p *BackupItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (any, error) { return common.NewClientDispenser(p.ClientLogger, clientConn, newBackupItemActionGRPCClient), nil } diff --git a/pkg/plugin/framework/backup_item_action_client.go b/pkg/plugin/framework/backup_item_action_client.go index 50101975f9..948cb3492e 100644 --- a/pkg/plugin/framework/backup_item_action_client.go +++ b/pkg/plugin/framework/backup_item_action_client.go @@ -46,7 +46,7 @@ type BackupItemActionGRPCClient struct { grpcClient protobiav1.BackupItemActionClient } -func newBackupItemActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) interface{} { +func newBackupItemActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) any { return &BackupItemActionGRPCClient{ ClientBase: base, grpcClient: protobiav1.NewBackupItemActionClient(clientConn), diff --git a/pkg/plugin/framework/backup_item_action_test.go b/pkg/plugin/framework/backup_item_action_test.go index fb304072e0..59a1bbba84 100644 --- a/pkg/plugin/framework/backup_item_action_test.go +++ b/pkg/plugin/framework/backup_item_action_test.go @@ -156,7 +156,7 @@ func TestBackupItemActionGRPCServerExecute(t *testing.T) { s := &BackupItemActionGRPCServer{mux: &common.ServerMux{ ServerLog: velerotest.NewLogger(), - Handlers: map[string]interface{}{ + Handlers: map[string]any{ "xyz": itemAction, }, }} diff --git a/pkg/plugin/framework/backupitemaction/v2/backup_item_action.go b/pkg/plugin/framework/backupitemaction/v2/backup_item_action.go index a4efa9a2e1..c1e2e54018 100644 --- a/pkg/plugin/framework/backupitemaction/v2/backup_item_action.go +++ b/pkg/plugin/framework/backupitemaction/v2/backup_item_action.go @@ -34,7 +34,7 @@ type BackupItemActionPlugin struct { } // GRPCClient returns a clientDispenser for BackupItemAction gRPC clients. -func (p *BackupItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { +func (p *BackupItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (any, error) { return common.NewClientDispenser(p.ClientLogger, clientConn, newBackupItemActionGRPCClient), nil } diff --git a/pkg/plugin/framework/backupitemaction/v2/backup_item_action_client.go b/pkg/plugin/framework/backupitemaction/v2/backup_item_action_client.go index d5a154b5fb..52733de2d9 100644 --- a/pkg/plugin/framework/backupitemaction/v2/backup_item_action_client.go +++ b/pkg/plugin/framework/backupitemaction/v2/backup_item_action_client.go @@ -46,7 +46,7 @@ type BackupItemActionGRPCClient struct { grpcClient protobiav2.BackupItemActionClient } -func newBackupItemActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) interface{} { +func newBackupItemActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) any { return &BackupItemActionGRPCClient{ ClientBase: base, grpcClient: protobiav2.NewBackupItemActionClient(clientConn), diff --git a/pkg/plugin/framework/backupitemaction/v2/backup_item_action_test.go b/pkg/plugin/framework/backupitemaction/v2/backup_item_action_test.go index 82d70a8e84..47f69dea95 100644 --- a/pkg/plugin/framework/backupitemaction/v2/backup_item_action_test.go +++ b/pkg/plugin/framework/backupitemaction/v2/backup_item_action_test.go @@ -159,7 +159,7 @@ func TestBackupItemActionGRPCServerExecute(t *testing.T) { s := &BackupItemActionGRPCServer{mux: &common.ServerMux{ ServerLog: velerotest.NewLogger(), - Handlers: map[string]interface{}{ + Handlers: map[string]any{ "xyz": itemAction, }, }} diff --git a/pkg/plugin/framework/common/client_dispenser.go b/pkg/plugin/framework/common/client_dispenser.go index 1abb11c2df..bff8b90ae5 100644 --- a/pkg/plugin/framework/common/client_dispenser.go +++ b/pkg/plugin/framework/common/client_dispenser.go @@ -28,7 +28,7 @@ type ClientBase struct { } type ClientDispenser interface { - ClientFor(name string) interface{} + ClientFor(name string) any } // clientDispenser supports the initialization and retrieval of multiple implementations for a single plugin kind, such as @@ -41,10 +41,10 @@ type clientDispenser struct { // initFunc returns a client that implements a plugin interface, such as ObjectStore. initFunc clientInitFunc // clients keeps track of all the initialized implementations. - clients map[string]interface{} + clients map[string]any } -type clientInitFunc func(base *ClientBase, clientConn *grpc.ClientConn) interface{} +type clientInitFunc func(base *ClientBase, clientConn *grpc.ClientConn) any // newClientDispenser creates a new clientDispenser. func NewClientDispenser(logger logrus.FieldLogger, clientConn *grpc.ClientConn, initFunc clientInitFunc) *clientDispenser { @@ -52,13 +52,13 @@ func NewClientDispenser(logger logrus.FieldLogger, clientConn *grpc.ClientConn, clientConn: clientConn, logger: logger, initFunc: initFunc, - clients: make(map[string]interface{}), + clients: make(map[string]any), } } // ClientFor returns a gRPC client stub for the implementation of a plugin named name. If the client stub does not // currently exist, clientFor creates it. -func (cd *clientDispenser) ClientFor(name string) interface{} { +func (cd *clientDispenser) ClientFor(name string) any { if client, found := cd.clients[name]; found { return client } diff --git a/pkg/plugin/framework/common/client_dispenser_test.go b/pkg/plugin/framework/common/client_dispenser_test.go index 3a33774987..3aa0cd2995 100644 --- a/pkg/plugin/framework/common/client_dispenser_test.go +++ b/pkg/plugin/framework/common/client_dispenser_test.go @@ -36,7 +36,7 @@ func TestNewClientDispenser(t *testing.T) { clientConn := new(grpc.ClientConn) c := 3 - initFunc := func(base *ClientBase, clientConn *grpc.ClientConn) interface{} { + initFunc := func(base *ClientBase, clientConn *grpc.ClientConn) any { return c } @@ -52,7 +52,7 @@ func TestClientFor(t *testing.T) { c := new(fakeClient) count := 0 - initFunc := func(base *ClientBase, clientConn *grpc.ClientConn) interface{} { + initFunc := func(base *ClientBase, clientConn *grpc.ClientConn) any { c.base = base c.clientConn = clientConn count++ diff --git a/pkg/plugin/framework/common/handle_panic.go b/pkg/plugin/framework/common/handle_panic.go index e4324898dd..697ff588c0 100644 --- a/pkg/plugin/framework/common/handle_panic.go +++ b/pkg/plugin/framework/common/handle_panic.go @@ -24,7 +24,7 @@ import ( ) // HandlePanic is a panic handler for the server half of velero plugins. -func HandlePanic(p interface{}) error { +func HandlePanic(p any) error { if p == nil { return nil } diff --git a/pkg/plugin/framework/common/server_mux.go b/pkg/plugin/framework/common/server_mux.go index 960975c7e6..4eecdb8d21 100644 --- a/pkg/plugin/framework/common/server_mux.go +++ b/pkg/plugin/framework/common/server_mux.go @@ -27,13 +27,13 @@ import ( // HandlerInitializer is a function that initializes and returns a new instance of one of Velero's plugin interfaces // (ObjectStore, VolumeSnapshotter, BackupItemAction, RestoreItemAction). -type HandlerInitializer func(logger logrus.FieldLogger) (interface{}, error) +type HandlerInitializer func(logger logrus.FieldLogger) (any, error) // ServerMux manages multiple implementations of a single plugin kind, such as pod and pvc BackupItemActions. type ServerMux struct { kind PluginKind initializers map[string]HandlerInitializer - Handlers map[string]interface{} + Handlers map[string]any ServerLog logrus.FieldLogger } @@ -41,7 +41,7 @@ type ServerMux struct { func NewServerMux(logger logrus.FieldLogger) *ServerMux { return &ServerMux{ initializers: make(map[string]HandlerInitializer), - Handlers: make(map[string]interface{}), + Handlers: make(map[string]any), ServerLog: logger, } } @@ -63,7 +63,7 @@ func (m *ServerMux) Names() []string { // GetHandler returns the instance for a plugin with the given name. If an instance has already been initialized, // that is returned. Otherwise, the instance is initialized by calling its initialization function. -func (m *ServerMux) GetHandler(name string) (interface{}, error) { +func (m *ServerMux) GetHandler(name string) (any, error) { if instance, found := m.Handlers[name]; found { return instance, nil } diff --git a/pkg/plugin/framework/delete_item_action.go b/pkg/plugin/framework/delete_item_action.go index c6c0f6bbb1..afc5d548ed 100644 --- a/pkg/plugin/framework/delete_item_action.go +++ b/pkg/plugin/framework/delete_item_action.go @@ -34,7 +34,7 @@ type DeleteItemActionPlugin struct { } // GRPCClient returns a DeleteItemAction gRPC client. -func (p *DeleteItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { +func (p *DeleteItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (any, error) { return common.NewClientDispenser(p.ClientLogger, clientConn, newDeleteItemActionGRPCClient), nil } diff --git a/pkg/plugin/framework/delete_item_action_client.go b/pkg/plugin/framework/delete_item_action_client.go index 4241d0b33c..088c42b511 100644 --- a/pkg/plugin/framework/delete_item_action_client.go +++ b/pkg/plugin/framework/delete_item_action_client.go @@ -44,7 +44,7 @@ type DeleteItemActionGRPCClient struct { grpcClient proto.DeleteItemActionClient } -func newDeleteItemActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) interface{} { +func newDeleteItemActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) any { return &DeleteItemActionGRPCClient{ ClientBase: base, grpcClient: proto.NewDeleteItemActionClient(clientConn), diff --git a/pkg/plugin/framework/examples_test.go b/pkg/plugin/framework/examples_test.go index 16ce5bd492..41bb8395ec 100644 --- a/pkg/plugin/framework/examples_test.go +++ b/pkg/plugin/framework/examples_test.go @@ -30,7 +30,7 @@ func ExampleNewServer_volumeSnapshotter() { Serve() // serve the plugin } -func newVolumeSnapshotter(logger logrus.FieldLogger) (interface{}, error) { +func newVolumeSnapshotter(logger logrus.FieldLogger) (any, error) { return &VolumeSnapshotter{FieldLogger: logger}, nil } @@ -97,7 +97,7 @@ func (b *VolumeSnapshotter) DeleteSnapshot(snapshotID string) error { // Implement all methods for the DeleteItemAction interface -func newDeleteItemAction(logger logrus.FieldLogger) (interface{}, error) { +func newDeleteItemAction(logger logrus.FieldLogger) (any, error) { return DeleteItemAction{FieldLogger: logger}, nil } diff --git a/pkg/plugin/framework/itemblockaction/v1/item_block_action.go b/pkg/plugin/framework/itemblockaction/v1/item_block_action.go index dfe7a83b48..9fb8094ee2 100644 --- a/pkg/plugin/framework/itemblockaction/v1/item_block_action.go +++ b/pkg/plugin/framework/itemblockaction/v1/item_block_action.go @@ -34,7 +34,7 @@ type ItemBlockActionPlugin struct { } // GRPCClient returns a clientDispenser for ItemBlockAction gRPC clients. -func (p *ItemBlockActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { +func (p *ItemBlockActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (any, error) { return common.NewClientDispenser(p.ClientLogger, clientConn, newItemBlockActionGRPCClient), nil } diff --git a/pkg/plugin/framework/itemblockaction/v1/item_block_action_client.go b/pkg/plugin/framework/itemblockaction/v1/item_block_action_client.go index 06287da33c..612a14a6cc 100644 --- a/pkg/plugin/framework/itemblockaction/v1/item_block_action_client.go +++ b/pkg/plugin/framework/itemblockaction/v1/item_block_action_client.go @@ -45,7 +45,7 @@ type ItemBlockActionGRPCClient struct { grpcClient protoibav1.ItemBlockActionClient } -func newItemBlockActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) interface{} { +func newItemBlockActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) any { return &ItemBlockActionGRPCClient{ ClientBase: base, grpcClient: protoibav1.NewItemBlockActionClient(clientConn), diff --git a/pkg/plugin/framework/itemblockaction/v1/item_block_action_test.go b/pkg/plugin/framework/itemblockaction/v1/item_block_action_test.go index ecfa693ae2..4397821cb5 100644 --- a/pkg/plugin/framework/itemblockaction/v1/item_block_action_test.go +++ b/pkg/plugin/framework/itemblockaction/v1/item_block_action_test.go @@ -132,7 +132,7 @@ func TestItemBlockActionGRPCServerGetRelatedItems(t *testing.T) { s := &ItemBlockActionGRPCServer{mux: &common.ServerMux{ ServerLog: velerotest.NewLogger(), - Handlers: map[string]interface{}{ + Handlers: map[string]any{ "xyz": itemAction, }, }} diff --git a/pkg/plugin/framework/object_store.go b/pkg/plugin/framework/object_store.go index ad246ede8e..d7c7b95e4d 100644 --- a/pkg/plugin/framework/object_store.go +++ b/pkg/plugin/framework/object_store.go @@ -34,7 +34,7 @@ type ObjectStorePlugin struct { } // GRPCClient returns an ObjectStore gRPC client. -func (p *ObjectStorePlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { +func (p *ObjectStorePlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (any, error) { return common.NewClientDispenser(p.ClientLogger, clientConn, newObjectStoreGRPCClient), nil } diff --git a/pkg/plugin/framework/object_store_client.go b/pkg/plugin/framework/object_store_client.go index 3cc5cd6e99..725f8e934d 100644 --- a/pkg/plugin/framework/object_store_client.go +++ b/pkg/plugin/framework/object_store_client.go @@ -44,7 +44,7 @@ type ObjectStoreGRPCClient struct { grpcClient proto.ObjectStoreClient } -func newObjectStoreGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) interface{} { +func newObjectStoreGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) any { return &ObjectStoreGRPCClient{ ClientBase: base, grpcClient: proto.NewObjectStoreClient(clientConn), diff --git a/pkg/plugin/framework/plugin_lister.go b/pkg/plugin/framework/plugin_lister.go index e658ae8a21..19e3490070 100644 --- a/pkg/plugin/framework/plugin_lister.go +++ b/pkg/plugin/framework/plugin_lister.go @@ -69,7 +69,7 @@ func NewPluginListerPlugin(impl PluginLister) *PluginListerPlugin { ////////////////////////////////////////////////////////////////////////////// // GRPCClient returns a PluginLister gRPC client. -func (p *PluginListerPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { +func (p *PluginListerPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (any, error) { return &PluginListerGRPCClient{grpcClient: proto.NewPluginListerClient(clientConn)}, nil } diff --git a/pkg/plugin/framework/plugin_types_test.go b/pkg/plugin/framework/plugin_types_test.go index f9b4d1f809..8ec8318f0f 100644 --- a/pkg/plugin/framework/plugin_types_test.go +++ b/pkg/plugin/framework/plugin_types_test.go @@ -24,7 +24,7 @@ import ( ) func TestPluginImplementationsAreGRPCPlugins(t *testing.T) { - pluginImpls := []interface{}{ + pluginImpls := []any{ new(VolumeSnapshotterPlugin), new(BackupItemActionPlugin), new(ObjectStorePlugin), diff --git a/pkg/plugin/framework/restore_item_action.go b/pkg/plugin/framework/restore_item_action.go index b5a3d41c16..0aaf2b47ed 100644 --- a/pkg/plugin/framework/restore_item_action.go +++ b/pkg/plugin/framework/restore_item_action.go @@ -34,7 +34,7 @@ type RestoreItemActionPlugin struct { } // GRPCClient returns a RestoreItemAction gRPC client. -func (p *RestoreItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { +func (p *RestoreItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (any, error) { return common.NewClientDispenser(p.ClientLogger, clientConn, newRestoreItemActionGRPCClient), nil } diff --git a/pkg/plugin/framework/restore_item_action_client.go b/pkg/plugin/framework/restore_item_action_client.go index 75490d4c2f..8809e31c3d 100644 --- a/pkg/plugin/framework/restore_item_action_client.go +++ b/pkg/plugin/framework/restore_item_action_client.go @@ -47,7 +47,7 @@ type RestoreItemActionGRPCClient struct { grpcClient proto.RestoreItemActionClient } -func newRestoreItemActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) interface{} { +func newRestoreItemActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) any { return &RestoreItemActionGRPCClient{ ClientBase: base, grpcClient: proto.NewRestoreItemActionClient(clientConn), diff --git a/pkg/plugin/framework/restoreitemaction/v2/restore_item_action.go b/pkg/plugin/framework/restoreitemaction/v2/restore_item_action.go index 13ec1b851d..243e2fd678 100644 --- a/pkg/plugin/framework/restoreitemaction/v2/restore_item_action.go +++ b/pkg/plugin/framework/restoreitemaction/v2/restore_item_action.go @@ -34,7 +34,7 @@ type RestoreItemActionPlugin struct { } // GRPCClient returns a RestoreItemAction gRPC client. -func (p *RestoreItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { +func (p *RestoreItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (any, error) { return common.NewClientDispenser(p.ClientLogger, clientConn, newRestoreItemActionGRPCClient), nil } diff --git a/pkg/plugin/framework/restoreitemaction/v2/restore_item_action_client.go b/pkg/plugin/framework/restoreitemaction/v2/restore_item_action_client.go index 4abb2c9969..b1d61fb75c 100644 --- a/pkg/plugin/framework/restoreitemaction/v2/restore_item_action_client.go +++ b/pkg/plugin/framework/restoreitemaction/v2/restore_item_action_client.go @@ -48,7 +48,7 @@ type RestoreItemActionGRPCClient struct { grpcClient protoriav2.RestoreItemActionClient } -func newRestoreItemActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) interface{} { +func newRestoreItemActionGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) any { return &RestoreItemActionGRPCClient{ ClientBase: base, grpcClient: protoriav2.NewRestoreItemActionClient(clientConn), diff --git a/pkg/plugin/framework/volume_snapshotter.go b/pkg/plugin/framework/volume_snapshotter.go index 566fc1eb72..5eb6159eb5 100644 --- a/pkg/plugin/framework/volume_snapshotter.go +++ b/pkg/plugin/framework/volume_snapshotter.go @@ -34,7 +34,7 @@ type VolumeSnapshotterPlugin struct { } // GRPCClient returns a VolumeSnapshotter gRPC client. -func (p *VolumeSnapshotterPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) { +func (p *VolumeSnapshotterPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (any, error) { return common.NewClientDispenser(p.ClientLogger, clientConn, newVolumeSnapshotterGRPCClient), nil } diff --git a/pkg/plugin/framework/volume_snapshotter_client.go b/pkg/plugin/framework/volume_snapshotter_client.go index a359046177..da66f2cea2 100644 --- a/pkg/plugin/framework/volume_snapshotter_client.go +++ b/pkg/plugin/framework/volume_snapshotter_client.go @@ -43,7 +43,7 @@ type VolumeSnapshotterGRPCClient struct { grpcClient proto.VolumeSnapshotterClient } -func newVolumeSnapshotterGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) interface{} { +func newVolumeSnapshotterGRPCClient(base *common.ClientBase, clientConn *grpc.ClientConn) any { return &VolumeSnapshotterGRPCClient{ ClientBase: base, grpcClient: proto.NewVolumeSnapshotterClient(clientConn), diff --git a/pkg/podexec/pod_command_executor.go b/pkg/podexec/pod_command_executor.go index 60793aebd3..b1d7fbf59a 100644 --- a/pkg/podexec/pod_command_executor.go +++ b/pkg/podexec/pod_command_executor.go @@ -39,7 +39,7 @@ const defaultTimeout = 30 * time.Second type PodCommandExecutor interface { // ExecutePodCommand executes a command in a container in a pod. If the command takes longer than // the specified timeout, an error is returned. - ExecutePodCommand(log logrus.FieldLogger, item map[string]interface{}, namespace, name, hookName string, hook *api.ExecHook) error + ExecutePodCommand(log logrus.FieldLogger, item map[string]any, namespace, name, hookName string, hook *api.ExecHook) error } type poster interface { @@ -67,7 +67,7 @@ func NewPodCommandExecutor(restClientConfig *rest.Config, restClient poster) Pod // command takes longer than the specified timeout, an error is returned (NOTE: it is not currently // possible to ensure the command is terminated when the timeout occurs, so it may continue to run // in the background). -func (e *defaultPodCommandExecutor) ExecutePodCommand(log logrus.FieldLogger, item map[string]interface{}, namespace, name, hookName string, hook *api.ExecHook) error { +func (e *defaultPodCommandExecutor) ExecutePodCommand(log logrus.FieldLogger, item map[string]any, namespace, name, hookName string, hook *api.ExecHook) error { if item == nil { return errors.New("item is required") } diff --git a/pkg/podexec/pod_command_executor_test.go b/pkg/podexec/pod_command_executor_test.go index 150c1babdf..ad22a302ca 100644 --- a/pkg/podexec/pod_command_executor_test.go +++ b/pkg/podexec/pod_command_executor_test.go @@ -52,7 +52,7 @@ func TestNewPodCommandExecutor(t *testing.T) { func TestExecutePodCommandMissingInputs(t *testing.T) { tests := []struct { name string - item map[string]interface{} + item map[string]any podNamespace string podName string hookName string @@ -63,22 +63,22 @@ func TestExecutePodCommandMissingInputs(t *testing.T) { }, { name: "missing pod namespace", - item: map[string]interface{}{}, + item: map[string]any{}, }, { name: "missing pod name", - item: map[string]interface{}{}, + item: map[string]any{}, podNamespace: "ns", }, { name: "missing hookName", - item: map[string]interface{}{}, + item: map[string]any{}, podNamespace: "ns", podName: "pod", }, { name: "missing hook", - item: map[string]interface{}{}, + item: map[string]any{}, podNamespace: "ns", podName: "pod", hookName: "hook", diff --git a/pkg/podvolume/backupper.go b/pkg/podvolume/backupper.go index 09ad91db88..3b0dbe4999 100644 --- a/pkg/podvolume/backupper.go +++ b/pkg/podvolume/backupper.go @@ -108,7 +108,7 @@ func (pbs *PVCBackupSummary) addSkipped(volumeName string, reason string) { const indexNamePod = "POD" -func podIndexFunc(obj interface{}) ([]string, error) { +func podIndexFunc(obj any) ([]string, error) { pvb, ok := obj.(*velerov1api.PodVolumeBackup) if !ok { return nil, errors.Errorf("expected PodVolumeBackup, but got %T", obj) @@ -144,7 +144,7 @@ func newBackupper( b.handlerRegistration, _ = pvbInformer.AddEventHandler( cache.ResourceEventHandlerFuncs{ - UpdateFunc: func(_, obj interface{}) { + UpdateFunc: func(_, obj any) { pvb, ok := obj.(*velerov1api.PodVolumeBackup) if !ok { log.Errorf("expected PodVolumeBackup, but got %T", obj) diff --git a/pkg/podvolume/restorer.go b/pkg/podvolume/restorer.go index 18e7717631..1c50b79d97 100644 --- a/pkg/podvolume/restorer.go +++ b/pkg/podvolume/restorer.go @@ -92,7 +92,7 @@ func newRestorer( _, _ = pvrInformer.AddEventHandler( cache.ResourceEventHandlerFuncs{ - UpdateFunc: func(_, obj interface{}) { + UpdateFunc: func(_, obj any) { pvr := obj.(*velerov1api.PodVolumeRestore) if pvr.GetLabels()[velerov1api.RestoreUIDLabel] != string(restore.UID) { return diff --git a/pkg/repository/provider/unified_repo.go b/pkg/repository/provider/unified_repo.go index 42f100fa97..bdd909f206 100644 --- a/pkg/repository/provider/unified_repo.go +++ b/pkg/repository/provider/unified_repo.go @@ -376,7 +376,7 @@ func (urp *unifiedRepoProvider) DefaultMaintenanceFrequency(ctx context.Context, return urp.repoService.DefaultMaintenanceFrequency() } -func (urp *unifiedRepoProvider) GetPassword(param interface{}) (string, error) { +func (urp *unifiedRepoProvider) GetPassword(param any) (string, error) { _, ok := param.(RepoParam) if !ok { return "", errors.Errorf("invalid parameter, expect %T, actual %T", RepoParam{}, param) @@ -390,7 +390,7 @@ func (urp *unifiedRepoProvider) GetPassword(param interface{}) (string, error) { return repoPassword, nil } -func (urp *unifiedRepoProvider) GetStoreType(param interface{}) (string, error) { +func (urp *unifiedRepoProvider) GetStoreType(param any) (string, error) { repoParam, ok := param.(RepoParam) if !ok { return "", errors.Errorf("invalid parameter, expect %T, actual %T", RepoParam{}, param) @@ -399,7 +399,7 @@ func (urp *unifiedRepoProvider) GetStoreType(param interface{}) (string, error) return getStorageType(repoParam.BackupLocation), nil } -func (urp *unifiedRepoProvider) GetStoreOptions(param interface{}) (map[string]string, error) { +func (urp *unifiedRepoProvider) GetStoreOptions(param any) (map[string]string, error) { repoParam, ok := param.(RepoParam) if !ok { return map[string]string{}, errors.Errorf("invalid parameter, expect %T, actual %T", RepoParam{}, param) diff --git a/pkg/repository/provider/unified_repo_test.go b/pkg/repository/provider/unified_repo_test.go index 8c9203b5bf..162f9b4572 100644 --- a/pkg/repository/provider/unified_repo_test.go +++ b/pkg/repository/provider/unified_repo_test.go @@ -538,7 +538,7 @@ func TestGetStoreOptions(t *testing.T) { testCases := []struct { name string funcTable localFuncTable - repoParam interface{} + repoParam any expected map[string]string expectedErr string }{ @@ -798,9 +798,9 @@ func TestForget(t *testing.T) { getter *credmock.SecretStore repoService *reposervicenmocks.BackupRepoService backupRepo *reposervicenmocks.BackupRepo - retFuncOpen []interface{} - retFuncDelete interface{} - retFuncFlush interface{} + retFuncOpen []any + retFuncDelete any + retFuncFlush any credStoreReturn string credStoreError error expectedErr string @@ -822,7 +822,7 @@ func TestForget(t *testing.T) { }, }, repoService: new(reposervicenmocks.BackupRepoService), - retFuncOpen: []interface{}{ + retFuncOpen: []any{ func(context.Context, udmrepo.RepoOptions) udmrepo.BackupRepo { return backupRepo }, @@ -847,7 +847,7 @@ func TestForget(t *testing.T) { }, repoService: new(reposervicenmocks.BackupRepoService), backupRepo: new(reposervicenmocks.BackupRepo), - retFuncOpen: []interface{}{ + retFuncOpen: []any{ func(context.Context, udmrepo.RepoOptions) udmrepo.BackupRepo { return backupRepo }, @@ -875,7 +875,7 @@ func TestForget(t *testing.T) { }, repoService: new(reposervicenmocks.BackupRepoService), backupRepo: new(reposervicenmocks.BackupRepo), - retFuncOpen: []interface{}{ + retFuncOpen: []any{ func(context.Context, udmrepo.RepoOptions) udmrepo.BackupRepo { return backupRepo }, @@ -947,9 +947,9 @@ func TestBatchForget(t *testing.T) { getter *credmock.SecretStore repoService *reposervicenmocks.BackupRepoService backupRepo *reposervicenmocks.BackupRepo - retFuncOpen []interface{} - retFuncDelete interface{} - retFuncFlush interface{} + retFuncOpen []any + retFuncDelete any + retFuncFlush any credStoreReturn string credStoreError error snapshots []string @@ -972,7 +972,7 @@ func TestBatchForget(t *testing.T) { }, }, repoService: new(reposervicenmocks.BackupRepoService), - retFuncOpen: []interface{}{ + retFuncOpen: []any{ func(context.Context, udmrepo.RepoOptions) udmrepo.BackupRepo { return backupRepo }, @@ -997,7 +997,7 @@ func TestBatchForget(t *testing.T) { }, repoService: new(reposervicenmocks.BackupRepoService), backupRepo: new(reposervicenmocks.BackupRepo), - retFuncOpen: []interface{}{ + retFuncOpen: []any{ func(context.Context, udmrepo.RepoOptions) udmrepo.BackupRepo { return backupRepo }, @@ -1026,7 +1026,7 @@ func TestBatchForget(t *testing.T) { }, repoService: new(reposervicenmocks.BackupRepoService), backupRepo: new(reposervicenmocks.BackupRepo), - retFuncOpen: []interface{}{ + retFuncOpen: []any{ func(context.Context, udmrepo.RepoOptions) udmrepo.BackupRepo { return backupRepo }, @@ -1106,7 +1106,7 @@ func TestInitRepo(t *testing.T) { funcTable localFuncTable getter *credmock.SecretStore repoService *reposervicenmocks.BackupRepoService - retFuncInit interface{} + retFuncInit any credStoreReturn string credStoreError error readOnlyBSL bool @@ -1206,7 +1206,7 @@ func TestConnectToRepo(t *testing.T) { funcTable localFuncTable getter *credmock.SecretStore repoService *reposervicenmocks.BackupRepoService - retFuncInit interface{} + retFuncInit any credStoreReturn string credStoreError error expectedErr string @@ -1297,8 +1297,8 @@ func TestBoostRepoConnect(t *testing.T) { getter *credmock.SecretStore repoService *reposervicenmocks.BackupRepoService backupRepo *reposervicenmocks.BackupRepo - retFuncInit interface{} - retFuncOpen []interface{} + retFuncInit any + retFuncOpen []any credStoreReturn string credStoreError error expectedErr string @@ -1320,7 +1320,7 @@ func TestBoostRepoConnect(t *testing.T) { }, }, repoService: new(reposervicenmocks.BackupRepoService), - retFuncOpen: []interface{}{ + retFuncOpen: []any{ func(context.Context, udmrepo.RepoOptions) udmrepo.BackupRepo { return backupRepo }, @@ -1347,7 +1347,7 @@ func TestBoostRepoConnect(t *testing.T) { }, }, repoService: new(reposervicenmocks.BackupRepoService), - retFuncOpen: []interface{}{ + retFuncOpen: []any{ func(context.Context, udmrepo.RepoOptions) udmrepo.BackupRepo { return backupRepo }, @@ -1374,7 +1374,7 @@ func TestBoostRepoConnect(t *testing.T) { }, repoService: new(reposervicenmocks.BackupRepoService), backupRepo: new(reposervicenmocks.BackupRepo), - retFuncOpen: []interface{}{ + retFuncOpen: []any{ func(context.Context, udmrepo.RepoOptions) udmrepo.BackupRepo { return backupRepo }, @@ -1438,7 +1438,7 @@ func TestPruneRepo(t *testing.T) { funcTable localFuncTable getter *credmock.SecretStore repoService *reposervicenmocks.BackupRepoService - retFuncMaintain interface{} + retFuncMaintain any credStoreReturn string credStoreError error expectedErr string diff --git a/pkg/repository/udmrepo/repo.go b/pkg/repository/udmrepo/repo.go index db32d09535..0adb397510 100644 --- a/pkg/repository/udmrepo/repo.go +++ b/pkg/repository/udmrepo/repo.go @@ -33,7 +33,7 @@ type ManifestEntryMetadata struct { } type RepoManifest struct { - Payload interface{} // The user data of manifest + Payload any // The user data of manifest Metadata *ManifestEntryMetadata // The metadata data of manifest } diff --git a/pkg/repository/udmrepo/repo_options.go b/pkg/repository/udmrepo/repo_options.go index 8dbbbee366..ad4c597f92 100644 --- a/pkg/repository/udmrepo/repo_options.go +++ b/pkg/repository/udmrepo/repo_options.go @@ -96,13 +96,13 @@ type RepoOptions struct { // PasswordGetter defines the method to get a repository password. type PasswordGetter interface { - GetPassword(param interface{}) (string, error) + GetPassword(param any) (string, error) } // StoreOptionsGetter defines the methods to get the storage related options. type StoreOptionsGetter interface { - GetStoreType(param interface{}) (string, error) - GetStoreOptions(param interface{}) (map[string]string, error) + GetStoreType(param any) (string, error) + GetStoreOptions(param any) (map[string]string, error) } // NewRepoOptions creates a new RepoOptions for different purpose @@ -124,7 +124,7 @@ func NewRepoOptions(optionFuncs ...func(*RepoOptions) error) (*RepoOptions, erro // WithPassword sets the RepoPassword to RepoOptions, the password is acquired through // the provided interface -func WithPassword(getter PasswordGetter, param interface{}) func(*RepoOptions) error { +func WithPassword(getter PasswordGetter, param any) func(*RepoOptions) error { return func(options *RepoOptions) error { password, err := getter.GetPassword(param) if err != nil { @@ -158,7 +158,7 @@ func WithGenOptions(genOptions map[string]string) func(*RepoOptions) error { // WithStoreOptions sets the StorageOptions to RepoOptions, the store options are acquired through // the provided interface -func WithStoreOptions(getter StoreOptionsGetter, param interface{}) func(*RepoOptions) error { +func WithStoreOptions(getter StoreOptionsGetter, param any) func(*RepoOptions) error { return func(options *RepoOptions) error { storeType, err := getter.GetStoreType(param) if err != nil { diff --git a/pkg/restore/actions/admissionwebhook_config_action.go b/pkg/restore/actions/admissionwebhook_config_action.go index c6c9676999..82599dc62f 100644 --- a/pkg/restore/actions/admissionwebhook_config_action.go +++ b/pkg/restore/actions/admissionwebhook_config_action.go @@ -69,7 +69,7 @@ func (a *AdmissionWebhookConfigurationAction) Execute(input *velero.RestoreItemA logger.Info("webhooks is not set, skip") return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } - newWebhooks := make([]interface{}, 0) + newWebhooks := make([]any, 0) for i := range webhooks { logger2 := logger.WithField("index", i) obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&webhooks[i]) diff --git a/pkg/restore/actions/admissionwebhook_config_action_test.go b/pkg/restore/actions/admissionwebhook_config_action_test.go index fb0205cb4e..4daad1c088 100644 --- a/pkg/restore/actions/admissionwebhook_config_action_test.go +++ b/pkg/restore/actions/admissionwebhook_config_action_test.go @@ -177,7 +177,7 @@ func TestNewAdmissionWebhookConfigurationActionExecute(t *testing.T) { } for _, tt := range cases { t.Run(tt.name, func(t *testing.T) { - o := map[string]interface{}{} + o := map[string]any{} json.Unmarshal([]byte(tt.itemJSON), &o) input := &velero.RestoreItemActionExecuteInput{ Item: &unstructured.Unstructured{ diff --git a/pkg/restore/actions/change_image_name_action.go b/pkg/restore/actions/change_image_name_action.go index 66fac1f186..c705ddfa35 100644 --- a/pkg/restore/actions/change_image_name_action.go +++ b/pkg/restore/actions/change_image_name_action.go @@ -145,7 +145,7 @@ func (a *ChangeImageNameAction) Execute(input *velero.RestoreItemActionExecuteIn } func (a *ChangeImageNameAction) replaceImageName(obj *unstructured.Unstructured, config *corev1.ConfigMap, filed ...string) error { - log := a.logger.WithFields(map[string]interface{}{ + log := a.logger.WithFields(map[string]any{ "kind": obj.GetKind(), "namespace": obj.GetNamespace(), "name": obj.GetName(), @@ -161,12 +161,12 @@ func (a *ChangeImageNameAction) replaceImageName(obj *unstructured.Unstructured, } for i, container := range containers { log.Infoln("container:", container) - if image, ok := container.(map[string]interface{})["image"]; ok { + if image, ok := container.(map[string]any)["image"]; ok { imageName := image.(string) if exists, newImageName, err := a.isImageReplaceRuleExist(log, imageName, config); exists && err == nil { needUpdateObj = true log.Infof("Updating item's image from %s to %s", imageName, newImageName) - container.(map[string]interface{})["image"] = newImageName + container.(map[string]any)["image"] = newImageName containers[i] = container } } diff --git a/pkg/restore/actions/change_image_name_action_test.go b/pkg/restore/actions/change_image_name_action_test.go index 134fc154ce..75f9b5939d 100644 --- a/pkg/restore/actions/change_image_name_action_test.go +++ b/pkg/restore/actions/change_image_name_action_test.go @@ -40,11 +40,11 @@ import ( func TestChangeImageRepositoryActionExecute(t *testing.T) { tests := []struct { name string - podOrObj interface{} + podOrObj any configMap *corev1.ConfigMap freshedImageName string imageNameSlice []string - want interface{} + want any wantErr error }{ { diff --git a/pkg/restore/actions/change_pvc_node_selector.go b/pkg/restore/actions/change_pvc_node_selector.go index 2888b6b2da..64d5ceb3f5 100644 --- a/pkg/restore/actions/change_pvc_node_selector.go +++ b/pkg/restore/actions/change_pvc_node_selector.go @@ -81,7 +81,7 @@ func (p *ChangePVCNodeSelectorAction) Execute(input *velero.RestoreItemActionExe return velero.NewRestoreItemActionExecuteOutput(input.Item), nil } - log := p.logger.WithFields(map[string]interface{}{ + log := p.logger.WithFields(map[string]any{ "kind": typeAcc.GetKind(), "namespace": metadata.GetNamespace(), "name": metadata.GetName(), diff --git a/pkg/restore/actions/change_storageclass_action.go b/pkg/restore/actions/change_storageclass_action.go index b4052eb2dc..5743042fa4 100644 --- a/pkg/restore/actions/change_storageclass_action.go +++ b/pkg/restore/actions/change_storageclass_action.go @@ -84,7 +84,7 @@ func (a *ChangeStorageClassAction) Execute(input *velero.RestoreItemActionExecut return nil, errors.Errorf("object was of unexpected type %T", input.Item) } - log := a.logger.WithFields(map[string]interface{}{ + log := a.logger.WithFields(map[string]any{ "kind": obj.GetKind(), "namespace": obj.GetNamespace(), "name": obj.GetName(), diff --git a/pkg/restore/actions/change_storageclass_action_test.go b/pkg/restore/actions/change_storageclass_action_test.go index 4d32a6bade..686be146f2 100644 --- a/pkg/restore/actions/change_storageclass_action_test.go +++ b/pkg/restore/actions/change_storageclass_action_test.go @@ -42,11 +42,11 @@ import ( func TestChangeStorageClassActionExecute(t *testing.T) { tests := []struct { name string - pvOrPvcOrSTS interface{} + pvOrPvcOrSTS any configMap *corev1api.ConfigMap storageClass *storagev1api.StorageClass storageClassSlice []*storagev1api.StorageClass - want interface{} + want any wantErr error }{ { diff --git a/pkg/restore/actions/crd_v1_preserve_unknown_fields_action.go b/pkg/restore/actions/crd_v1_preserve_unknown_fields_action.go index 673edd1b61..9e4cf7e2fa 100644 --- a/pkg/restore/actions/crd_v1_preserve_unknown_fields_action.go +++ b/pkg/restore/actions/crd_v1_preserve_unknown_fields_action.go @@ -107,7 +107,7 @@ func (c *CRDV1PreserveUnknownFieldsAction) Execute(input *velero.RestoreItemActi }, nil } -func fromUnstructured(unstructured map[string]interface{}) (*apiextv1.CustomResourceDefinition, error) { +func fromUnstructured(unstructured map[string]any) (*apiextv1.CustomResourceDefinition, error) { var crd apiextv1.CustomResourceDefinition js, err := json.Marshal(unstructured) diff --git a/pkg/restore/actions/csi/pvc_action.go b/pkg/restore/actions/csi/pvc_action.go index 0462bb74c9..ef0143629c 100644 --- a/pkg/restore/actions/csi/pvc_action.go +++ b/pkg/restore/actions/csi/pvc_action.go @@ -598,7 +598,7 @@ func (p *pvcRestoreItemAction) isResourceExist( } func NewPvcRestoreItemAction(f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { crClient, err := f.KubebuilderClient() if err != nil { return nil, err diff --git a/pkg/restore/actions/csi/volumesnapshot_action.go b/pkg/restore/actions/csi/volumesnapshot_action.go index 61af12c675..9bac9a3361 100644 --- a/pkg/restore/actions/csi/volumesnapshot_action.go +++ b/pkg/restore/actions/csi/volumesnapshot_action.go @@ -207,7 +207,7 @@ func (p *volumeSnapshotRestoreItemAction) AreAdditionalItemsReady( func NewVolumeSnapshotRestoreItemAction( f client.Factory) plugincommon.HandlerInitializer { - return func(logger logrus.FieldLogger) (interface{}, error) { + return func(logger logrus.FieldLogger) (any, error) { crClient, err := f.KubebuilderClient() if err != nil { return nil, err diff --git a/pkg/restore/actions/csi/volumesnapshotclass_action.go b/pkg/restore/actions/csi/volumesnapshotclass_action.go index 577445a4bb..34782efe2c 100644 --- a/pkg/restore/actions/csi/volumesnapshotclass_action.go +++ b/pkg/restore/actions/csi/volumesnapshotclass_action.go @@ -106,6 +106,6 @@ func (p *volumeSnapshotClassRestoreItemAction) AreAdditionalItemsReady( } func NewVolumeSnapshotClassRestoreItemAction( - logger logrus.FieldLogger) (interface{}, error) { + logger logrus.FieldLogger) (any, error) { return &volumeSnapshotClassRestoreItemAction{logger}, nil } diff --git a/pkg/restore/actions/csi/volumesnapshotcontent_action.go b/pkg/restore/actions/csi/volumesnapshotcontent_action.go index c00919a279..bea63b53b9 100644 --- a/pkg/restore/actions/csi/volumesnapshotcontent_action.go +++ b/pkg/restore/actions/csi/volumesnapshotcontent_action.go @@ -108,6 +108,6 @@ func (p *volumeSnapshotContentRestoreItemAction) AreAdditionalItemsReady( return true, nil } -func NewVolumeSnapshotContentRestoreItemAction(logger logrus.FieldLogger) (interface{}, error) { +func NewVolumeSnapshotContentRestoreItemAction(logger logrus.FieldLogger) (any, error) { return &volumeSnapshotContentRestoreItemAction{logger}, nil } diff --git a/pkg/restore/actions/dataupload_retrieve_action_test.go b/pkg/restore/actions/dataupload_retrieve_action_test.go index 6bfc7aabfb..c3d262947a 100644 --- a/pkg/restore/actions/dataupload_retrieve_action_test.go +++ b/pkg/restore/actions/dataupload_retrieve_action_test.go @@ -90,7 +90,7 @@ func TestDataUploadRetrieveActionExectue(t *testing.T) { fakeClient := fakeClientBuilder.WithRuntimeObjects(tc.veleroObjs...).Build() - var unstructuredDataUpload map[string]interface{} + var unstructuredDataUpload map[string]any if tc.dataUpload != nil { var err error unstructuredDataUpload, err = runtime.DefaultUnstructuredConverter.ToUnstructured(tc.dataUpload) diff --git a/pkg/restore/actions/pod_volume_restore_action_test.go b/pkg/restore/actions/pod_volume_restore_action_test.go index 4327214e64..08a85d188c 100644 --- a/pkg/restore/actions/pod_volume_restore_action_test.go +++ b/pkg/restore/actions/pod_volume_restore_action_test.go @@ -299,7 +299,7 @@ func TestPodVolumeRestoreActionExecute(t *testing.T) { require.NoError(t, err) // Default to using the same pod for both Item and ItemFromBackup if podFromBackup not provided - var unstructuredPodFromBackup map[string]interface{} + var unstructuredPodFromBackup map[string]any if tc.podFromBackup != nil { unstructuredPodFromBackup, err = runtime.DefaultUnstructuredConverter.ToUnstructured(tc.podFromBackup) require.NoError(t, err) diff --git a/pkg/restore/actions/service_action.go b/pkg/restore/actions/service_action.go index ee392a3810..9de75228e7 100644 --- a/pkg/restore/actions/service_action.go +++ b/pkg/restore/actions/service_action.go @@ -96,7 +96,7 @@ func deleteHealthCheckNodePort(service *corev1api.Service) error { // annotation(HealthCheckNodePort is specified by `kubectl apply` command) lastAppliedConfig, ok := service.Annotations[annotationLastAppliedConfig] if ok { - appliedServiceUnstructured := new(map[string]interface{}) + appliedServiceUnstructured := new(map[string]any) if err := json.Unmarshal([]byte(lastAppliedConfig), appliedServiceUnstructured); err != nil { return errors.WithStack(err) } @@ -119,7 +119,7 @@ func deleteHealthCheckNodePort(service *corev1api.Service) error { if entry.FieldsV1 == nil { continue } - fields := new(map[string]interface{}) + fields := new(map[string]any) if err := json.Unmarshal(entry.FieldsV1.Raw, fields); err != nil { return errors.WithStack(err) } @@ -157,7 +157,7 @@ func deleteNodePorts(service *corev1api.Service) error { if ok { explicitNodePorts := sets.NewString() unnamedPortInts := sets.NewInt() - appliedServiceUnstructured := new(map[string]interface{}) + appliedServiceUnstructured := new(map[string]any) if err := json.Unmarshal([]byte(lastAppliedConfig), appliedServiceUnstructured); err != nil { return errors.WithStack(err) } @@ -170,7 +170,7 @@ func deleteNodePorts(service *corev1api.Service) error { if bool { for _, port := range ports { - p, ok := port.(map[string]interface{}) + p, ok := port.(map[string]any) if !ok { continue } @@ -224,7 +224,7 @@ func deleteNodePorts(service *corev1api.Service) error { if entry.FieldsV1 == nil { continue } - fields := new(map[string]interface{}) + fields := new(map[string]any) if err := json.Unmarshal(entry.FieldsV1.Raw, fields); err != nil { return errors.WithStack(err) } @@ -237,7 +237,7 @@ func deleteNodePorts(service *corev1api.Service) error { continue } for key, port := range ports { - p, ok := port.(map[string]interface{}) + p, ok := port.(map[string]any) if !ok { continue } diff --git a/pkg/restore/actions/service_action_test.go b/pkg/restore/actions/service_action_test.go index e8ed85d698..42c0d290d1 100644 --- a/pkg/restore/actions/service_action_test.go +++ b/pkg/restore/actions/service_action_test.go @@ -49,9 +49,9 @@ func svcJSON(ports ...corev1api.ServicePort) string { return string(data) } -func svcJSONFromUnstructured(ports ...map[string]interface{}) string { - svc := map[string]interface{}{ - "spec": map[string]interface{}{ +func svcJSONFromUnstructured(ports ...map[string]any) string { + svc := map[string]any{ + "spec": map[string]any{ "ports": ports, }, } @@ -259,7 +259,7 @@ func TestServiceActionExecute(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "svc-1", Annotations: map[string]string{ - annotationLastAppliedConfig: svcJSONFromUnstructured(map[string]interface{}{"name": "http", "nodePort": "8080"}), + annotationLastAppliedConfig: svcJSONFromUnstructured(map[string]any{"name": "http", "nodePort": "8080"}), }, }, Spec: corev1api.ServiceSpec{ @@ -275,7 +275,7 @@ func TestServiceActionExecute(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "svc-1", Annotations: map[string]string{ - annotationLastAppliedConfig: svcJSONFromUnstructured(map[string]interface{}{"name": "http", "nodePort": "8080"}), + annotationLastAppliedConfig: svcJSONFromUnstructured(map[string]any{"name": "http", "nodePort": "8080"}), }, }, Spec: corev1api.ServiceSpec{ diff --git a/pkg/restore/merge_service_account.go b/pkg/restore/merge_service_account.go index f77a7730aa..7abaa7ee20 100644 --- a/pkg/restore/merge_service_account.go +++ b/pkg/restore/merge_service_account.go @@ -54,7 +54,7 @@ func mergeServiceAccounts(fromCluster, fromBackup *unstructured.Unstructured) (* } // The DefaultUnstructuredConverter.ToUnstructured function will populate the creation timestamp with the nil value // However, we remove this on both the backup and cluster objects before comparison, and we don't want it in any patches. - delete(desiredUnstructured["metadata"].(map[string]interface{}), "creationTimestamp") + delete(desiredUnstructured["metadata"].(map[string]any), "creationTimestamp") return &unstructured.Unstructured{Object: desiredUnstructured}, nil } diff --git a/pkg/restore/pv_restorer_test.go b/pkg/restore/pv_restorer_test.go index 86ee05e408..8db8a21a86 100644 --- a/pkg/restore/pv_restorer_test.go +++ b/pkg/restore/pv_restorer_test.go @@ -253,7 +253,7 @@ type testUnstructured struct { func newTestUnstructured() *testUnstructured { obj := &testUnstructured{ Unstructured: &unstructured.Unstructured{ - Object: make(map[string]interface{}), + Object: make(map[string]any), }, } @@ -275,15 +275,15 @@ func (obj *testUnstructured) WithStatus(fields ...string) *testUnstructured { return obj.withMap("status", fields...) } -func (obj *testUnstructured) WithMetadataField(field string, value interface{}) *testUnstructured { +func (obj *testUnstructured) WithMetadataField(field string, value any) *testUnstructured { return obj.withMapEntry("metadata", field, value) } -func (obj *testUnstructured) WithSpecField(field string, value interface{}) *testUnstructured { +func (obj *testUnstructured) WithSpecField(field string, value any) *testUnstructured { return obj.withMapEntry("spec", field, value) } -func (obj *testUnstructured) WithStatusField(field string, value interface{}) *testUnstructured { +func (obj *testUnstructured) WithStatusField(field string, value any) *testUnstructured { return obj.withMapEntry("status", field, value) } @@ -297,7 +297,7 @@ func (obj *testUnstructured) WithAnnotations(fields ...string) *testUnstructured } func (obj *testUnstructured) WithAnnotationValues(fieldVals map[string]string) *testUnstructured { - annotations := make(map[string]interface{}) + annotations := make(map[string]any) for field, val := range fieldVals { annotations[field] = val } @@ -312,7 +312,7 @@ func (obj *testUnstructured) WithName(name string) *testUnstructured { } func (obj *testUnstructured) withMap(name string, fields ...string) *testUnstructured { - m := make(map[string]interface{}) + m := make(map[string]any) obj.Object[name] = m for _, field := range fields { @@ -322,14 +322,14 @@ func (obj *testUnstructured) withMap(name string, fields ...string) *testUnstruc return obj } -func (obj *testUnstructured) withMapEntry(mapName, field string, value interface{}) *testUnstructured { - var m map[string]interface{} +func (obj *testUnstructured) withMapEntry(mapName, field string, value any) *testUnstructured { + var m map[string]any if res, ok := obj.Unstructured.Object[mapName]; !ok { - m = make(map[string]interface{}) + m = make(map[string]any) obj.Unstructured.Object[mapName] = m } else { - m = res.(map[string]interface{}) + m = res.(map[string]any) } m[field] = value diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 619db5b87e..bc7aa32f0f 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -777,7 +777,7 @@ func (ctx *restoreContext) processSelectedResource( itemsRestored: len(ctx.restoredItems), } } - ctx.log.WithFields(map[string]interface{}{ + ctx.log.WithFields(map[string]any{ "progress": "", "resource": groupResource.String(), "namespace": selectedItem.targetNamespace, @@ -2039,7 +2039,7 @@ func hasPodVolumeBackup(unstructuredPV *unstructured.Unstructured, ctx *restoreC return found } -func hasDeleteReclaimPolicy(obj map[string]interface{}) bool { +func hasDeleteReclaimPolicy(obj map[string]any) bool { policy, _, _ := unstructured.NestedString(obj, "spec", "persistentVolumeReclaimPolicy") return policy == string(v1.PersistentVolumeReclaimDelete) } @@ -2075,9 +2075,9 @@ func resetMetadata(obj *unstructured.Unstructured) (*unstructured.Unstructured, if !ok { return nil, errors.New("metadata not found") } - metadata, ok := res.(map[string]interface{}) + metadata, ok := res.(map[string]any) if !ok { - return nil, errors.Errorf("metadata was of type %T, expected map[string]interface{}", res) + return nil, errors.Errorf("metadata was of type %T, expected map[string]any", res) } for k := range metadata { diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index 065d23cbe5..bfa767e76a 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -2354,7 +2354,7 @@ func assertRestoredItems(t *testing.T, h *harness, want []*test.APIResource) { t.Logf("%v", string(itemJSON)) - u := make(map[string]interface{}) + u := make(map[string]any) if !assert.NoError(t, json.Unmarshal(itemJSON, &u)) { continue } @@ -3761,7 +3761,7 @@ func Test_resetVolumeBindingInfo(t *testing.T) { kubeutil.KubeAnnBindCompleted, kubeutil.KubeAnnBoundByController, kubeutil.KubeAnnDynamicallyProvisioned, - ).WithSpecField("claimRef", map[string]interface{}{ + ).WithSpecField("claimRef", map[string]any{ "namespace": "ns-1", "name": "pvc-1", "uid": "abc", @@ -3769,7 +3769,7 @@ func Test_resetVolumeBindingInfo(t *testing.T) { expected: newTestUnstructured().WithMetadataField("kind", "persistentVolume"). WithName("pv-1"). WithAnnotations(kubeutil.KubeAnnDynamicallyProvisioned). - WithSpecField("claimRef", map[string]interface{}{ + WithSpecField("claimRef", map[string]any{ "namespace": "ns-1", "name": "pvc-1"}).Unstructured, }, { @@ -3809,7 +3809,7 @@ func TestIsAlreadyExistsError(t *testing.T) { { name: "The input obj isn't service", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "Pod", }, }, @@ -3818,7 +3818,7 @@ func TestIsAlreadyExistsError(t *testing.T) { { name: "The StatusError contains no causes", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "Service", }, }, @@ -3832,7 +3832,7 @@ func TestIsAlreadyExistsError(t *testing.T) { { name: "The causes contains not only port already allocated error", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "Service", }, }, @@ -3852,9 +3852,9 @@ func TestIsAlreadyExistsError(t *testing.T) { { name: "Get already allocated error but the service doesn't exist", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "Service", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "namespace": "default", "name": "test", }, @@ -3878,9 +3878,9 @@ func TestIsAlreadyExistsError(t *testing.T) { builder.ForService("default", "test").Result(), ), obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "Service", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "namespace": "default", "name": "test", }, @@ -3939,7 +3939,7 @@ func TestHasCSIVolumeSnapshot(t *testing.T) { { name: "Invalid PV, expect false.", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": 1, }, }, @@ -3948,10 +3948,10 @@ func TestHasCSIVolumeSnapshot(t *testing.T) { { name: "Cannot find VS, expect false", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "PersistentVolume", "apiVersion": "v1", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "namespace": "default", "name": "test", }, @@ -3962,15 +3962,15 @@ func TestHasCSIVolumeSnapshot(t *testing.T) { { name: "VS's source PVC is nil, expect false", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "PersistentVolume", "apiVersion": "v1", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "namespace": "default", "name": "test", }, - "spec": map[string]interface{}{ - "claimRef": map[string]interface{}{ + "spec": map[string]any{ + "claimRef": map[string]any{ "namespace": "velero", "name": "test", }, @@ -3983,10 +3983,10 @@ func TestHasCSIVolumeSnapshot(t *testing.T) { { name: "PVs claimref is nil, expect false.", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "PersistentVolume", "apiVersion": "v1", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "namespace": "velero", "name": "test", }, @@ -3999,15 +3999,15 @@ func TestHasCSIVolumeSnapshot(t *testing.T) { { name: "Find VS, expect true.", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "PersistentVolume", "apiVersion": "v1", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "namespace": "velero", "name": "test", }, - "spec": map[string]interface{}{ - "claimRef": map[string]interface{}{ + "spec": map[string]any{ + "claimRef": map[string]any{ "namespace": "velero", "name": "test", }, @@ -4048,7 +4048,7 @@ func TestHasSnapshotDataUpload(t *testing.T) { { name: "Invalid PV, expect false.", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": 1, }, }, @@ -4057,10 +4057,10 @@ func TestHasSnapshotDataUpload(t *testing.T) { { name: "PV without ClaimRef, expect false", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "PersistentVolume", "apiVersion": "v1", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "namespace": "default", "name": "test", }, @@ -4073,15 +4073,15 @@ func TestHasSnapshotDataUpload(t *testing.T) { { name: "Cannot find DataUploadResult CM, expect false", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "PersistentVolume", "apiVersion": "v1", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "namespace": "default", "name": "test", }, - "spec": map[string]interface{}{ - "claimRef": map[string]interface{}{ + "spec": map[string]any{ + "claimRef": map[string]any{ "namespace": "velero", "name": "testPVC", }, @@ -4095,15 +4095,15 @@ func TestHasSnapshotDataUpload(t *testing.T) { { name: "Find DataUploadResult CM, expect true", obj: &unstructured.Unstructured{ - Object: map[string]interface{}{ + Object: map[string]any{ "kind": "PersistentVolume", "apiVersion": "v1", - "metadata": map[string]interface{}{ + "metadata": map[string]any{ "namespace": "default", "name": "test", }, - "spec": map[string]interface{}{ - "claimRef": map[string]interface{}{ + "spec": map[string]any{ + "claimRef": map[string]any{ "namespace": "velero", "name": "testPVC", }, diff --git a/pkg/test/comparisons.go b/pkg/test/comparisons.go index 4a0e415739..670cf3cf02 100644 --- a/pkg/test/comparisons.go +++ b/pkg/test/comparisons.go @@ -73,7 +73,7 @@ func CompareActions(t *testing.T, expected, actual []core.Action) { // that the action is a PatchAction, that the patch decodes from JSON // with the provided decode func and has no extraneous fields, and that // the decoded patch matches the expected. -func ValidatePatch(t *testing.T, action core.Action, expected interface{}, decodeFunc func(*json.Decoder) (interface{}, error)) { +func ValidatePatch(t *testing.T, action core.Action, expected any, decodeFunc func(*json.Decoder) (any, error)) { t.Helper() patchAction, ok := action.(core.PatchAction) require.True(t, ok, "action is not a PatchAction") @@ -97,7 +97,7 @@ func TimesAreEqual(t1, t2 time.Time) bool { // AssertDeepEqual asserts the semantic equality of objects. // This function exists in order to make sure time.Time and metav1.Time objects // can be compared correctly. See https://github.com/stretchr/testify/issues/502. -func AssertDeepEqual(t *testing.T, expected, actual interface{}) bool { +func AssertDeepEqual(t *testing.T, expected, actual any) bool { t.Helper() // By default, the equality.Semantic object doesn't have a function for comparing time.Times err := equality.Semantic.AddFunc(TimesAreEqual) diff --git a/pkg/test/helpers.go b/pkg/test/helpers.go index 5c103c5eae..3020cdfeee 100644 --- a/pkg/test/helpers.go +++ b/pkg/test/helpers.go @@ -29,8 +29,8 @@ func UnstructuredOrDie(data string) *unstructured.Unstructured { return o.(*unstructured.Unstructured) } -func GetAsMap(j string) (map[string]interface{}, error) { - m := make(map[string]interface{}) +func GetAsMap(j string) (map[string]any, error) { + m := make(map[string]any) err := json.Unmarshal([]byte(j), &m) return m, err } diff --git a/pkg/test/mock_pod_command_executor.go b/pkg/test/mock_pod_command_executor.go index 2a05914c2d..b8ace0c6e0 100644 --- a/pkg/test/mock_pod_command_executor.go +++ b/pkg/test/mock_pod_command_executor.go @@ -40,7 +40,7 @@ func (h HookExecutionEntry) String() string { return fmt.Sprintf("%s.%s.%s.%s", h.Namespace, h.Name, h.HookName, strings.Join(h.HookCommand, ",")) } -func (e *MockPodCommandExecutor) ExecutePodCommand(log logrus.FieldLogger, item map[string]interface{}, namespace, name, hookName string, hook *v1.ExecHook) error { +func (e *MockPodCommandExecutor) ExecutePodCommand(log logrus.FieldLogger, item map[string]any, namespace, name, hookName string, hook *v1.ExecHook) error { e.HookExecutionLog = append(e.HookExecutionLog, HookExecutionEntry{ Namespace: namespace, Name: name, diff --git a/pkg/test/mocks/VolumeSnapshotLister.go b/pkg/test/mocks/VolumeSnapshotLister.go index b1fb43637d..cd49527a94 100644 --- a/pkg/test/mocks/VolumeSnapshotLister.go +++ b/pkg/test/mocks/VolumeSnapshotLister.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.35.4. DO NOT EDIT. +// Code generated by mockery v2.51.0. DO NOT EDIT. package mocks @@ -20,6 +20,10 @@ type VolumeSnapshotLister struct { func (_m *VolumeSnapshotLister) List(selector labels.Selector) ([]*v1.VolumeSnapshot, error) { ret := _m.Called(selector) + if len(ret) == 0 { + panic("no return value specified for List") + } + var r0 []*v1.VolumeSnapshot var r1 error if rf, ok := ret.Get(0).(func(labels.Selector) ([]*v1.VolumeSnapshot, error)); ok { @@ -46,6 +50,10 @@ func (_m *VolumeSnapshotLister) List(selector labels.Selector) ([]*v1.VolumeSnap func (_m *VolumeSnapshotLister) VolumeSnapshots(namespace string) volumesnapshotv1.VolumeSnapshotNamespaceLister { ret := _m.Called(namespace) + if len(ret) == 0 { + panic("no return value specified for VolumeSnapshots") + } + var r0 volumesnapshotv1.VolumeSnapshotNamespaceLister if rf, ok := ret.Get(0).(func(string) volumesnapshotv1.VolumeSnapshotNamespaceLister); ok { r0 = rf(namespace) diff --git a/pkg/test/tar_writer.go b/pkg/test/tar_writer.go index 6cfcd8bd7c..20706766cc 100644 --- a/pkg/test/tar_writer.go +++ b/pkg/test/tar_writer.go @@ -67,7 +67,7 @@ func (tw *TarWriter) AddItems(groupResource string, items ...metav1.Object) *Tar return tw } -func (tw *TarWriter) Add(name string, obj interface{}) *TarWriter { +func (tw *TarWriter) Add(name string, obj any) *TarWriter { tw.t.Helper() var data []byte diff --git a/pkg/uploader/kopia/shim.go b/pkg/uploader/kopia/shim.go index b6d0bff807..1b9812d487 100644 --- a/pkg/uploader/kopia/shim.go +++ b/pkg/uploader/kopia/shim.go @@ -75,7 +75,7 @@ func (sr *shimRepository) VerifyObject(ctx context.Context, id object.ID) ([]con } // Get one or more manifest data that match the specific manifest id -func (sr *shimRepository) GetManifest(ctx context.Context, id manifest.ID, payload interface{}) (*manifest.EntryMetadata, error) { +func (sr *shimRepository) GetManifest(ctx context.Context, id manifest.ID, payload any) (*manifest.EntryMetadata, error) { repoMani := udmrepo.RepoManifest{ Payload: payload, } @@ -194,7 +194,7 @@ func (sr *shimRepository) NewObjectWriter(ctx context.Context, option object.Wri } // PutManifest saves the given manifest payload with a set of labels. -func (sr *shimRepository) PutManifest(ctx context.Context, labels map[string]string, payload interface{}) (manifest.ID, error) { +func (sr *shimRepository) PutManifest(ctx context.Context, labels map[string]string, payload any) (manifest.ID, error) { id, err := sr.udmRepo.PutManifest(ctx, udmrepo.RepoManifest{ Payload: payload, Metadata: &udmrepo.ManifestEntryMetadata{ @@ -210,7 +210,7 @@ func (sr *shimRepository) DeleteManifest(ctx context.Context, id manifest.ID) er return sr.udmRepo.DeleteManifest(ctx, udmrepo.ID(id)) } -func (sr *shimRepository) ReplaceManifests(ctx context.Context, labels map[string]string, payload interface{}) (manifest.ID, error) { +func (sr *shimRepository) ReplaceManifests(ctx context.Context, labels map[string]string, payload any) (manifest.ID, error) { const minReplaceManifestTimeDelta = 100 * time.Millisecond md, err := sr.FindManifests(ctx, labels) diff --git a/pkg/uploader/kopia/snapshot_test.go b/pkg/uploader/kopia/snapshot_test.go index de621ce85b..2d2379884d 100644 --- a/pkg/uploader/kopia/snapshot_test.go +++ b/pkg/uploader/kopia/snapshot_test.go @@ -50,7 +50,7 @@ type snapshotMockes struct { type mockArgs struct { methodName string - returns []interface{} + returns []any } func injectSnapshotFuncs() *snapshotMockes { @@ -103,65 +103,65 @@ func TestSnapshotSource(t *testing.T) { { name: "regular test", args: []mockArgs{ - {methodName: "LoadSnapshot", returns: []interface{}{manifest, nil}}, - {methodName: "SaveSnapshot", returns: []interface{}{manifest.ID, nil}}, - {methodName: "TreeForSource", returns: []interface{}{nil, nil}}, - {methodName: "ApplyRetentionPolicy", returns: []interface{}{nil, nil}}, - {methodName: "SetPolicy", returns: []interface{}{nil}}, - {methodName: "Upload", returns: []interface{}{manifest, nil}}, - {methodName: "Flush", returns: []interface{}{nil}}, + {methodName: "LoadSnapshot", returns: []any{manifest, nil}}, + {methodName: "SaveSnapshot", returns: []any{manifest.ID, nil}}, + {methodName: "TreeForSource", returns: []any{nil, nil}}, + {methodName: "ApplyRetentionPolicy", returns: []any{nil, nil}}, + {methodName: "SetPolicy", returns: []any{nil}}, + {methodName: "Upload", returns: []any{manifest, nil}}, + {methodName: "Flush", returns: []any{nil}}, }, notError: true, }, { name: "failed to load snapshot, should fallback to full backup and not error", args: []mockArgs{ - {methodName: "LoadSnapshot", returns: []interface{}{manifest, errors.New("failed to load snapshot")}}, - {methodName: "SaveSnapshot", returns: []interface{}{manifest.ID, nil}}, - {methodName: "TreeForSource", returns: []interface{}{nil, nil}}, - {methodName: "ApplyRetentionPolicy", returns: []interface{}{nil, nil}}, - {methodName: "SetPolicy", returns: []interface{}{nil}}, - {methodName: "Upload", returns: []interface{}{manifest, nil}}, - {methodName: "Flush", returns: []interface{}{nil}}, + {methodName: "LoadSnapshot", returns: []any{manifest, errors.New("failed to load snapshot")}}, + {methodName: "SaveSnapshot", returns: []any{manifest.ID, nil}}, + {methodName: "TreeForSource", returns: []any{nil, nil}}, + {methodName: "ApplyRetentionPolicy", returns: []any{nil, nil}}, + {methodName: "SetPolicy", returns: []any{nil}}, + {methodName: "Upload", returns: []any{manifest, nil}}, + {methodName: "Flush", returns: []any{nil}}, }, notError: true, }, { name: "failed to save snapshot", args: []mockArgs{ - {methodName: "LoadSnapshot", returns: []interface{}{manifest, nil}}, - {methodName: "SaveSnapshot", returns: []interface{}{manifest.ID, errors.New("failed to save snapshot")}}, - {methodName: "TreeForSource", returns: []interface{}{nil, nil}}, - {methodName: "ApplyRetentionPolicy", returns: []interface{}{nil, nil}}, - {methodName: "SetPolicy", returns: []interface{}{nil}}, - {methodName: "Upload", returns: []interface{}{manifest, nil}}, - {methodName: "Flush", returns: []interface{}{nil}}, + {methodName: "LoadSnapshot", returns: []any{manifest, nil}}, + {methodName: "SaveSnapshot", returns: []any{manifest.ID, errors.New("failed to save snapshot")}}, + {methodName: "TreeForSource", returns: []any{nil, nil}}, + {methodName: "ApplyRetentionPolicy", returns: []any{nil, nil}}, + {methodName: "SetPolicy", returns: []any{nil}}, + {methodName: "Upload", returns: []any{manifest, nil}}, + {methodName: "Flush", returns: []any{nil}}, }, notError: false, }, { name: "failed to set policy", args: []mockArgs{ - {methodName: "LoadSnapshot", returns: []interface{}{manifest, nil}}, - {methodName: "SaveSnapshot", returns: []interface{}{manifest.ID, nil}}, - {methodName: "TreeForSource", returns: []interface{}{nil, nil}}, - {methodName: "ApplyRetentionPolicy", returns: []interface{}{nil, nil}}, - {methodName: "SetPolicy", returns: []interface{}{errors.New("failed to set policy")}}, - {methodName: "Upload", returns: []interface{}{manifest, nil}}, - {methodName: "Flush", returns: []interface{}{nil}}, + {methodName: "LoadSnapshot", returns: []any{manifest, nil}}, + {methodName: "SaveSnapshot", returns: []any{manifest.ID, nil}}, + {methodName: "TreeForSource", returns: []any{nil, nil}}, + {methodName: "ApplyRetentionPolicy", returns: []any{nil, nil}}, + {methodName: "SetPolicy", returns: []any{errors.New("failed to set policy")}}, + {methodName: "Upload", returns: []any{manifest, nil}}, + {methodName: "Flush", returns: []any{nil}}, }, notError: false, }, { name: "set policy with parallel files upload", args: []mockArgs{ - {methodName: "LoadSnapshot", returns: []interface{}{manifest, nil}}, - {methodName: "SaveSnapshot", returns: []interface{}{manifest.ID, nil}}, - {methodName: "TreeForSource", returns: []interface{}{nil, nil}}, - {methodName: "ApplyRetentionPolicy", returns: []interface{}{nil, nil}}, - {methodName: "SetPolicy", returns: []interface{}{nil}}, - {methodName: "Upload", returns: []interface{}{manifest, nil}}, - {methodName: "Flush", returns: []interface{}{nil}}, + {methodName: "LoadSnapshot", returns: []any{manifest, nil}}, + {methodName: "SaveSnapshot", returns: []any{manifest.ID, nil}}, + {methodName: "TreeForSource", returns: []any{nil, nil}}, + {methodName: "ApplyRetentionPolicy", returns: []any{nil, nil}}, + {methodName: "SetPolicy", returns: []any{nil}}, + {methodName: "Upload", returns: []any{manifest, nil}}, + {methodName: "Flush", returns: []any{nil}}, }, uploaderCfg: map[string]string{ "ParallelFilesUpload": "10", @@ -171,26 +171,26 @@ func TestSnapshotSource(t *testing.T) { { name: "failed to upload snapshot", args: []mockArgs{ - {methodName: "LoadSnapshot", returns: []interface{}{manifest, nil}}, - {methodName: "SaveSnapshot", returns: []interface{}{manifest.ID, nil}}, - {methodName: "TreeForSource", returns: []interface{}{nil, nil}}, - {methodName: "ApplyRetentionPolicy", returns: []interface{}{nil, nil}}, - {methodName: "SetPolicy", returns: []interface{}{nil}}, - {methodName: "Upload", returns: []interface{}{manifest, errors.New("failed to upload snapshot")}}, - {methodName: "Flush", returns: []interface{}{nil}}, + {methodName: "LoadSnapshot", returns: []any{manifest, nil}}, + {methodName: "SaveSnapshot", returns: []any{manifest.ID, nil}}, + {methodName: "TreeForSource", returns: []any{nil, nil}}, + {methodName: "ApplyRetentionPolicy", returns: []any{nil, nil}}, + {methodName: "SetPolicy", returns: []any{nil}}, + {methodName: "Upload", returns: []any{manifest, errors.New("failed to upload snapshot")}}, + {methodName: "Flush", returns: []any{nil}}, }, notError: false, }, { name: "failed to flush repo", args: []mockArgs{ - {methodName: "LoadSnapshot", returns: []interface{}{manifest, nil}}, - {methodName: "SaveSnapshot", returns: []interface{}{manifest.ID, errors.New("failed to save snapshot")}}, - {methodName: "TreeForSource", returns: []interface{}{nil, nil}}, - {methodName: "ApplyRetentionPolicy", returns: []interface{}{nil, nil}}, - {methodName: "SetPolicy", returns: []interface{}{nil}}, - {methodName: "Upload", returns: []interface{}{manifest, nil}}, - {methodName: "Flush", returns: []interface{}{errors.New("failed to flush repo")}}, + {methodName: "LoadSnapshot", returns: []any{manifest, nil}}, + {methodName: "SaveSnapshot", returns: []any{manifest.ID, errors.New("failed to save snapshot")}}, + {methodName: "TreeForSource", returns: []any{nil, nil}}, + {methodName: "ApplyRetentionPolicy", returns: []any{nil, nil}}, + {methodName: "SetPolicy", returns: []any{nil}}, + {methodName: "Upload", returns: []any{manifest, nil}}, + {methodName: "Flush", returns: []any{errors.New("failed to flush repo")}}, }, notError: false, }, @@ -628,13 +628,13 @@ func TestBackup(t *testing.T) { } s := injectSnapshotFuncs() args := []mockArgs{ - {methodName: "LoadSnapshot", returns: []interface{}{manifest, nil}}, - {methodName: "SaveSnapshot", returns: []interface{}{manifest.ID, nil}}, - {methodName: "TreeForSource", returns: []interface{}{nil, nil}}, - {methodName: "ApplyRetentionPolicy", returns: []interface{}{nil, nil}}, - {methodName: "SetPolicy", returns: []interface{}{nil}}, - {methodName: "Upload", returns: []interface{}{manifest, nil}}, - {methodName: "Flush", returns: []interface{}{nil}}, + {methodName: "LoadSnapshot", returns: []any{manifest, nil}}, + {methodName: "SaveSnapshot", returns: []any{manifest.ID, nil}}, + {methodName: "TreeForSource", returns: []any{nil, nil}}, + {methodName: "ApplyRetentionPolicy", returns: []any{nil, nil}}, + {methodName: "SetPolicy", returns: []any{nil}}, + {methodName: "Upload", returns: []any{manifest, nil}}, + {methodName: "Flush", returns: []any{nil}}, } MockFuncs(s, args) if tc.isSnapshotSourceError { diff --git a/pkg/uploader/mocks/uploader.go b/pkg/uploader/mocks/uploader.go index d8b5fa2fda..d76a65f471 100644 --- a/pkg/uploader/mocks/uploader.go +++ b/pkg/uploader/mocks/uploader.go @@ -34,11 +34,11 @@ type Uploader struct { // Execute provides a mock function with given fields: ctx, source, policyTree, sourceInfo, previousManifests func (_m *Uploader) Upload(ctx context.Context, source fs.Entry, policyTree *policy.Tree, sourceInfo snapshot.SourceInfo, previousManifests ...*snapshot.Manifest) (*snapshot.Manifest, error) { - _va := make([]interface{}, len(previousManifests)) + _va := make([]any, len(previousManifests)) for _i := range previousManifests { _va[_i] = previousManifests[_i] } - var _ca []interface{} + var _ca []any _ca = append(_ca, ctx, source, policyTree, sourceInfo) _ca = append(_ca, _va...) ret := _m.Called(_ca...) diff --git a/pkg/uploader/provider/kopia.go b/pkg/uploader/provider/kopia.go index d8c55fa56f..f76d91214a 100644 --- a/pkg/uploader/provider/kopia.go +++ b/pkg/uploader/provider/kopia.go @@ -192,7 +192,7 @@ func (kp *kopiaProvider) RunBackup( return snapshotInfo.ID, false, snapshotInfo.Size, nil } -func (kp *kopiaProvider) GetPassword(param interface{}) (string, error) { +func (kp *kopiaProvider) GetPassword(param any) (string, error) { if kp.credGetter.FromSecret == nil { return "", errors.New("invalid credentials interface") } diff --git a/pkg/util/encode/encode.go b/pkg/util/encode/encode.go index 9704c1a2e1..b7cbdc1c75 100644 --- a/pkg/util/encode/encode.go +++ b/pkg/util/encode/encode.go @@ -78,7 +78,7 @@ func EncoderFor(format string, obj runtime.Object) (runtime.Encoder, error) { } // ToJSONGzip takes arbitrary Go data and encodes it to GZip compressed JSON in a buffer, as well as a description of the data to put into an error should encoding fail. -func ToJSONGzip(data interface{}, desc string) (*bytes.Buffer, []error) { +func ToJSONGzip(data any, desc string) (*bytes.Buffer, []error) { buf := new(bytes.Buffer) gzw := gzip.NewWriter(buf) diff --git a/pkg/util/logging/error_location_hook_test.go b/pkg/util/logging/error_location_hook_test.go index 1dd73d6936..606c6e5259 100644 --- a/pkg/util/logging/error_location_hook_test.go +++ b/pkg/util/logging/error_location_hook_test.go @@ -29,30 +29,30 @@ import ( func TestFire(t *testing.T) { tests := []struct { name string - preEntryFields map[string]interface{} - expectedEntryFields map[string]interface{} + preEntryFields map[string]any + expectedEntryFields map[string]any expectedErr bool }{ { name: "no error", - preEntryFields: map[string]interface{}{"foo": "bar"}, - expectedEntryFields: map[string]interface{}{"foo": "bar"}, + preEntryFields: map[string]any{"foo": "bar"}, + expectedEntryFields: map[string]any{"foo": "bar"}, }, { name: "basic (non-pkg/errors) error", - preEntryFields: map[string]interface{}{logrus.ErrorKey: errors.New("a normal error")}, - expectedEntryFields: map[string]interface{}{logrus.ErrorKey: errors.New("a normal error")}, + preEntryFields: map[string]any{logrus.ErrorKey: errors.New("a normal error")}, + expectedEntryFields: map[string]any{logrus.ErrorKey: errors.New("a normal error")}, }, { name: "non-error logged in error field", - preEntryFields: map[string]interface{}{logrus.ErrorKey: "not an error"}, - expectedEntryFields: map[string]interface{}{logrus.ErrorKey: "not an error"}, + preEntryFields: map[string]any{logrus.ErrorKey: "not an error"}, + expectedEntryFields: map[string]any{logrus.ErrorKey: "not an error"}, expectedErr: false, }, { name: "pkg/errors error", - preEntryFields: map[string]interface{}{logrus.ErrorKey: pkgerrs.New("a pkg/errors error")}, - expectedEntryFields: map[string]interface{}{ + preEntryFields: map[string]any{logrus.ErrorKey: pkgerrs.New("a pkg/errors error")}, + expectedEntryFields: map[string]any{ logrus.ErrorKey: pkgerrs.New("a pkg/errors error"), errorFileField: "", errorFunctionField: "github.com/vmware-tanzu/velero/pkg/util/logging.TestFire", @@ -60,12 +60,12 @@ func TestFire(t *testing.T) { }, { name: "already have error file and function fields", - preEntryFields: map[string]interface{}{ + preEntryFields: map[string]any{ logrus.ErrorKey: pkgerrs.New("a pkg/errors error"), errorFileField: "some_file.go:123", errorFunctionField: "SomeFunction", }, - expectedEntryFields: map[string]interface{}{ + expectedEntryFields: map[string]any{ logrus.ErrorKey: pkgerrs.New("a pkg/errors error"), errorFileField: "some_file.go:123", errorFunctionField: "SomeFunction", diff --git a/test/e2e/basic/api-group/enable_api_group_versions.go b/test/e2e/basic/api-group/enable_api_group_versions.go index c0eb770626..13ee3a39e1 100644 --- a/test/e2e/basic/api-group/enable_api_group_versions.go +++ b/test/e2e/basic/api-group/enable_api_group_versions.go @@ -419,20 +419,20 @@ func resourceInfo(ctx context.Context, g, v, r string, index int) (map[string]ma return nil, errors.Wrap(err, errMsg) } - var info map[string]interface{} + var info map[string]any if err := json.Unmarshal([]byte(stdout), &info); err != nil { return nil, errors.Wrap(err, "unmarshal resource info JSON") } - items := info["items"].([]interface{}) + items := info["items"].([]any) if len(items) < 1 { return nil, errors.New("resource info is empty") } - item := items[0].(map[string]interface{}) - metadata := item["metadata"].(map[string]interface{}) - annotations := metadata["annotations"].(map[string]interface{}) - specs := item["spec"].(map[string]interface{}) + item := items[0].(map[string]any) + metadata := item["metadata"].(map[string]any) + annotations := metadata["annotations"].(map[string]any) + specs := item["spec"].(map[string]any) annoSpec := make(map[string]map[string]string) diff --git a/test/perf/e2e_suite_test.go b/test/perf/e2e_suite_test.go index cb4522d699..48a5ceec9e 100644 --- a/test/perf/e2e_suite_test.go +++ b/test/perf/e2e_suite_test.go @@ -88,7 +88,7 @@ func initConfig() error { ReportData = &E2EReport{ TestDescription: VeleroCfg.TestCaseDescribe, - OtherFields: make(map[string]interface{}), + OtherFields: make(map[string]any), } return nil diff --git a/test/perf/metrics/monitor.go b/test/perf/metrics/monitor.go index c98fd30134..e8f746ac62 100644 --- a/test/perf/metrics/monitor.go +++ b/test/perf/metrics/monitor.go @@ -82,11 +82,11 @@ func (m *MetricsCollector) UpdateOneTimeMetrics() { } // GetMetrics returns the metrics from all metrics -func (m *MetricsCollector) GetMetrics() map[string]interface{} { +func (m *MetricsCollector) GetMetrics() map[string]any { m.Mu.Lock() // Acquire the lock before accessing shared resources defer m.Mu.Unlock() // Release the lock after the function returns - dataMap := make(map[string]interface{}) + dataMap := make(map[string]any) resData := make(map[string]([]map[string]map[string]string)) for _, metric := range m.Metrics { monitorMetrics := metric.GetMetrics() @@ -102,7 +102,7 @@ func (m *MetricsCollector) GetMetrics() map[string]interface{} { } for _, metric := range m.OneTimeMetrics { - oneTimeMetricsMap := make(map[string]interface{}) + oneTimeMetricsMap := make(map[string]any) monitorMetrics := metric.GetMetrics() for key, value := range monitorMetrics { oneTimeMetricsMap[key] = value diff --git a/test/pkg/client/config.go b/test/pkg/client/config.go index 7546a0ac4c..687c303e7b 100644 --- a/test/pkg/client/config.go +++ b/test/pkg/client/config.go @@ -33,9 +33,9 @@ const ( ConfigKeyColorized = "colorized" ) -// VeleroConfig is a map of strings to interface{} for deserializing Velero client config options. +// VeleroConfig is a map of strings to any for deserializing Velero client config options. // The alias is a way to attach type-asserting convenience methods. -type VeleroConfig map[string]interface{} +type VeleroConfig map[string]any // LoadConfig loads the Velero client configuration file and returns it as a VeleroConfig. If the // file does not exist, an empty map is returned. diff --git a/test/pkg/client/factory_test.go b/test/pkg/client/factory_test.go index d257b88b57..5df2e07fd8 100644 --- a/test/pkg/client/factory_test.go +++ b/test/pkg/client/factory_test.go @@ -31,14 +31,14 @@ func TestFactory(t *testing.T) { // Env variable should set the namespace if no config or argument are used os.Setenv("VELERO_NAMESPACE", "env-velero") - f := NewFactory("velero", "", make(map[string]interface{})) + f := NewFactory("velero", "", make(map[string]any)) assert.Equal(t, "env-velero", f.Namespace()) os.Unsetenv("VELERO_NAMESPACE") // Argument should change the namespace - f = NewFactory("velero", "", make(map[string]interface{})) + f = NewFactory("velero", "", make(map[string]any)) s := "flag-velero" flags := new(pflag.FlagSet) @@ -50,7 +50,7 @@ func TestFactory(t *testing.T) { // An argument overrides the env variable if both are set. os.Setenv("VELERO_NAMESPACE", "env-velero") - f = NewFactory("velero", "", make(map[string]interface{})) + f = NewFactory("velero", "", make(map[string]any)) flags = new(pflag.FlagSet) f.BindFlags(flags) diff --git a/test/types.go b/test/types.go index 35a1502c2d..552b9e38d7 100644 --- a/test/types.go +++ b/test/types.go @@ -63,8 +63,8 @@ var UUIDgen uuid.UUID var VeleroCfg VeleroConfig type E2EReport struct { - TestDescription string `yaml:"Test Description"` - OtherFields map[string]interface{} `yaml:",inline"` + TestDescription string `yaml:"Test Description"` + OtherFields map[string]any `yaml:",inline"` } var ReportData *E2EReport diff --git a/test/util/report/report.go b/test/util/report/report.go index 91ec876b17..6d5955392c 100644 --- a/test/util/report/report.go +++ b/test/util/report/report.go @@ -47,6 +47,6 @@ func GenerateYamlReport() error { return nil } -func AddTestSuitData(dataMap map[string]interface{}, testSuitDesc string) { +func AddTestSuitData(dataMap map[string]any, testSuitDesc string) { test.ReportData.OtherFields[testSuitDesc] = dataMap } diff --git a/test/util/velero/install.go b/test/util/velero/install.go index 027ca43048..e8760e21fe 100644 --- a/test/util/velero/install.go +++ b/test/util/velero/install.go @@ -478,7 +478,7 @@ func patchResources(resources *unstructured.UnstructuredList, namespace string, ".dockerconfigjson": credential, }, } - resource.Object["imagePullSecrets"] = []map[string]interface{}{ + resource.Object["imagePullSecrets"] = []map[string]any{ { "name": "image-pull-secret", }, @@ -559,7 +559,7 @@ func patchResources(resources *unstructured.UnstructuredList, namespace string, return nil } -func toUnstructured(res interface{}) (unstructured.Unstructured, error) { +func toUnstructured(res any) (unstructured.Unstructured, error) { un := unstructured.Unstructured{} data, err := json.Marshal(res) if err != nil {