Merge pull request #5318 from sseago/volumesnapshotter-refactor

plugin versioning v1 refactor for VolumeSnapshotter
This commit is contained in:
Xun Jiang/Bruce Jiang
2022-09-23 09:54:01 +08:00
committed by GitHub
16 changed files with 142 additions and 110 deletions

View File

@@ -0,0 +1 @@
plugin versioning v1 refactor for VolumeSnapshotter

View File

@@ -44,8 +44,8 @@ import (
velerov1client "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
"github.com/vmware-tanzu/velero/pkg/kuberesource"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
biav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/backupitemaction/v1"
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
"github.com/vmware-tanzu/velero/pkg/podexec"
"github.com/vmware-tanzu/velero/pkg/podvolume"
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
@@ -165,7 +165,7 @@ func getResourceHook(hookSpec velerov1api.BackupResourceHookSpec, discoveryHelpe
}
type VolumeSnapshotterGetter interface {
GetVolumeSnapshotter(name string) (velero.VolumeSnapshotter, error)
GetVolumeSnapshotter(name string) (vsv1.VolumeSnapshotter, error)
}
// Backup backs up the items specified in the Backup, placing them in a gzip-compressed tar file

View File

@@ -48,6 +48,7 @@ import (
"github.com/vmware-tanzu/velero/pkg/kuberesource"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
biav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/backupitemaction/v1"
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
"github.com/vmware-tanzu/velero/pkg/podvolume"
"github.com/vmware-tanzu/velero/pkg/test"
testutil "github.com/vmware-tanzu/velero/pkg/test"
@@ -1831,10 +1832,10 @@ func TestBackupActionAdditionalItems(t *testing.T) {
}
// volumeSnapshotterGetter is a simple implementation of the VolumeSnapshotterGetter
// interface that returns velero.VolumeSnapshotters from a map if they exist.
type volumeSnapshotterGetter map[string]velero.VolumeSnapshotter
// interface that returns vsv1.VolumeSnapshotters from a map if they exist.
type volumeSnapshotterGetter map[string]vsv1.VolumeSnapshotter
func (vsg volumeSnapshotterGetter) GetVolumeSnapshotter(name string) (velero.VolumeSnapshotter, error) {
func (vsg volumeSnapshotterGetter) GetVolumeSnapshotter(name string) (vsv1.VolumeSnapshotter, error) {
snapshotter, ok := vsg[name]
if !ok {
return nil, errors.New("volume snapshotter not found")
@@ -1859,7 +1860,7 @@ type volumeInfo struct {
snapshotErr bool
}
// fakeVolumeSnapshotter is a test fake for the velero.VolumeSnapshotter interface.
// fakeVolumeSnapshotter is a test fake for the vsv1.VolumeSnapshotter interface.
type fakeVolumeSnapshotter struct {
// PVVolumeNames is a map from PV name to volume ID, used as the basis
// for the GetVolumeID method.
@@ -1982,7 +1983,7 @@ func TestBackupWithSnapshots(t *testing.T) {
builder.ForPersistentVolume("pv-1").Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "", "type-1", 100, false),
},
want: []*volume.Snapshot{
@@ -2015,7 +2016,7 @@ func TestBackupWithSnapshots(t *testing.T) {
builder.ForPersistentVolume("pv-1").ObjectMeta(builder.WithLabels("failure-domain.beta.kubernetes.io/zone", "zone-1")).Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "zone-1", "type-1", 100, false),
},
want: []*volume.Snapshot{
@@ -2049,7 +2050,7 @@ func TestBackupWithSnapshots(t *testing.T) {
builder.ForPersistentVolume("pv-1").ObjectMeta(builder.WithLabels("topology.kubernetes.io/zone", "zone-1")).Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "zone-1", "type-1", 100, false),
},
want: []*volume.Snapshot{
@@ -2083,7 +2084,7 @@ func TestBackupWithSnapshots(t *testing.T) {
builder.ForPersistentVolume("pv-1").ObjectMeta(builder.WithLabelsMap(map[string]string{"failure-domain.beta.kubernetes.io/zone": "zone-1-deprecated", "topology.kubernetes.io/zone": "zone-1-ga"})).Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "zone-1-ga", "type-1", 100, false),
},
want: []*volume.Snapshot{
@@ -2117,7 +2118,7 @@ func TestBackupWithSnapshots(t *testing.T) {
builder.ForPersistentVolume("pv-1").Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "", "type-1", 100, true),
},
want: []*volume.Snapshot{
@@ -2149,7 +2150,7 @@ func TestBackupWithSnapshots(t *testing.T) {
builder.ForPersistentVolume("pv-1").Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "", "type-1", 100, false),
},
want: nil,
@@ -2164,7 +2165,7 @@ func TestBackupWithSnapshots(t *testing.T) {
builder.ForPersistentVolume("pv-1").Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "", "type-1", 100, false),
},
want: nil,
@@ -2182,7 +2183,7 @@ func TestBackupWithSnapshots(t *testing.T) {
builder.ForPersistentVolume("pv-1").Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{},
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{},
want: nil,
},
{
@@ -2198,7 +2199,7 @@ func TestBackupWithSnapshots(t *testing.T) {
builder.ForPersistentVolume("pv-1").Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter),
},
want: nil,
@@ -2218,7 +2219,7 @@ func TestBackupWithSnapshots(t *testing.T) {
builder.ForPersistentVolume("pv-2").Result(),
),
},
snapshotterGetter: map[string]velero.VolumeSnapshotter{
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter).WithVolume("pv-1", "vol-1", "", "type-1", 100, false),
"another": new(fakeVolumeSnapshotter).WithVolume("pv-2", "vol-2", "", "type-2", 100, false),
},
@@ -2686,7 +2687,7 @@ func TestBackupWithRestic(t *testing.T) {
),
},
vsl: newSnapshotLocation("velero", "default", "default"),
snapshotterGetter: map[string]velero.VolumeSnapshotter{
snapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"default": new(fakeVolumeSnapshotter).
WithVolume("pv-1", "vol-1", "", "type-1", 100, false).
WithVolume("pv-2", "vol-2", "", "type-1", 100, false),

View File

@@ -41,7 +41,7 @@ import (
"github.com/vmware-tanzu/velero/pkg/discovery"
"github.com/vmware-tanzu/velero/pkg/features"
"github.com/vmware-tanzu/velero/pkg/kuberesource"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
"github.com/vmware-tanzu/velero/pkg/podvolume"
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
"github.com/vmware-tanzu/velero/pkg/volume"
@@ -58,7 +58,7 @@ type itemBackupper struct {
volumeSnapshotterGetter VolumeSnapshotterGetter
itemHookHandler hook.ItemHookHandler
snapshotLocationVolumeSnapshotters map[string]velero.VolumeSnapshotter
snapshotLocationVolumeSnapshotters map[string]vsv1.VolumeSnapshotter
}
const (
@@ -357,7 +357,7 @@ func (ib *itemBackupper) executeActions(
// volumeSnapshotter instantiates and initializes a VolumeSnapshotter given a VolumeSnapshotLocation,
// or returns an existing one if one's already been initialized for the location.
func (ib *itemBackupper) volumeSnapshotter(snapshotLocation *velerov1api.VolumeSnapshotLocation) (velero.VolumeSnapshotter, error) {
func (ib *itemBackupper) volumeSnapshotter(snapshotLocation *velerov1api.VolumeSnapshotLocation) (vsv1.VolumeSnapshotter, error) {
if bs, ok := ib.snapshotLocationVolumeSnapshotters[snapshotLocation.Name]; ok {
return bs, nil
}
@@ -372,7 +372,7 @@ func (ib *itemBackupper) volumeSnapshotter(snapshotLocation *velerov1api.VolumeS
}
if ib.snapshotLocationVolumeSnapshotters == nil {
ib.snapshotLocationVolumeSnapshotters = make(map[string]velero.VolumeSnapshotter)
ib.snapshotLocationVolumeSnapshotters = make(map[string]vsv1.VolumeSnapshotter)
}
ib.snapshotLocationVolumeSnapshotters[snapshotLocation.Name] = bs
@@ -447,7 +447,7 @@ func (ib *itemBackupper) takePVSnapshot(obj runtime.Unstructured, log logrus.Fie
var (
volumeID, location string
volumeSnapshotter velero.VolumeSnapshotter
volumeSnapshotter vsv1.VolumeSnapshotter
)
for _, snapshotLocation := range ib.backupRequest.SnapshotLocations {

View File

@@ -39,7 +39,7 @@ import (
"github.com/vmware-tanzu/velero/pkg/metrics"
"github.com/vmware-tanzu/velero/pkg/persistence"
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
"github.com/vmware-tanzu/velero/pkg/repository"
"github.com/vmware-tanzu/velero/pkg/util/filesystem"
"github.com/vmware-tanzu/velero/pkg/util/kube"
@@ -282,7 +282,7 @@ func (r *backupDeletionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
if snapshots, err := backupStore.GetBackupVolumeSnapshots(backup.Name); err != nil {
errs = append(errs, errors.Wrap(err, "error getting backup's volume snapshots").Error())
} else {
volumeSnapshotters := make(map[string]velero.VolumeSnapshotter)
volumeSnapshotters := make(map[string]vsv1.VolumeSnapshotter)
for _, snapshot := range snapshots {
log.WithField("providerSnapshotID", snapshot.Status.ProviderSnapshotID).Info("Removing snapshot associated with backup")
@@ -392,7 +392,7 @@ func volumeSnapshottersForVSL(
namespace, vslName string,
client client.Client,
pluginManager clientmgmt.Manager,
) (velero.VolumeSnapshotter, error) {
) (vsv1.VolumeSnapshotter, error) {
vsl := &velerov1api.VolumeSnapshotLocation{}
if err := client.Get(ctx, types.NamespacedName{
Namespace: namespace,

View File

@@ -27,11 +27,13 @@ import (
biav1cli "github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt/backupitemaction/v1"
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt/process"
riav1cli "github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt/restoreitemaction/v1"
vsv1cli "github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt/volumesnapshotter/v1"
"github.com/vmware-tanzu/velero/pkg/plugin/framework/common"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
biav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/backupitemaction/v1"
isv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/item_snapshotter/v1"
riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
)
// Manager manages the lifecycles of plugins.
@@ -40,7 +42,7 @@ type Manager interface {
GetObjectStore(name string) (velero.ObjectStore, error)
// GetVolumeSnapshotter returns the VolumeSnapshotter plugin for name.
GetVolumeSnapshotter(name string) (velero.VolumeSnapshotter, error)
GetVolumeSnapshotter(name string) (vsv1.VolumeSnapshotter, error)
// GetBackupItemActions returns all v1 backup item action plugins.
GetBackupItemActions() ([]biav1.BackupItemAction, error)
@@ -161,17 +163,21 @@ func (m *manager) GetObjectStore(name string) (velero.ObjectStore, error) {
}
// GetVolumeSnapshotter returns a restartableVolumeSnapshotter for name.
func (m *manager) GetVolumeSnapshotter(name string) (velero.VolumeSnapshotter, error) {
func (m *manager) GetVolumeSnapshotter(name string) (vsv1.VolumeSnapshotter, error) {
name = sanitizeName(name)
restartableProcess, err := m.getRestartableProcess(common.PluginKindVolumeSnapshotter, name)
if err != nil {
return nil, err
for _, adaptedVolumeSnapshotter := range vsv1cli.AdaptedVolumeSnapshotters() {
restartableProcess, err := m.getRestartableProcess(adaptedVolumeSnapshotter.Kind, name)
// Check if plugin was not found
if errors.As(err, &pluginNotFoundErrType) {
continue
}
if err != nil {
return nil, err
}
return adaptedVolumeSnapshotter.GetRestartable(name, restartableProcess), nil
}
r := NewRestartableVolumeSnapshotter(name, restartableProcess)
return r, nil
return nil, fmt.Errorf("unable to get valid VolumeSnapshotter for %q", name)
}
// GetBackupItemActions returns all backup item actions as restartableBackupItemActions.

View File

@@ -30,6 +30,7 @@ import (
biav1cli "github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt/backupitemaction/v1"
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt/process"
riav1cli "github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt/restoreitemaction/v1"
vsv1cli "github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt/volumesnapshotter/v1"
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"github.com/vmware-tanzu/velero/pkg/plugin/framework/common"
"github.com/vmware-tanzu/velero/pkg/test"
@@ -176,9 +177,9 @@ func TestGetVolumeSnapshotter(t *testing.T) {
return m.GetVolumeSnapshotter(name)
},
func(name string, sharedPluginProcess process.RestartableProcess) interface{} {
return &restartableVolumeSnapshotter{
key: process.KindAndName{Kind: common.PluginKindVolumeSnapshotter, Name: name},
sharedPluginProcess: sharedPluginProcess,
return &vsv1cli.RestartableVolumeSnapshotter{
Key: process.KindAndName{Kind: common.PluginKindVolumeSnapshotter, Name: name},
SharedPluginProcess: sharedPluginProcess,
}
},
true,

View File

@@ -1,5 +1,5 @@
/*
Copyright 2018 the Velero contributors.
Copyright 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.
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package clientmgmt
package v1
import (
"github.com/pkg/errors"
@@ -22,25 +22,44 @@ import (
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt/process"
"github.com/vmware-tanzu/velero/pkg/plugin/framework/common"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
)
// AdaptedVolumeSnapshotter is a volume snapshotter adapted to the v1 VolumeSnapshotter API
type AdaptedVolumeSnapshotter struct {
Kind common.PluginKind
// Get returns a restartable VolumeSnapshotter for the given name and process, wrapping if necessary
GetRestartable func(name string, restartableProcess process.RestartableProcess) vsv1.VolumeSnapshotter
}
func AdaptedVolumeSnapshotters() []AdaptedVolumeSnapshotter {
return []AdaptedVolumeSnapshotter{
{
Kind: common.PluginKindVolumeSnapshotter,
GetRestartable: func(name string, restartableProcess process.RestartableProcess) vsv1.VolumeSnapshotter {
return NewRestartableVolumeSnapshotter(name, restartableProcess)
},
},
}
}
// RestartableVolumeSnapshotter is a volume snapshotter for a given implementation (such as "aws"). It is associated with
// a restartableProcess, which may be shared and used to run multiple plugins. At the beginning of each method
// call, the restartableVolumeSnapshotter asks its restartableProcess to restart itself if needed (e.g. if the
// process terminated for any reason), then it proceeds with the actual call.
type restartableVolumeSnapshotter struct {
key process.KindAndName
sharedPluginProcess process.RestartableProcess
type RestartableVolumeSnapshotter struct {
Key process.KindAndName
SharedPluginProcess process.RestartableProcess
config map[string]string
}
// NewRestartableVolumeSnapshotter returns a new restartableVolumeSnapshotter.
func NewRestartableVolumeSnapshotter(name string, sharedPluginProcess process.RestartableProcess) *restartableVolumeSnapshotter {
func NewRestartableVolumeSnapshotter(name string, sharedPluginProcess process.RestartableProcess) *RestartableVolumeSnapshotter {
key := process.KindAndName{Kind: common.PluginKindVolumeSnapshotter, Name: name}
r := &restartableVolumeSnapshotter{
key: key,
sharedPluginProcess: sharedPluginProcess,
r := &RestartableVolumeSnapshotter{
Key: key,
SharedPluginProcess: sharedPluginProcess,
}
// Register our reinitializer so we can reinitialize after a restart with r.config.
@@ -50,8 +69,8 @@ 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 {
volumeSnapshotter, ok := dispensed.(velero.VolumeSnapshotter)
func (r *RestartableVolumeSnapshotter) Reinitialize(dispensed interface{}) error {
volumeSnapshotter, ok := dispensed.(vsv1.VolumeSnapshotter)
if !ok {
return errors.Errorf("%T is not a VolumeSnapshotter!", dispensed)
}
@@ -60,13 +79,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) {
plugin, err := r.sharedPluginProcess.GetByKindAndName(r.key)
func (r *RestartableVolumeSnapshotter) getVolumeSnapshotter() (vsv1.VolumeSnapshotter, error) {
plugin, err := r.SharedPluginProcess.GetByKindAndName(r.Key)
if err != nil {
return nil, err
}
volumeSnapshotter, ok := plugin.(velero.VolumeSnapshotter)
volumeSnapshotter, ok := plugin.(vsv1.VolumeSnapshotter)
if !ok {
return nil, errors.Errorf("%T is not a VolumeSnapshotter!", plugin)
}
@@ -74,9 +93,9 @@ func (r *restartableVolumeSnapshotter) getVolumeSnapshotter() (velero.VolumeSnap
return volumeSnapshotter, nil
}
// getDelegate restarts the plugin process (if needed) and returns the volume snapshotter for this restartableVolumeSnapshotter.
func (r *restartableVolumeSnapshotter) getDelegate() (velero.VolumeSnapshotter, error) {
if err := r.sharedPluginProcess.ResetIfNeeded(); err != nil {
// getDelegate restarts the plugin process (if needed) and returns the volume snapshotter for this RestartableVolumeSnapshotter.
func (r *RestartableVolumeSnapshotter) getDelegate() (vsv1.VolumeSnapshotter, error) {
if err := r.SharedPluginProcess.ResetIfNeeded(); err != nil {
return nil, err
}
@@ -85,7 +104,7 @@ func (r *restartableVolumeSnapshotter) getDelegate() (velero.VolumeSnapshotter,
// Init initializes the volume snapshotter 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 *restartableVolumeSnapshotter) Init(config map[string]string) error {
func (r *RestartableVolumeSnapshotter) Init(config map[string]string) error {
if r.config != nil {
return errors.Errorf("already initialized")
}
@@ -103,12 +122,12 @@ 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 vsv1.VolumeSnapshotter, config map[string]string) error {
return volumeSnapshotter.Init(config)
}
// CreateVolumeFromSnapshot restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) CreateVolumeFromSnapshot(snapshotID string, volumeType string, volumeAZ string, iops *int64) (volumeID string, err error) {
func (r *RestartableVolumeSnapshotter) CreateVolumeFromSnapshot(snapshotID string, volumeType string, volumeAZ string, iops *int64) (volumeID string, err error) {
delegate, err := r.getDelegate()
if err != nil {
return "", err
@@ -117,7 +136,7 @@ func (r *restartableVolumeSnapshotter) CreateVolumeFromSnapshot(snapshotID strin
}
// GetVolumeID restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) GetVolumeID(pv runtime.Unstructured) (string, error) {
func (r *RestartableVolumeSnapshotter) GetVolumeID(pv runtime.Unstructured) (string, error) {
delegate, err := r.getDelegate()
if err != nil {
return "", err
@@ -126,7 +145,7 @@ func (r *restartableVolumeSnapshotter) GetVolumeID(pv runtime.Unstructured) (str
}
// SetVolumeID restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) SetVolumeID(pv runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
func (r *RestartableVolumeSnapshotter) SetVolumeID(pv runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
delegate, err := r.getDelegate()
if err != nil {
return nil, err
@@ -135,7 +154,7 @@ func (r *restartableVolumeSnapshotter) SetVolumeID(pv runtime.Unstructured, volu
}
// GetVolumeInfo restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) GetVolumeInfo(volumeID string, volumeAZ string) (string, *int64, error) {
func (r *RestartableVolumeSnapshotter) GetVolumeInfo(volumeID string, volumeAZ string) (string, *int64, error) {
delegate, err := r.getDelegate()
if err != nil {
return "", nil, err
@@ -144,7 +163,7 @@ func (r *restartableVolumeSnapshotter) GetVolumeInfo(volumeID string, volumeAZ s
}
// CreateSnapshot restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) CreateSnapshot(volumeID string, volumeAZ string, tags map[string]string) (snapshotID string, err error) {
func (r *RestartableVolumeSnapshotter) CreateSnapshot(volumeID string, volumeAZ string, tags map[string]string) (snapshotID string, err error) {
delegate, err := r.getDelegate()
if err != nil {
return "", err
@@ -153,7 +172,7 @@ func (r *restartableVolumeSnapshotter) CreateSnapshot(volumeID string, volumeAZ
}
// DeleteSnapshot restarts the plugin's process if needed, then delegates the call.
func (r *restartableVolumeSnapshotter) DeleteSnapshot(snapshotID string) error {
func (r *RestartableVolumeSnapshotter) DeleteSnapshot(snapshotID string) error {
delegate, err := r.getDelegate()
if err != nil {
return err

View File

@@ -1,5 +1,5 @@
/*
Copyright 2018 the Velero contributors.
Copyright 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.
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package clientmgmt
package v1
import (
"testing"
@@ -28,7 +28,7 @@ import (
"github.com/vmware-tanzu/velero/internal/restartabletest"
"github.com/vmware-tanzu/velero/pkg/plugin/clientmgmt/process"
"github.com/vmware-tanzu/velero/pkg/plugin/framework/common"
providermocks "github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks"
providermocks "github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks/volumesnapshotter/v1"
)
func TestRestartableGetVolumeSnapshotter(t *testing.T) {
@@ -64,9 +64,9 @@ func TestRestartableGetVolumeSnapshotter(t *testing.T) {
key := process.KindAndName{Kind: common.PluginKindVolumeSnapshotter, Name: name}
p.On("GetByKindAndName", key).Return(tc.plugin, tc.getError)
r := &restartableVolumeSnapshotter{
key: key,
sharedPluginProcess: p,
r := &RestartableVolumeSnapshotter{
Key: key,
SharedPluginProcess: p,
}
a, err := r.getVolumeSnapshotter()
if tc.expectedError != "" {
@@ -87,9 +87,9 @@ func TestRestartableVolumeSnapshotterReinitialize(t *testing.T) {
name := "aws"
key := process.KindAndName{Kind: common.PluginKindVolumeSnapshotter, Name: name}
r := &restartableVolumeSnapshotter{
key: key,
sharedPluginProcess: p,
r := &RestartableVolumeSnapshotter{
Key: key,
SharedPluginProcess: p,
config: map[string]string{
"color": "blue",
},
@@ -120,9 +120,9 @@ func TestRestartableVolumeSnapshotterGetDelegate(t *testing.T) {
p.On("ResetIfNeeded").Return(errors.Errorf("reset error")).Once()
name := "aws"
key := process.KindAndName{Kind: common.PluginKindVolumeSnapshotter, Name: name}
r := &restartableVolumeSnapshotter{
key: key,
sharedPluginProcess: p,
r := &RestartableVolumeSnapshotter{
Key: key,
SharedPluginProcess: p,
}
a, err := r.getDelegate()
assert.Nil(t, a)
@@ -148,9 +148,9 @@ func TestRestartableVolumeSnapshotterInit(t *testing.T) {
// getVolumeSnapshottererror
name := "aws"
key := process.KindAndName{Kind: common.PluginKindVolumeSnapshotter, Name: name}
r := &restartableVolumeSnapshotter{
key: key,
sharedPluginProcess: p,
r := &RestartableVolumeSnapshotter{
Key: key,
SharedPluginProcess: p,
}
p.On("GetByKindAndName", key).Return(nil, errors.Errorf("GetByKindAndName error")).Once()
@@ -201,9 +201,9 @@ func TestRestartableVolumeSnapshotterDelegatedFunctions(t *testing.T) {
t,
common.PluginKindVolumeSnapshotter,
func(key process.KindAndName, p process.RestartableProcess) interface{} {
return &restartableVolumeSnapshotter{
key: key,
sharedPluginProcess: p,
return &RestartableVolumeSnapshotter{
Key: key,
SharedPluginProcess: p,
}
},
func() restartabletest.Mockable {

View File

@@ -1,5 +1,5 @@
/*
Copyright 2017, 2019 the Velero contributors.
Copyright 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.
@@ -25,7 +25,7 @@ import (
"github.com/vmware-tanzu/velero/pkg/plugin/framework/common"
proto "github.com/vmware-tanzu/velero/pkg/plugin/generated"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
)
// VolumeSnapshotterGRPCServer implements the proto-generated VolumeSnapshotterServer interface, and accepts
@@ -34,13 +34,13 @@ type VolumeSnapshotterGRPCServer struct {
mux *common.ServerMux
}
func (s *VolumeSnapshotterGRPCServer) getImpl(name string) (velero.VolumeSnapshotter, error) {
func (s *VolumeSnapshotterGRPCServer) getImpl(name string) (vsv1.VolumeSnapshotter, error) {
impl, err := s.mux.GetHandler(name)
if err != nil {
return nil, err
}
volumeSnapshotter, ok := impl.(velero.VolumeSnapshotter)
volumeSnapshotter, ok := impl.(vsv1.VolumeSnapshotter)
if !ok {
return nil, errors.Errorf("%T is not a volume snapshotter", impl)
}

View File

@@ -11,6 +11,8 @@ import (
v1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/backupitemaction/v1"
velero "github.com/vmware-tanzu/velero/pkg/plugin/velero"
volumesnapshotterv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
)
// Manager is an autogenerated mock type for the Manager type
@@ -231,15 +233,15 @@ func (_m *Manager) GetRestoreItemActions() ([]restoreitemactionv1.RestoreItemAct
}
// GetVolumeSnapshotter provides a mock function with given fields: name
func (_m *Manager) GetVolumeSnapshotter(name string) (velero.VolumeSnapshotter, error) {
func (_m *Manager) GetVolumeSnapshotter(name string) (volumesnapshotterv1.VolumeSnapshotter, error) {
ret := _m.Called(name)
var r0 velero.VolumeSnapshotter
if rf, ok := ret.Get(0).(func(string) velero.VolumeSnapshotter); ok {
var r0 volumesnapshotterv1.VolumeSnapshotter
if rf, ok := ret.Get(0).(func(string) volumesnapshotterv1.VolumeSnapshotter); ok {
r0 = rf(name)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(velero.VolumeSnapshotter)
r0 = ret.Get(0).(volumesnapshotterv1.VolumeSnapshotter)
}
}

View File

@@ -1,5 +1,5 @@
/*
Copyright 2017, 2019 the Velero contributors.
Copyright 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.
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package velero
package v1
import (
"k8s.io/apimachinery/pkg/runtime"

View File

@@ -29,8 +29,8 @@ import (
"github.com/vmware-tanzu/velero/pkg/builder"
"github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/fake"
informers "github.com/vmware-tanzu/velero/pkg/generated/informers/externalversions"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
providermocks "github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks"
providermocks "github.com/vmware-tanzu/velero/pkg/plugin/velero/mocks/volumesnapshotter/v1"
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
"github.com/vmware-tanzu/velero/pkg/volume"
)
@@ -187,7 +187,7 @@ func TestExecutePVAction_SnapshotRestores(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
var (
volumeSnapshotter = new(providermocks.VolumeSnapshotter)
volumeSnapshotterGetter = providerToVolumeSnapshotterMap(map[string]velero.VolumeSnapshotter{
volumeSnapshotterGetter = providerToVolumeSnapshotterMap(map[string]vsv1.VolumeSnapshotter{
tc.expectedProvider: volumeSnapshotter,
})
locationsInformer = informers.NewSharedInformerFactory(fake.NewSimpleClientset(), 0).Velero().V1().VolumeSnapshotLocations()
@@ -217,9 +217,9 @@ func TestExecutePVAction_SnapshotRestores(t *testing.T) {
}
}
type providerToVolumeSnapshotterMap map[string]velero.VolumeSnapshotter
type providerToVolumeSnapshotterMap map[string]vsv1.VolumeSnapshotter
func (g providerToVolumeSnapshotterMap) GetVolumeSnapshotter(provider string) (velero.VolumeSnapshotter, error) {
func (g providerToVolumeSnapshotterMap) GetVolumeSnapshotter(provider string) (vsv1.VolumeSnapshotter, error) {
if bs, ok := g[provider]; !ok {
return nil, errors.New("volume snapshotter not found for provider")
} else {

View File

@@ -60,6 +60,7 @@ import (
"github.com/vmware-tanzu/velero/pkg/plugin/framework"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
"github.com/vmware-tanzu/velero/pkg/podexec"
"github.com/vmware-tanzu/velero/pkg/podvolume"
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
@@ -70,7 +71,7 @@ import (
)
type VolumeSnapshotterGetter interface {
GetVolumeSnapshotter(name string) (velero.VolumeSnapshotter, error)
GetVolumeSnapshotter(name string) (vsv1.VolumeSnapshotter, error)
}
type Request struct {

View File

@@ -49,6 +49,7 @@ import (
"github.com/vmware-tanzu/velero/pkg/kuberesource"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
riav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/restoreitemaction/v1"
vsv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/volumesnapshotter/v1"
"github.com/vmware-tanzu/velero/pkg/podvolume"
uploadermocks "github.com/vmware-tanzu/velero/pkg/podvolume/mocks"
"github.com/vmware-tanzu/velero/pkg/test"
@@ -1876,10 +1877,10 @@ func assertRestoredItems(t *testing.T, h *harness, want []*test.APIResource) {
}
// volumeSnapshotterGetter is a simple implementation of the VolumeSnapshotterGetter
// interface that returns velero.VolumeSnapshotters from a map if they exist.
type volumeSnapshotterGetter map[string]velero.VolumeSnapshotter
// interface that returns vsv1.VolumeSnapshotters from a map if they exist.
type volumeSnapshotterGetter map[string]vsv1.VolumeSnapshotter
func (vsg volumeSnapshotterGetter) GetVolumeSnapshotter(name string) (velero.VolumeSnapshotter, error) {
func (vsg volumeSnapshotterGetter) GetVolumeSnapshotter(name string) (vsv1.VolumeSnapshotter, error) {
snapshotter, ok := vsg[name]
if !ok {
return nil, errors.New("volume snapshotter not found")
@@ -1888,7 +1889,7 @@ func (vsg volumeSnapshotterGetter) GetVolumeSnapshotter(name string) (velero.Vol
return snapshotter, nil
}
// volumeSnapshotter is a test fake for the velero.VolumeSnapshotter interface
// volumeSnapshotter is a test fake for the vsv1.VolumeSnapshotter interface
type volumeSnapshotter struct {
// a map from snapshotID to volumeID
snapshotVolumes map[string]string
@@ -2052,7 +2053,7 @@ func TestRestorePersistentVolumes(t *testing.T) {
volumeSnapshotLocations: []*velerov1api.VolumeSnapshotLocation{
builder.ForVolumeSnapshotLocation(velerov1api.DefaultNamespace, "default").Provider("provider-1").Result(),
},
volumeSnapshotterGetter: map[string]velero.VolumeSnapshotter{
volumeSnapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"provider-1": &volumeSnapshotter{
snapshotVolumes: map[string]string{"snapshot-1": "new-volume"},
},
@@ -2101,7 +2102,7 @@ func TestRestorePersistentVolumes(t *testing.T) {
volumeSnapshotLocations: []*velerov1api.VolumeSnapshotLocation{
builder.ForVolumeSnapshotLocation(velerov1api.DefaultNamespace, "default").Provider("provider-1").Result(),
},
volumeSnapshotterGetter: map[string]velero.VolumeSnapshotter{
volumeSnapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"provider-1": &volumeSnapshotter{
snapshotVolumes: map[string]string{"snapshot-1": "new-volume"},
},
@@ -2155,7 +2156,7 @@ func TestRestorePersistentVolumes(t *testing.T) {
volumeSnapshotLocations: []*velerov1api.VolumeSnapshotLocation{
builder.ForVolumeSnapshotLocation(velerov1api.DefaultNamespace, "default").Provider("provider-1").Result(),
},
volumeSnapshotterGetter: map[string]velero.VolumeSnapshotter{
volumeSnapshotterGetter: map[string]vsv1.VolumeSnapshotter{
// the volume snapshotter fake is not configured with any snapshotID -> volumeID
// mappings as a way to verify that the snapshot is not restored, since if it were
// restored, we'd get an error of "snapshot not found".
@@ -2207,7 +2208,7 @@ func TestRestorePersistentVolumes(t *testing.T) {
volumeSnapshotLocations: []*velerov1api.VolumeSnapshotLocation{
builder.ForVolumeSnapshotLocation(velerov1api.DefaultNamespace, "default").Provider("provider-1").Result(),
},
volumeSnapshotterGetter: map[string]velero.VolumeSnapshotter{
volumeSnapshotterGetter: map[string]vsv1.VolumeSnapshotter{
// the volume snapshotter fake is not configured with any snapshotID -> volumeID
// mappings as a way to verify that the snapshot is not restored, since if it were
// restored, we'd get an error of "snapshot not found".
@@ -2258,7 +2259,7 @@ func TestRestorePersistentVolumes(t *testing.T) {
volumeSnapshotLocations: []*velerov1api.VolumeSnapshotLocation{
builder.ForVolumeSnapshotLocation(velerov1api.DefaultNamespace, "default").Provider("provider-1").Result(),
},
volumeSnapshotterGetter: map[string]velero.VolumeSnapshotter{
volumeSnapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"provider-1": &volumeSnapshotter{
snapshotVolumes: map[string]string{"snapshot-1": "new-volume"},
},
@@ -2319,7 +2320,7 @@ func TestRestorePersistentVolumes(t *testing.T) {
volumeSnapshotLocations: []*velerov1api.VolumeSnapshotLocation{
builder.ForVolumeSnapshotLocation(velerov1api.DefaultNamespace, "default").Provider("provider-1").Result(),
},
volumeSnapshotterGetter: map[string]velero.VolumeSnapshotter{
volumeSnapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"provider-1": &volumeSnapshotter{
snapshotVolumes: map[string]string{"snapshot-1": "new-volume"},
},
@@ -2467,7 +2468,7 @@ func TestRestorePersistentVolumes(t *testing.T) {
volumeSnapshotLocations: []*velerov1api.VolumeSnapshotLocation{
builder.ForVolumeSnapshotLocation(velerov1api.DefaultNamespace, "default").Provider("provider-1").Result(),
},
volumeSnapshotterGetter: map[string]velero.VolumeSnapshotter{
volumeSnapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"provider-1": &volumeSnapshotter{
snapshotVolumes: map[string]string{"snapshot-1": "new-pvname"},
pvName: map[string]string{"new-pvname": "new-pvname"},
@@ -2539,7 +2540,7 @@ func TestRestorePersistentVolumes(t *testing.T) {
},
},
},
volumeSnapshotterGetter: map[string]velero.VolumeSnapshotter{
volumeSnapshotterGetter: map[string]vsv1.VolumeSnapshotter{
// the volume snapshotter fake is not configured with any snapshotID -> volumeID
// mappings as a way to verify that the snapshot is not restored, since if it were
// restored, we'd get an error of "snapshot not found".
@@ -2591,7 +2592,7 @@ func TestRestorePersistentVolumes(t *testing.T) {
volumeSnapshotLocations: []*velerov1api.VolumeSnapshotLocation{
builder.ForVolumeSnapshotLocation(velerov1api.DefaultNamespace, "default").Provider("provider-1").Result(),
},
volumeSnapshotterGetter: map[string]velero.VolumeSnapshotter{
volumeSnapshotterGetter: map[string]vsv1.VolumeSnapshotter{
"provider-1": &volumeSnapshotter{
snapshotVolumes: map[string]string{"snapshot-1": "new-volume"},
pvName: map[string]string{"new-volume": "volumesnapshotter-renamed-source-pv"},