chore: enable use-any from revive

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
Matthieu MOREL
2025-01-17 07:58:10 +01:00
parent 5b1738abf8
commit cbba3bdde7
139 changed files with 798 additions and 799 deletions
@@ -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")},
},
)
}
@@ -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")},
},
)
}
@@ -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")},
},
)
}
+30 -30
View File
@@ -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])
}
+11 -11
View File
@@ -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...)
@@ -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,
+2 -2
View File
@@ -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 {
@@ -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 {
@@ -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
@@ -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")},
},
)
}
@@ -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)
@@ -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")},
},
)
}
@@ -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")},
},
)
}
@@ -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")},
},
)
}
@@ -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)
@@ -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")},
},
)
}
+1 -1
View File
@@ -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
}
@@ -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),
@@ -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,
},
}}
@@ -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
}
@@ -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),
@@ -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,
},
}}
@@ -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
}
@@ -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++
+1 -1
View File
@@ -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
}
+4 -4
View File
@@ -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
}
+1 -1
View File
@@ -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
}
@@ -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),
+2 -2
View File
@@ -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
}
@@ -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
}
@@ -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),
@@ -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,
},
}}
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -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),
+1 -1
View File
@@ -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
}
+1 -1
View File
@@ -24,7 +24,7 @@ import (
)
func TestPluginImplementationsAreGRPCPlugins(t *testing.T) {
pluginImpls := []interface{}{
pluginImpls := []any{
new(VolumeSnapshotterPlugin),
new(BackupItemActionPlugin),
new(ObjectStorePlugin),
+1 -1
View File
@@ -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
}
@@ -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),
@@ -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
}
@@ -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),
+1 -1
View File
@@ -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
}
@@ -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),