Initial implementation of plugin version v2: Adding context object

This commit is contained in:
Hoang, Phuong
2021-07-22 00:20:37 -07:00
committed by Bridget McErlean
parent 9f54451e58
commit b059030666
48 changed files with 1652 additions and 245 deletions

View File

@@ -73,6 +73,12 @@ func (b *clientBuilder) clientConfig() *hcplugin.ClientConfig {
string(framework.PluginKindPluginLister): &framework.PluginListerPlugin{},
string(framework.PluginKindRestoreItemAction): framework.NewRestoreItemActionPlugin(framework.ClientLogger(b.clientLogger)),
string(framework.PluginKindDeleteItemAction): framework.NewDeleteItemActionPlugin(framework.ClientLogger(b.clientLogger)),
// Version 2
string(framework.PluginKindBackupItemActionV2): framework.NewBackupItemActionPlugin(framework.ClientLogger(b.clientLogger)),
string(framework.PluginKindVolumeSnapshotterV2): framework.NewVolumeSnapshotterPlugin(framework.ClientLogger(b.clientLogger)),
string(framework.PluginKindObjectStoreV2): framework.NewObjectStorePlugin(framework.ClientLogger(b.clientLogger)),
string(framework.PluginKindRestoreItemActionV2): framework.NewRestoreItemActionPlugin(framework.ClientLogger(b.clientLogger)),
string(framework.PluginKindDeleteItemActionV2): framework.NewDeleteItemActionPlugin(framework.ClientLogger(b.clientLogger)),
},
Logger: b.pluginLogger,
Cmd: exec.Command(b.commandName, b.commandArgs...),

View File

@@ -1,5 +1,5 @@
/*
Copyright 2020 the Velero contributors.
Copyright 2021 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,40 +17,44 @@ limitations under the License.
package clientmgmt
import (
"errors"
"strings"
"sync"
"github.com/sirupsen/logrus"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
backupitemactionv2 "github.com/vmware-tanzu/velero/pkg/plugin/velero/backupitemaction/v2"
deleteitemactionv2 "github.com/vmware-tanzu/velero/pkg/plugin/velero/deleteitemaction/v2"
objectstorev2 "github.com/vmware-tanzu/velero/pkg/plugin/velero/objectstore/v2"
restoreitemactionv2 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v2"
volumesnapshotterv2 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v2"
)
// Manager manages the lifecycles of plugins.
type Manager interface {
// GetObjectStore returns the ObjectStore plugin for name.
GetObjectStore(name string) (velero.ObjectStore, error)
GetObjectStore(name string) (objectstorev2.ObjectStore, error)
// GetVolumeSnapshotter returns the VolumeSnapshotter plugin for name.
GetVolumeSnapshotter(name string) (velero.VolumeSnapshotter, error)
GetVolumeSnapshotter(name string) (volumesnapshotterv2.VolumeSnapshotter, error)
// GetBackupItemActions returns all backup item action plugins.
GetBackupItemActions() ([]velero.BackupItemAction, error)
GetBackupItemActions() ([]backupitemactionv2.BackupItemAction, error)
// GetBackupItemAction returns the backup item action plugin for name.
GetBackupItemAction(name string) (velero.BackupItemAction, error)
GetBackupItemAction(name string) (backupitemactionv2.BackupItemAction, error)
// GetRestoreItemActions returns all restore item action plugins.
GetRestoreItemActions() ([]velero.RestoreItemAction, error)
GetRestoreItemActions() ([]restoreitemactionv2.RestoreItemAction, error)
// GetRestoreItemAction returns the restore item action plugin for name.
GetRestoreItemAction(name string) (velero.RestoreItemAction, error)
GetRestoreItemAction(name string) (restoreitemactionv2.RestoreItemAction, error)
// GetDeleteItemActions returns all delete item action plugins.
GetDeleteItemActions() ([]velero.DeleteItemAction, error)
GetDeleteItemActions() ([]deleteitemactionv2.DeleteItemAction, error)
// GetDeleteItemAction returns the delete item action plugin for name.
GetDeleteItemAction(name string) (velero.DeleteItemAction, error)
GetDeleteItemAction(name string) (deleteitemactionv2.DeleteItemAction, error)
// CleanupClients terminates all of the Manager's running plugin processes.
CleanupClients()
@@ -92,7 +96,7 @@ func (m *manager) CleanupClients() {
m.lock.Unlock()
}
// getRestartableProcess returns a restartableProcess for a plugin identified by kind and name, creating a
// getRestartableProcessV2 returns a restartableProcess for a plugin identified by kind and name, creating a
// restartableProcess if it is the first time it has been requested.
func (m *manager) getRestartableProcess(kind framework.PluginKind, name string) (RestartableProcess, error) {
m.lock.Lock()
@@ -130,38 +134,61 @@ func (m *manager) getRestartableProcess(kind framework.PluginKind, name string)
}
// GetObjectStore returns a restartableObjectStore for name.
func (m *manager) GetObjectStore(name string) (velero.ObjectStore, error) {
func (m *manager) GetObjectStore(name string) (objectstorev2.ObjectStore, error) {
name = sanitizeName(name)
restartableProcess, err := m.getRestartableProcess(framework.PluginKindObjectStore, name)
restartableProcess, err := m.getRestartableProcess(framework.PluginKindObjectStoreV2, name)
if err != nil {
return nil, err
// Check if plugin was not found
if errors.Is(err, &pluginNotFoundError{}) {
// Try again but with previous version
restartableProcess, err := m.getRestartableProcess(framework.PluginKindObjectStore, name)
if err != nil {
// No v1 version found, return
return nil, err
}
// Adapt v1 plugin to v2
return newAdaptedV1ObjectStore(name, restartableProcess), nil
} else {
return nil, err
}
}
r := newRestartableObjectStore(name, restartableProcess)
return r, nil
return newRestartableObjectStoreV2(name, restartableProcess), nil
}
// GetVolumeSnapshotter returns a restartableVolumeSnapshotter for name.
func (m *manager) GetVolumeSnapshotter(name string) (velero.VolumeSnapshotter, error) {
func (m *manager) GetVolumeSnapshotter(name string) (volumesnapshotterv2.VolumeSnapshotter, error) {
name = sanitizeName(name)
restartableProcess, err := m.getRestartableProcess(framework.PluginKindVolumeSnapshotter, name)
restartableProcess, err := m.getRestartableProcess(framework.PluginKindVolumeSnapshotterV2, name)
if err != nil {
return nil, err
// Check if plugin was not found
if errors.Is(err, &pluginNotFoundError{}) {
// Try again but with previous version
restartableProcess, err := m.getRestartableProcess(framework.PluginKindVolumeSnapshotter, name)
if err != nil {
// No v1 version found, return
return nil, err
}
// Adapt v1 plugin to v2
return newAdaptedV1VolumeSnapshotter(name, restartableProcess), nil
} else {
return nil, err
}
}
r := newRestartableVolumeSnapshotter(name, restartableProcess)
r := newRestartableVolumeSnapshotterV2(name, restartableProcess)
return r, nil
}
// GetBackupItemActions returns all backup item actions as restartableBackupItemActions.
func (m *manager) GetBackupItemActions() ([]velero.BackupItemAction, error) {
list := m.registry.List(framework.PluginKindBackupItemAction)
func (m *manager) GetBackupItemActions() ([]backupitemactionv2.BackupItemAction, error) {
listv1 := m.registry.List(framework.PluginKindBackupItemAction)
listv2 := m.registry.List(framework.PluginKindBackupItemActionV2)
list := append(listv1, listv2...)
actions := make([]velero.BackupItemAction, 0, len(list))
actions := make([]backupitemactionv2.BackupItemAction, 0, len(list))
for i := range list {
id := list[i]
@@ -178,23 +205,37 @@ func (m *manager) GetBackupItemActions() ([]velero.BackupItemAction, error) {
}
// GetBackupItemAction returns a restartableBackupItemAction for name.
func (m *manager) GetBackupItemAction(name string) (velero.BackupItemAction, error) {
func (m *manager) GetBackupItemAction(name string) (backupitemactionv2.BackupItemAction, error) {
name = sanitizeName(name)
restartableProcess, err := m.getRestartableProcess(framework.PluginKindBackupItemAction, name)
restartableProcess, err := m.getRestartableProcess(framework.PluginKindBackupItemActionV2, name)
if err != nil {
return nil, err
// Check if plugin was not found
if errors.Is(err, &pluginNotFoundError{}) {
// Try again but with previous version
restartableProcess, err := m.getRestartableProcess(framework.PluginKindBackupItemAction, name)
if err != nil {
// No v1 version found, return
return nil, err
}
// Adapt v1 plugin to v2
return newAdaptedV1BackupItemAction(name, restartableProcess), nil
} else {
return nil, err
}
}
r := newRestartableBackupItemAction(name, restartableProcess)
r := newRestartableBackupItemActionV2(name, restartableProcess)
return r, nil
}
// GetRestoreItemActions returns all restore item actions as restartableRestoreItemActions.
func (m *manager) GetRestoreItemActions() ([]velero.RestoreItemAction, error) {
list := m.registry.List(framework.PluginKindRestoreItemAction)
func (m *manager) GetRestoreItemActions() ([]restoreitemactionv2.RestoreItemAction, error) {
listv1 := m.registry.List(framework.PluginKindRestoreItemAction)
listv2 := m.registry.List(framework.PluginKindRestoreItemActionV2)
list := append(listv1, listv2...)
actions := make([]velero.RestoreItemAction, 0, len(list))
actions := make([]restoreitemactionv2.RestoreItemAction, 0, len(list))
for i := range list {
id := list[i]
@@ -211,23 +252,37 @@ func (m *manager) GetRestoreItemActions() ([]velero.RestoreItemAction, error) {
}
// GetRestoreItemAction returns a restartableRestoreItemAction for name.
func (m *manager) GetRestoreItemAction(name string) (velero.RestoreItemAction, error) {
func (m *manager) GetRestoreItemAction(name string) (restoreitemactionv2.RestoreItemAction, error) {
name = sanitizeName(name)
restartableProcess, err := m.getRestartableProcess(framework.PluginKindRestoreItemAction, name)
restartableProcess, err := m.getRestartableProcess(framework.PluginKindRestoreItemActionV2, name)
if err != nil {
return nil, err
// Check if plugin was not found
if errors.Is(err, &pluginNotFoundError{}) {
// Try again but with previous version
restartableProcess, err := m.getRestartableProcess(framework.PluginKindRestoreItemAction, name)
if err != nil {
// No v1 version found, return
return nil, err
}
// Adapt v1 plugin to v2
return newAdaptedV1RestoreItemAction(name, restartableProcess), nil
} else {
return nil, err
}
}
r := newRestartableRestoreItemAction(name, restartableProcess)
r := newRestartableRestoreItemActionV2(name, restartableProcess)
return r, nil
}
// GetDeleteItemActions returns all delete item actions as restartableDeleteItemActions.
func (m *manager) GetDeleteItemActions() ([]velero.DeleteItemAction, error) {
list := m.registry.List(framework.PluginKindDeleteItemAction)
func (m *manager) GetDeleteItemActions() ([]deleteitemactionv2.DeleteItemAction, error) {
listv1 := m.registry.List(framework.PluginKindDeleteItemAction)
listv2 := m.registry.List(framework.PluginKindDeleteItemActionV2)
list := append(listv1, listv2...)
actions := make([]velero.DeleteItemAction, 0, len(list))
actions := make([]deleteitemactionv2.DeleteItemAction, 0, len(list))
for i := range list {
id := list[i]
@@ -244,15 +299,27 @@ func (m *manager) GetDeleteItemActions() ([]velero.DeleteItemAction, error) {
}
// GetDeleteItemAction returns a restartableDeleteItemAction for name.
func (m *manager) GetDeleteItemAction(name string) (velero.DeleteItemAction, error) {
func (m *manager) GetDeleteItemAction(name string) (deleteitemactionv2.DeleteItemAction, error) {
name = sanitizeName(name)
restartableProcess, err := m.getRestartableProcess(framework.PluginKindDeleteItemAction, name)
restartableProcess, err := m.getRestartableProcess(framework.PluginKindDeleteItemActionV2, name)
if err != nil {
return nil, err
// Check if plugin was not found
if errors.Is(err, &pluginNotFoundError{}) {
// Try again but with previous version
restartableProcess, err := m.getRestartableProcess(framework.PluginKindDeleteItemAction, name)
if err != nil {
// No v1 version found, return
return nil, err
}
// Adapt v1 plugin to v2
return newAdaptedV1DeleteItemAction(name, restartableProcess), nil
} else {
return nil, err
}
}
r := newRestartableDeleteItemAction(name, restartableProcess)
r := newRestartableDeleteItemActionV2(name, restartableProcess)
return r, nil
}

View File

@@ -0,0 +1,97 @@
/*
Copyright 2018, 2021 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package clientmgmt
import (
"context"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
backupitemactionv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/backupitemaction/v1"
)
type restartableAdaptedV1BackupItemAction struct {
key kindAndName
sharedPluginProcess RestartableProcess
}
// newAdaptedV1BackupItemAction returns a new restartableAdaptedV1BackupItemAction.
func newAdaptedV1BackupItemAction(name string, sharedPluginProcess RestartableProcess) *restartableAdaptedV1BackupItemAction {
r := &restartableAdaptedV1BackupItemAction{
key: kindAndName{kind: framework.PluginKindBackupItemAction, name: name},
sharedPluginProcess: sharedPluginProcess,
}
return r
}
// getBackupItemAction returns the backup item action for this restartableAdaptedV1BackupItemAction. It does *not* restart the
// plugin process.
func (r *restartableAdaptedV1BackupItemAction) getBackupItemAction() (backupitemactionv1.BackupItemAction, error) {
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
if err != nil {
return nil, err
}
backupItemAction, ok := plugin.(backupitemactionv1.BackupItemAction)
if !ok {
return nil, errors.Errorf("%T is not a BackupItemAction!", plugin)
}
return backupItemAction, nil
}
// getDelegate restarts the plugin process (if needed) and returns the backup item action for this restartableAdaptedV1BackupItemAction.
func (r *restartableAdaptedV1BackupItemAction) getDelegate() (backupitemactionv1.BackupItemAction, error) {
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
return nil, err
}
return r.getBackupItemAction()
}
// AppliesTo restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1BackupItemAction) AppliesTo() (velero.ResourceSelector, error) {
delegate, err := r.getDelegate()
if err != nil {
return velero.ResourceSelector{}, err
}
return delegate.AppliesTo()
}
// Execute restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1BackupItemAction) Execute(item runtime.Unstructured, backup *api.Backup) (runtime.Unstructured, []velero.ResourceIdentifier, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, nil, err
}
return delegate.Execute(item, backup)
}
// Version 2: simply discard ctx and call version 1 function.
// ExecuteV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1BackupItemAction) ExecuteV2(ctx context.Context, item runtime.Unstructured, backup *api.Backup) (runtime.Unstructured, []velero.ResourceIdentifier, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, nil, err
}
return delegate.Execute(item, backup)
}

View File

@@ -0,0 +1,238 @@
/*
Copyright 2021 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package clientmgmt
import (
"context"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"io"
"time"
"github.com/pkg/errors"
objectstorev1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/objectstore/v1"
)
// restartableAdaptedV1ObjectStore is restartableAdaptedV1ObjectStore version 1 adaptive to version 2 plugin
type restartableAdaptedV1ObjectStore struct {
restartableObjectStore
}
// newAdaptedV1ObjectStore returns a new restartableAdaptedV1ObjectStore.
func newAdaptedV1ObjectStore(name string, sharedPluginProcess RestartableProcess) *restartableAdaptedV1ObjectStore {
key := kindAndName{kind: framework.PluginKindObjectStore, name: name}
r := &restartableAdaptedV1ObjectStore{
restartableObjectStore: restartableObjectStore{
key: key,
sharedPluginProcess: sharedPluginProcess,
},
}
// Register our reinitializer so we can reinitialize after a restart with r.config.
sharedPluginProcess.addReinitializer(key, r)
return r
}
// reinitialize reinitializes a re-dispensed plugin using the initial data passed to Init().
func (r *restartableAdaptedV1ObjectStore) reinitialize(dispensed interface{}) error {
objectStore, ok := dispensed.(objectstorev1.ObjectStore)
if !ok {
return errors.Errorf("%T is not a ObjectStore!", dispensed)
}
return r.init(objectStore, r.config)
}
// getObjectStore returns the object store for this restartableObjectStore. It does *not* restart the
// plugin process.
func (r *restartableAdaptedV1ObjectStore) getObjectStore() (objectstorev1.ObjectStore, error) {
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
if err != nil {
return nil, err
}
objectStore, ok := plugin.(objectstorev1.ObjectStore)
if !ok {
return nil, errors.Errorf("%T is not a ObjectStore!", plugin)
}
return objectStore, nil
}
// getDelegate restarts the plugin process (if needed) and returns the object store for this restartableObjectStore.
func (r *restartableAdaptedV1ObjectStore) getDelegate() (objectstorev1.ObjectStore, error) {
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
return nil, err
}
return r.getObjectStore()
}
// Init initializes the object store instance using config. If this is the first invocation, r stores config for future
// reinitialization needs. Init does NOT restart the shared plugin process. Init may only be called once.
func (r *restartableAdaptedV1ObjectStore) Init(config map[string]string) error {
if r.config != nil {
return errors.Errorf("already initialized")
}
// Not using getDelegate() to avoid possible infinite recursion
delegate, err := r.getObjectStore()
if err != nil {
return err
}
r.config = config
return r.init(delegate, config)
}
func (r *restartableAdaptedV1ObjectStore) InitV2(ctx context.Context, config map[string]string) error {
return r.Init(config)
}
// init calls Init on objectStore with config. This is split out from Init() so that both Init() and reinitialize() may
// call it using a specific ObjectStore.
func (r *restartableAdaptedV1ObjectStore) init(objectStore objectstorev1.ObjectStore, config map[string]string) error {
return objectStore.Init(config)
}
// PutObject restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) PutObject(bucket string, key string, body io.Reader) error {
delegate, err := r.getDelegate()
if err != nil {
return err
}
return delegate.PutObject(bucket, key, body)
}
// ObjectExists restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) ObjectExists(bucket, key string) (bool, error) {
delegate, err := r.getDelegate()
if err != nil {
return false, err
}
return delegate.ObjectExists(bucket, key)
}
// GetObject restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) GetObject(bucket string, key string) (io.ReadCloser, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.GetObject(bucket, key)
}
// ListCommonPrefixes restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) ListCommonPrefixes(bucket string, prefix string, delimiter string) ([]string, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.ListCommonPrefixes(bucket, prefix, delimiter)
}
// ListObjects restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) ListObjects(bucket string, prefix string) ([]string, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.ListObjects(bucket, prefix)
}
// DeleteObject restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) DeleteObject(bucket string, key string) error {
delegate, err := r.getDelegate()
if err != nil {
return err
}
return delegate.DeleteObject(bucket, key)
}
// CreateSignedURL restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) CreateSignedURL(bucket string, key string, ttl time.Duration) (string, error) {
delegate, err := r.getDelegate()
if err != nil {
return "", err
}
return delegate.CreateSignedURL(bucket, key, ttl)
}
// Version 2. Simply discard ctx.
// PutObjectV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) PutObjectV2(ctx context.Context, bucket string, key string, body io.Reader) error {
delegate, err := r.getDelegate()
if err != nil {
return err
}
return delegate.PutObject(bucket, key, body)
}
// ObjectExistsV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) ObjectExistsV2(ctx context.Context, bucket, key string) (bool, error) {
delegate, err := r.getDelegate()
if err != nil {
return false, err
}
return delegate.ObjectExists(bucket, key)
}
// GetObjectV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) GetObjectV2(ctx context.Context, bucket string, key string) (io.ReadCloser, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.GetObject(bucket, key)
}
// ListCommonPrefixesV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) ListCommonPrefixesV2(
ctx context.Context, bucket string, prefix string, delimiter string) ([]string, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.ListCommonPrefixes(bucket, prefix, delimiter)
}
// ListObjectsV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) ListObjectsV2(ctx context.Context, bucket string, prefix string) ([]string, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.ListObjects(bucket, prefix)
}
// DeleteObjectV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) DeleteObjectV2(ctx context.Context, bucket string, key string) error {
delegate, err := r.getDelegate()
if err != nil {
return err
}
return delegate.DeleteObject(bucket, key)
}
// CreateSignedURLV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1ObjectStore) CreateSignedURLV2(ctx context.Context, bucket string, key string, ttl time.Duration) (string, error) {
delegate, err := r.getDelegate()
if err != nil {
return "", err
}
return delegate.CreateSignedURL(bucket, key, ttl)
}

View File

@@ -0,0 +1,97 @@
/*
Copyright 2021 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package clientmgmt
import (
"context"
"github.com/pkg/errors"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
restoreitemactionv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
)
type restartableAdaptedV1RestoreItemAction struct {
key kindAndName
sharedPluginProcess RestartableProcess
config map[string]string
}
// newRestartableRestoreItemAction returns a new restartableRestoreItemAction.
func newAdaptedV1RestoreItemAction(name string, sharedPluginProcess RestartableProcess) *restartableAdaptedV1RestoreItemAction {
r := &restartableAdaptedV1RestoreItemAction{
key: kindAndName{kind: framework.PluginKindRestoreItemAction, name: name},
sharedPluginProcess: sharedPluginProcess,
}
return r
}
// getRestoreItemAction returns the restore item action for this restartableRestoreItemAction. It does *not* restart the
// plugin process.
func (r *restartableAdaptedV1RestoreItemAction) getRestoreItemAction() (restoreitemactionv1.RestoreItemAction, error) {
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
if err != nil {
return nil, err
}
restoreItemAction, ok := plugin.(restoreitemactionv1.RestoreItemAction)
if !ok {
return nil, errors.Errorf("%T is not a RestoreItemAction!", plugin)
}
return restoreItemAction, nil
}
// getDelegate restarts the plugin process (if needed) and returns the restore item action for this restartableRestoreItemAction.
func (r *restartableAdaptedV1RestoreItemAction) getDelegate() (restoreitemactionv1.RestoreItemAction, error) {
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
return nil, err
}
return r.getRestoreItemAction()
}
// AppliesTo restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1RestoreItemAction) AppliesTo() (velero.ResourceSelector, error) {
delegate, err := r.getDelegate()
if err != nil {
return velero.ResourceSelector{}, err
}
return delegate.AppliesTo()
}
// Execute restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1RestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.Execute(input)
}
// ExecuteV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableAdaptedV1RestoreItemAction) ExecuteV2(
ctx context.Context, input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.Execute(input)
}

View File

@@ -1,5 +1,5 @@
/*
Copyright 2018 the Velero contributors.
Copyright 2018, 2021 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,12 +17,15 @@ limitations under the License.
package clientmgmt
import (
"context"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
backupitemactionv2 "github.com/vmware-tanzu/velero/pkg/plugin/velero/backupitemaction/v2"
)
// restartableBackupItemAction is a backup item action for a given implementation (such as "pod"). It is associated with
@@ -34,10 +37,10 @@ type restartableBackupItemAction struct {
sharedPluginProcess RestartableProcess
}
// newRestartableBackupItemAction returns a new restartableBackupItemAction.
func newRestartableBackupItemAction(name string, sharedPluginProcess RestartableProcess) *restartableBackupItemAction {
// newRestartableBackupItemActionV2 returns a new restartableBackupItemAction.
func newRestartableBackupItemActionV2(name string, sharedPluginProcess RestartableProcess) *restartableBackupItemAction {
r := &restartableBackupItemAction{
key: kindAndName{kind: framework.PluginKindBackupItemAction, name: name},
key: kindAndName{kind: framework.PluginKindBackupItemActionV2, name: name},
sharedPluginProcess: sharedPluginProcess,
}
return r
@@ -45,13 +48,13 @@ func newRestartableBackupItemAction(name string, sharedPluginProcess Restartable
// getBackupItemAction returns the backup item action for this restartableBackupItemAction. It does *not* restart the
// plugin process.
func (r *restartableBackupItemAction) getBackupItemAction() (velero.BackupItemAction, error) {
func (r *restartableBackupItemAction) getBackupItemAction() (backupitemactionv2.BackupItemAction, error) {
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
if err != nil {
return nil, err
}
backupItemAction, ok := plugin.(velero.BackupItemAction)
backupItemAction, ok := plugin.(backupitemactionv2.BackupItemAction)
if !ok {
return nil, errors.Errorf("%T is not a BackupItemAction!", plugin)
}
@@ -60,7 +63,7 @@ func (r *restartableBackupItemAction) getBackupItemAction() (velero.BackupItemAc
}
// getDelegate restarts the plugin process (if needed) and returns the backup item action for this restartableBackupItemAction.
func (r *restartableBackupItemAction) getDelegate() (velero.BackupItemAction, error) {
func (r *restartableBackupItemAction) getDelegate() (backupitemactionv2.BackupItemAction, error) {
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
return nil, err
}
@@ -87,3 +90,13 @@ func (r *restartableBackupItemAction) Execute(item runtime.Unstructured, backup
return delegate.Execute(item, backup)
}
// ExecuteV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableBackupItemAction) ExecuteV2(ctx context.Context, item runtime.Unstructured, backup *api.Backup) (runtime.Unstructured, []velero.ResourceIdentifier, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, nil, err
}
return delegate.ExecuteV2(ctx, item, backup)
}

View File

@@ -17,10 +17,14 @@ limitations under the License.
package clientmgmt
import (
"context"
"github.com/pkg/errors"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
deleteitemactionv2 "github.com/vmware-tanzu/velero/pkg/plugin/velero/deleteitemaction/v2"
)
// restartableDeleteItemAction is a delete item action for a given implementation (such as "pod"). It is associated with
@@ -34,7 +38,7 @@ type restartableDeleteItemAction struct {
}
// newRestartableDeleteItemAction returns a new restartableDeleteItemAction.
func newRestartableDeleteItemAction(name string, sharedPluginProcess RestartableProcess) *restartableDeleteItemAction {
func newRestartableDeleteItemActionV2(name string, sharedPluginProcess RestartableProcess) *restartableDeleteItemAction {
r := &restartableDeleteItemAction{
key: kindAndName{kind: framework.PluginKindDeleteItemAction, name: name},
sharedPluginProcess: sharedPluginProcess,
@@ -44,13 +48,13 @@ func newRestartableDeleteItemAction(name string, sharedPluginProcess Restartable
// getDeleteItemAction returns the delete item action for this restartableDeleteItemAction. It does *not* restart the
// plugin process.
func (r *restartableDeleteItemAction) getDeleteItemAction() (velero.DeleteItemAction, error) {
func (r *restartableDeleteItemAction) getDeleteItemAction() (deleteitemactionv2.DeleteItemAction, error) {
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
if err != nil {
return nil, err
}
deleteItemAction, ok := plugin.(velero.DeleteItemAction)
deleteItemAction, ok := plugin.(deleteitemactionv2.DeleteItemAction)
if !ok {
return nil, errors.Errorf("%T is not a DeleteItemAction!", plugin)
}
@@ -59,7 +63,7 @@ func (r *restartableDeleteItemAction) getDeleteItemAction() (velero.DeleteItemAc
}
// getDelegate restarts the plugin process (if needed) and returns the delete item action for this restartableDeleteItemAction.
func (r *restartableDeleteItemAction) getDelegate() (velero.DeleteItemAction, error) {
func (r *restartableDeleteItemAction) getDelegate() (deleteitemactionv2.DeleteItemAction, error) {
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
return nil, err
}
@@ -86,3 +90,13 @@ func (r *restartableDeleteItemAction) Execute(input *velero.DeleteItemActionExec
return delegate.Execute(input)
}
// ExecuteV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableDeleteItemAction) ExecuteV2(ctx context.Context, input *velero.DeleteItemActionExecuteInput) error {
delegate, err := r.getDelegate()
if err != nil {
return err
}
return delegate.ExecuteV2(ctx, input)
}

View File

@@ -1,5 +1,5 @@
/*
Copyright 2018 the Velero contributors.
Copyright 2021 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,13 +17,14 @@ limitations under the License.
package clientmgmt
import (
"context"
"io"
"time"
"github.com/pkg/errors"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
objectstorev2 "github.com/vmware-tanzu/velero/pkg/plugin/velero/objectstore/v2"
)
// restartableObjectStore is an object store for a given implementation (such as "aws"). It is associated with
@@ -38,9 +39,9 @@ type restartableObjectStore struct {
config map[string]string
}
// newRestartableObjectStore returns a new restartableObjectStore.
func newRestartableObjectStore(name string, sharedPluginProcess RestartableProcess) *restartableObjectStore {
key := kindAndName{kind: framework.PluginKindObjectStore, name: name}
// newRestartableObjectStoreV2 returns a new restartableObjectStore for version 2.
func newRestartableObjectStoreV2(name string, sharedPluginProcess RestartableProcess) *restartableObjectStore {
key := kindAndName{kind: framework.PluginKindObjectStoreV2, name: name}
r := &restartableObjectStore{
key: key,
sharedPluginProcess: sharedPluginProcess,
@@ -54,7 +55,7 @@ func newRestartableObjectStore(name string, sharedPluginProcess RestartableProce
// reinitialize reinitializes a re-dispensed plugin using the initial data passed to Init().
func (r *restartableObjectStore) reinitialize(dispensed interface{}) error {
objectStore, ok := dispensed.(velero.ObjectStore)
objectStore, ok := dispensed.(objectstorev2.ObjectStore)
if !ok {
return errors.Errorf("%T is not a ObjectStore!", dispensed)
}
@@ -64,13 +65,13 @@ func (r *restartableObjectStore) reinitialize(dispensed interface{}) error {
// getObjectStore returns the object store for this restartableObjectStore. It does *not* restart the
// plugin process.
func (r *restartableObjectStore) getObjectStore() (velero.ObjectStore, error) {
func (r *restartableObjectStore) getObjectStore() (objectstorev2.ObjectStore, error) {
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
if err != nil {
return nil, err
}
objectStore, ok := plugin.(velero.ObjectStore)
objectStore, ok := plugin.(objectstorev2.ObjectStore)
if !ok {
return nil, errors.Errorf("%T is not a ObjectStore!", plugin)
}
@@ -79,7 +80,7 @@ func (r *restartableObjectStore) getObjectStore() (velero.ObjectStore, error) {
}
// getDelegate restarts the plugin process (if needed) and returns the object store for this restartableObjectStore.
func (r *restartableObjectStore) getDelegate() (velero.ObjectStore, error) {
func (r *restartableObjectStore) getDelegate() (objectstorev2.ObjectStore, error) {
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
return nil, err
}
@@ -105,9 +106,15 @@ func (r *restartableObjectStore) Init(config map[string]string) error {
return r.init(delegate, config)
}
// InitV2 initializes the object store instance using config. If this is the first invocation, r stores config for future
// reinitialization needs. Init does NOT restart the shared plugin process. Init may only be called once.
func (r *restartableObjectStore) InitV2(ctx context.Context, config map[string]string) error {
return r.Init(config)
}
// init calls Init on objectStore with config. This is split out from Init() so that both Init() and reinitialize() may
// call it using a specific ObjectStore.
func (r *restartableObjectStore) init(objectStore velero.ObjectStore, config map[string]string) error {
func (r *restartableObjectStore) init(objectStore objectstorev2.ObjectStore, config map[string]string) error {
return objectStore.Init(config)
}
@@ -173,3 +180,68 @@ func (r *restartableObjectStore) CreateSignedURL(bucket string, key string, ttl
}
return delegate.CreateSignedURL(bucket, key, ttl)
}
// Version 2
// PutObjectV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableObjectStore) PutObjectV2(ctx context.Context, bucket string, key string, body io.Reader) error {
delegate, err := r.getDelegate()
if err != nil {
return err
}
return delegate.PutObjectV2(ctx, bucket, key, body)
}
// ObjectExistsV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableObjectStore) ObjectExistsV2(ctx context.Context, bucket, key string) (bool, error) {
delegate, err := r.getDelegate()
if err != nil {
return false, err
}
return delegate.ObjectExistsV2(ctx, bucket, key)
}
// GetObjectV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableObjectStore) GetObjectV2(ctx context.Context, bucket string, key string) (io.ReadCloser, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.GetObjectV2(ctx, bucket, key)
}
// ListCommonPrefixesV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableObjectStore) ListCommonPrefixesV2(
ctx context.Context, bucket string, prefix string, delimiter string) ([]string, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.ListCommonPrefixesV2(ctx, bucket, prefix, delimiter)
}
// ListObjectsV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableObjectStore) ListObjectsV2(ctx context.Context, bucket string, prefix string) ([]string, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.ListObjectsV2(ctx, bucket, prefix)
}
// DeleteObjectV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableObjectStore) DeleteObjectV2(ctx context.Context, bucket string, key string) error {
delegate, err := r.getDelegate()
if err != nil {
return err
}
return delegate.DeleteObjectV2(ctx, bucket, key)
}
// CreateSignedURLV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableObjectStore) CreateSignedURLV2(ctx context.Context, bucket string, key string, ttl time.Duration) (string, error) {
delegate, err := r.getDelegate()
if err != nil {
return "", err
}
return delegate.CreateSignedURLV2(ctx, bucket, key, ttl)
}

View File

@@ -1,5 +1,5 @@
/*
Copyright 2018 the Velero contributors.
Copyright 2021 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,10 +17,12 @@ limitations under the License.
package clientmgmt
import (
"github.com/pkg/errors"
"context"
"github.com/pkg/errors"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
restoreitemactionv2 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v2"
)
// restartableRestoreItemAction is a restore item action for a given implementation (such as "pod"). It is associated with
@@ -33,10 +35,10 @@ type restartableRestoreItemAction struct {
config map[string]string
}
// newRestartableRestoreItemAction returns a new restartableRestoreItemAction.
func newRestartableRestoreItemAction(name string, sharedPluginProcess RestartableProcess) *restartableRestoreItemAction {
// newRestartableRestoreItemActionV2 returns a new restartableRestoreItemAction.
func newRestartableRestoreItemActionV2(name string, sharedPluginProcess RestartableProcess) *restartableRestoreItemAction {
r := &restartableRestoreItemAction{
key: kindAndName{kind: framework.PluginKindRestoreItemAction, name: name},
key: kindAndName{kind: framework.PluginKindRestoreItemActionV2, name: name},
sharedPluginProcess: sharedPluginProcess,
}
return r
@@ -44,13 +46,13 @@ func newRestartableRestoreItemAction(name string, sharedPluginProcess Restartabl
// getRestoreItemAction returns the restore item action for this restartableRestoreItemAction. It does *not* restart the
// plugin process.
func (r *restartableRestoreItemAction) getRestoreItemAction() (velero.RestoreItemAction, error) {
func (r *restartableRestoreItemAction) getRestoreItemAction() (restoreitemactionv2.RestoreItemAction, error) {
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
if err != nil {
return nil, err
}
restoreItemAction, ok := plugin.(velero.RestoreItemAction)
restoreItemAction, ok := plugin.(restoreitemactionv2.RestoreItemAction)
if !ok {
return nil, errors.Errorf("%T is not a RestoreItemAction!", plugin)
}
@@ -59,7 +61,7 @@ func (r *restartableRestoreItemAction) getRestoreItemAction() (velero.RestoreIte
}
// getDelegate restarts the plugin process (if needed) and returns the restore item action for this restartableRestoreItemAction.
func (r *restartableRestoreItemAction) getDelegate() (velero.RestoreItemAction, error) {
func (r *restartableRestoreItemAction) getDelegate() (restoreitemactionv2.RestoreItemAction, error) {
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
return nil, err
}
@@ -86,3 +88,14 @@ func (r *restartableRestoreItemAction) Execute(input *velero.RestoreItemActionEx
return delegate.Execute(input)
}
// ExecuteV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableRestoreItemAction) ExecuteV2(
ctx context.Context, input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.ExecuteV2(ctx, input)
}

View File

@@ -1,5 +1,5 @@
/*
Copyright 2018 the Velero contributors.
Copyright 2021 the Velero contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -17,11 +17,13 @@ limitations under the License.
package clientmgmt
import (
"context"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
volumesnapshotterv2 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v2"
)
// restartableVolumeSnapshotter is a volume snapshotter for a given implementation (such as "aws"). It is associated with
@@ -34,9 +36,9 @@ type restartableVolumeSnapshotter struct {
config map[string]string
}
// newRestartableVolumeSnapshotter returns a new restartableVolumeSnapshotter.
func newRestartableVolumeSnapshotter(name string, sharedPluginProcess RestartableProcess) *restartableVolumeSnapshotter {
key := kindAndName{kind: framework.PluginKindVolumeSnapshotter, name: name}
// newRestartableVolumeSnapshotterV2 returns a new restartableVolumeSnapshotter.
func newRestartableVolumeSnapshotterV2(name string, sharedPluginProcess RestartableProcess) *restartableVolumeSnapshotter {
key := kindAndName{kind: framework.PluginKindVolumeSnapshotterV2, name: name}
r := &restartableVolumeSnapshotter{
key: key,
sharedPluginProcess: sharedPluginProcess,
@@ -50,7 +52,7 @@ func newRestartableVolumeSnapshotter(name string, sharedPluginProcess Restartabl
// reinitialize reinitializes a re-dispensed plugin using the initial data passed to Init().
func (r *restartableVolumeSnapshotter) reinitialize(dispensed interface{}) error {
volumeSnapshotter, ok := dispensed.(velero.VolumeSnapshotter)
volumeSnapshotter, ok := dispensed.(volumesnapshotterv2.VolumeSnapshotter)
if !ok {
return errors.Errorf("%T is not a VolumeSnapshotter!", dispensed)
}
@@ -59,13 +61,13 @@ func (r *restartableVolumeSnapshotter) reinitialize(dispensed interface{}) error
// getVolumeSnapshotter returns the volume snapshotter for this restartableVolumeSnapshotter. It does *not* restart the
// plugin process.
func (r *restartableVolumeSnapshotter) getVolumeSnapshotter() (velero.VolumeSnapshotter, error) {
func (r *restartableVolumeSnapshotter) getVolumeSnapshotter() (volumesnapshotterv2.VolumeSnapshotter, error) {
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
if err != nil {
return nil, err
}
volumeSnapshotter, ok := plugin.(velero.VolumeSnapshotter)
volumeSnapshotter, ok := plugin.(volumesnapshotterv2.VolumeSnapshotter)
if !ok {
return nil, errors.Errorf("%T is not a VolumeSnapshotter!", plugin)
}
@@ -74,7 +76,7 @@ func (r *restartableVolumeSnapshotter) getVolumeSnapshotter() (velero.VolumeSnap
}
// getDelegate restarts the plugin process (if needed) and returns the volume snapshotter for this restartableVolumeSnapshotter.
func (r *restartableVolumeSnapshotter) getDelegate() (velero.VolumeSnapshotter, error) {
func (r *restartableVolumeSnapshotter) getDelegate() (volumesnapshotterv2.VolumeSnapshotter, error) {
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
return nil, err
}
@@ -102,7 +104,7 @@ func (r *restartableVolumeSnapshotter) Init(config map[string]string) error {
// init calls Init on volumeSnapshotter with config. This is split out from Init() so that both Init() and reinitialize() may
// call it using a specific VolumeSnapshotter.
func (r *restartableVolumeSnapshotter) init(volumeSnapshotter velero.VolumeSnapshotter, config map[string]string) error {
func (r *restartableVolumeSnapshotter) init(volumeSnapshotter volumesnapshotterv2.VolumeSnapshotter, config map[string]string) error {
return volumeSnapshotter.Init(config)
}
@@ -115,6 +117,7 @@ func (r *restartableVolumeSnapshotter) CreateVolumeFromSnapshot(snapshotID strin
return delegate.CreateVolumeFromSnapshot(snapshotID, volumeType, volumeAZ, iops)
}
// GetVolumeID restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) GetVolumeID(pv runtime.Unstructured) (string, error) {
delegate, err := r.getDelegate()
@@ -159,3 +162,66 @@ func (r *restartableVolumeSnapshotter) DeleteSnapshot(snapshotID string) error {
}
return delegate.DeleteSnapshot(snapshotID)
}
// Version 2
func (r *restartableVolumeSnapshotter) InitV2(ctx context.Context, config map[string]string) error {
return r.Init(config)
}
// CreateVolumeFromSnapshotV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) CreateVolumeFromSnapshotV2(
ctx context.Context, snapshotID string, volumeType string, volumeAZ string, iops *int64) (volumeID string, err error) {
delegate, err := r.getDelegate()
if err != nil {
return "", err
}
return delegate.CreateVolumeFromSnapshotV2(ctx, snapshotID, volumeType, volumeAZ, iops)
}
// GetVolumeIDV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) GetVolumeIDV2(
ctx context.Context, pv runtime.Unstructured) (string, error) {
delegate, err := r.getDelegate()
if err != nil {
return "", err
}
return delegate.GetVolumeIDV2(ctx, pv)
}
// SetVolumeIDV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) SetVolumeIDV2(
ctx context.Context, pv runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
}
return delegate.SetVolumeIDV2(ctx, pv, volumeID)
}
// GetVolumeInfoV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) GetVolumeInfoV2(
ctx context.Context, volumeID string, volumeAZ string) (string, *int64, error) {
delegate, err := r.getDelegate()
if err != nil {
return "", nil, err
}
return delegate.GetVolumeInfoV2(ctx, volumeID, volumeAZ)
}
// CreateSnapshotV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) CreateSnapshotV2(
ctx context.Context, volumeID string, volumeAZ string, tags map[string]string) (snapshotID string, err error) {
delegate, err := r.getDelegate()
if err != nil {
return "", err
}
return delegate.CreateSnapshotV2(ctx, volumeID, volumeAZ, tags)
}
// DeleteSnapshotV2 restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) DeleteSnapshotV2(ctx context.Context, snapshotID string) error {
delegate, err := r.getDelegate()
if err != nil {
return err
}
return delegate.DeleteSnapshotV2(ctx, snapshotID)
}