mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-08-15 11:46:06 +00:00
Move plugin interfaces to same package (#1264)
* Move plugin interfaces to same package Signed-off-by: Carlisia <carlisiac@vmware.com>
This commit is contained in:
committed by
Nolan Brubaker
parent
7674332313
commit
73514a003b
@@ -28,8 +28,8 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
api "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
velerobackup "github.com/heptio/velero/pkg/backup"
|
||||
proto "github.com/heptio/velero/pkg/plugin/generated"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
// BackupItemActionPlugin is an implementation of go-plugin's Plugin
|
||||
@@ -70,13 +70,13 @@ func newBackupItemActionGRPCClient(base *clientBase, clientConn *grpc.ClientConn
|
||||
}
|
||||
}
|
||||
|
||||
func (c *BackupItemActionGRPCClient) AppliesTo() (velerobackup.ResourceSelector, error) {
|
||||
func (c *BackupItemActionGRPCClient) AppliesTo() (velero.ResourceSelector, error) {
|
||||
res, err := c.grpcClient.AppliesTo(context.Background(), &proto.AppliesToRequest{Plugin: c.plugin})
|
||||
if err != nil {
|
||||
return velerobackup.ResourceSelector{}, err
|
||||
return velero.ResourceSelector{}, err
|
||||
}
|
||||
|
||||
return velerobackup.ResourceSelector{
|
||||
return velero.ResourceSelector{
|
||||
IncludedNamespaces: res.IncludedNamespaces,
|
||||
ExcludedNamespaces: res.ExcludedNamespaces,
|
||||
IncludedResources: res.IncludedResources,
|
||||
@@ -85,7 +85,7 @@ func (c *BackupItemActionGRPCClient) AppliesTo() (velerobackup.ResourceSelector,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *BackupItemActionGRPCClient) Execute(item runtime.Unstructured, backup *api.Backup) (runtime.Unstructured, []velerobackup.ResourceIdentifier, error) {
|
||||
func (c *BackupItemActionGRPCClient) Execute(item runtime.Unstructured, backup *api.Backup) (runtime.Unstructured, []velero.ResourceIdentifier, error) {
|
||||
itemJSON, err := json.Marshal(item.UnstructuredContent())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -112,10 +112,10 @@ func (c *BackupItemActionGRPCClient) Execute(item runtime.Unstructured, backup *
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var additionalItems []velerobackup.ResourceIdentifier
|
||||
var additionalItems []velero.ResourceIdentifier
|
||||
|
||||
for _, itm := range res.AdditionalItems {
|
||||
newItem := velerobackup.ResourceIdentifier{
|
||||
newItem := velero.ResourceIdentifier{
|
||||
GroupResource: schema.GroupResource{
|
||||
Group: itm.Group,
|
||||
Resource: itm.Resource,
|
||||
@@ -146,13 +146,13 @@ type BackupItemActionGRPCServer struct {
|
||||
mux *serverMux
|
||||
}
|
||||
|
||||
func (s *BackupItemActionGRPCServer) getImpl(name string) (velerobackup.ItemAction, error) {
|
||||
func (s *BackupItemActionGRPCServer) getImpl(name string) (velero.BackupItemAction, error) {
|
||||
impl, err := s.mux.getHandler(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
itemAction, ok := impl.(velerobackup.ItemAction)
|
||||
itemAction, ok := impl.(velero.BackupItemAction)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("%T is not a backup item action", impl)
|
||||
}
|
||||
@@ -236,7 +236,7 @@ func (s *BackupItemActionGRPCServer) Execute(ctx context.Context, req *proto.Exe
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func backupResourceIdentifierToProto(id velerobackup.ResourceIdentifier) *proto.ResourceIdentifier {
|
||||
func backupResourceIdentifierToProto(id velero.ResourceIdentifier) *proto.ResourceIdentifier {
|
||||
return &proto.ResourceIdentifier{
|
||||
Group: id.Group,
|
||||
Resource: id.Resource,
|
||||
|
||||
@@ -29,9 +29,9 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
v1 "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
"github.com/heptio/velero/pkg/backup"
|
||||
"github.com/heptio/velero/pkg/backup/mocks"
|
||||
proto "github.com/heptio/velero/pkg/plugin/generated"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
velerotest "github.com/heptio/velero/pkg/util/test"
|
||||
)
|
||||
|
||||
@@ -93,7 +93,7 @@ func TestBackupItemActionGRPCServerExecute(t *testing.T) {
|
||||
backup []byte
|
||||
item []byte
|
||||
implUpdatedItem runtime.Unstructured
|
||||
implAdditionalItems []backup.ResourceIdentifier
|
||||
implAdditionalItems []velero.ResourceIdentifier
|
||||
implError error
|
||||
expectError bool
|
||||
skipMock bool
|
||||
@@ -129,7 +129,7 @@ func TestBackupItemActionGRPCServerExecute(t *testing.T) {
|
||||
item: validItem,
|
||||
backup: validBackup,
|
||||
implUpdatedItem: &validItemObject,
|
||||
implAdditionalItems: []backup.ResourceIdentifier{
|
||||
implAdditionalItems: []velero.ResourceIdentifier{
|
||||
{
|
||||
GroupResource: schema.GroupResource{Group: "v1", Resource: "pods"},
|
||||
Namespace: "myns",
|
||||
|
||||
@@ -26,8 +26,8 @@ import (
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
"github.com/heptio/velero/pkg/cloudprovider"
|
||||
proto "github.com/heptio/velero/pkg/plugin/generated"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
// BlockStorePlugin is an implementation of go-plugin's Plugin
|
||||
@@ -203,13 +203,13 @@ type BlockStoreGRPCServer struct {
|
||||
mux *serverMux
|
||||
}
|
||||
|
||||
func (s *BlockStoreGRPCServer) getImpl(name string) (cloudprovider.BlockStore, error) {
|
||||
func (s *BlockStoreGRPCServer) getImpl(name string) (velero.BlockStore, error) {
|
||||
impl, err := s.mux.getHandler(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blockStore, ok := impl.(cloudprovider.BlockStore)
|
||||
blockStore, ok := impl.(velero.BlockStore)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("%T is not a block store", impl)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ type clientDispenser struct {
|
||||
logger logrus.FieldLogger
|
||||
// clienConn is shared among all implementations for this client.
|
||||
clientConn *grpc.ClientConn
|
||||
// initFunc returns a client that implements a plugin interface, such as cloudprovider.ObjectStore.
|
||||
// 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{}
|
||||
|
||||
+15
-17
@@ -21,30 +21,28 @@ import (
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/heptio/velero/pkg/backup"
|
||||
"github.com/heptio/velero/pkg/cloudprovider"
|
||||
"github.com/heptio/velero/pkg/restore"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
// Manager manages the lifecycles of plugins.
|
||||
type Manager interface {
|
||||
// GetObjectStore returns the ObjectStore plugin for name.
|
||||
GetObjectStore(name string) (cloudprovider.ObjectStore, error)
|
||||
GetObjectStore(name string) (velero.ObjectStore, error)
|
||||
|
||||
// GetBlockStore returns the BlockStore plugin for name.
|
||||
GetBlockStore(name string) (cloudprovider.BlockStore, error)
|
||||
GetBlockStore(name string) (velero.BlockStore, error)
|
||||
|
||||
// GetBackupItemActions returns all backup item action plugins.
|
||||
GetBackupItemActions() ([]backup.ItemAction, error)
|
||||
GetBackupItemActions() ([]velero.BackupItemAction, error)
|
||||
|
||||
// GetBackupItemAction returns the backup item action plugin for name.
|
||||
GetBackupItemAction(name string) (backup.ItemAction, error)
|
||||
GetBackupItemAction(name string) (velero.BackupItemAction, error)
|
||||
|
||||
// GetRestoreItemActions returns all restore item action plugins.
|
||||
GetRestoreItemActions() ([]restore.ItemAction, error)
|
||||
GetRestoreItemActions() ([]velero.RestoreItemAction, error)
|
||||
|
||||
// GetRestoreItemAction returns the restore item action plugin for name.
|
||||
GetRestoreItemAction(name string) (restore.ItemAction, error)
|
||||
GetRestoreItemAction(name string) (velero.RestoreItemAction, error)
|
||||
|
||||
// CleanupClients terminates all of the Manager's running plugin processes.
|
||||
CleanupClients()
|
||||
@@ -124,7 +122,7 @@ func (m *manager) getRestartableProcess(kind PluginKind, name string) (Restartab
|
||||
}
|
||||
|
||||
// GetObjectStore returns a restartableObjectStore for name.
|
||||
func (m *manager) GetObjectStore(name string) (cloudprovider.ObjectStore, error) {
|
||||
func (m *manager) GetObjectStore(name string) (velero.ObjectStore, error) {
|
||||
restartableProcess, err := m.getRestartableProcess(PluginKindObjectStore, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -136,7 +134,7 @@ func (m *manager) GetObjectStore(name string) (cloudprovider.ObjectStore, error)
|
||||
}
|
||||
|
||||
// GetBlockStore returns a restartableBlockStore for name.
|
||||
func (m *manager) GetBlockStore(name string) (cloudprovider.BlockStore, error) {
|
||||
func (m *manager) GetBlockStore(name string) (velero.BlockStore, error) {
|
||||
restartableProcess, err := m.getRestartableProcess(PluginKindBlockStore, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -148,10 +146,10 @@ func (m *manager) GetBlockStore(name string) (cloudprovider.BlockStore, error) {
|
||||
}
|
||||
|
||||
// GetBackupItemActions returns all backup item actions as restartableBackupItemActions.
|
||||
func (m *manager) GetBackupItemActions() ([]backup.ItemAction, error) {
|
||||
func (m *manager) GetBackupItemActions() ([]velero.BackupItemAction, error) {
|
||||
list := m.registry.List(PluginKindBackupItemAction)
|
||||
|
||||
actions := make([]backup.ItemAction, 0, len(list))
|
||||
actions := make([]velero.BackupItemAction, 0, len(list))
|
||||
|
||||
for i := range list {
|
||||
id := list[i]
|
||||
@@ -168,7 +166,7 @@ func (m *manager) GetBackupItemActions() ([]backup.ItemAction, error) {
|
||||
}
|
||||
|
||||
// GetBackupItemAction returns a restartableBackupItemAction for name.
|
||||
func (m *manager) GetBackupItemAction(name string) (backup.ItemAction, error) {
|
||||
func (m *manager) GetBackupItemAction(name string) (velero.BackupItemAction, error) {
|
||||
restartableProcess, err := m.getRestartableProcess(PluginKindBackupItemAction, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -179,10 +177,10 @@ func (m *manager) GetBackupItemAction(name string) (backup.ItemAction, error) {
|
||||
}
|
||||
|
||||
// GetRestoreItemActions returns all restore item actions as restartableRestoreItemActions.
|
||||
func (m *manager) GetRestoreItemActions() ([]restore.ItemAction, error) {
|
||||
func (m *manager) GetRestoreItemActions() ([]velero.RestoreItemAction, error) {
|
||||
list := m.registry.List(PluginKindRestoreItemAction)
|
||||
|
||||
actions := make([]restore.ItemAction, 0, len(list))
|
||||
actions := make([]velero.RestoreItemAction, 0, len(list))
|
||||
|
||||
for i := range list {
|
||||
id := list[i]
|
||||
@@ -199,7 +197,7 @@ func (m *manager) GetRestoreItemActions() ([]restore.ItemAction, error) {
|
||||
}
|
||||
|
||||
// GetRestoreItemAction returns a restartableRestoreItemAction for name.
|
||||
func (m *manager) GetRestoreItemAction(name string) (restore.ItemAction, error) {
|
||||
func (m *manager) GetRestoreItemAction(name string) (velero.RestoreItemAction, error) {
|
||||
restartableProcess, err := m.getRestartableProcess(PluginKindRestoreItemAction, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+28
-28
@@ -16,11 +16,11 @@ limitations under the License.
|
||||
// Code generated by mockery v1.0.0. DO NOT EDIT.
|
||||
package mocks
|
||||
|
||||
import backup "github.com/heptio/velero/pkg/backup"
|
||||
import cloudprovider "github.com/heptio/velero/pkg/cloudprovider"
|
||||
import mock "github.com/stretchr/testify/mock"
|
||||
import (
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
import restore "github.com/heptio/velero/pkg/restore"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
// Manager is an autogenerated mock type for the Manager type
|
||||
type Manager struct {
|
||||
@@ -33,15 +33,15 @@ func (_m *Manager) CleanupClients() {
|
||||
}
|
||||
|
||||
// GetBackupItemAction provides a mock function with given fields: name
|
||||
func (_m *Manager) GetBackupItemAction(name string) (backup.ItemAction, error) {
|
||||
func (_m *Manager) GetBackupItemAction(name string) (velero.BackupItemAction, error) {
|
||||
ret := _m.Called(name)
|
||||
|
||||
var r0 backup.ItemAction
|
||||
if rf, ok := ret.Get(0).(func(string) backup.ItemAction); ok {
|
||||
var r0 velero.BackupItemAction
|
||||
if rf, ok := ret.Get(0).(func(string) velero.BackupItemAction); ok {
|
||||
r0 = rf(name)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(backup.ItemAction)
|
||||
r0 = ret.Get(0).(velero.BackupItemAction)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,15 +56,15 @@ func (_m *Manager) GetBackupItemAction(name string) (backup.ItemAction, error) {
|
||||
}
|
||||
|
||||
// GetBackupItemActions provides a mock function with given fields:
|
||||
func (_m *Manager) GetBackupItemActions() ([]backup.ItemAction, error) {
|
||||
func (_m *Manager) GetBackupItemActions() ([]velero.BackupItemAction, error) {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 []backup.ItemAction
|
||||
if rf, ok := ret.Get(0).(func() []backup.ItemAction); ok {
|
||||
var r0 []velero.BackupItemAction
|
||||
if rf, ok := ret.Get(0).(func() []velero.BackupItemAction); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]backup.ItemAction)
|
||||
r0 = ret.Get(0).([]velero.BackupItemAction)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,15 +79,15 @@ func (_m *Manager) GetBackupItemActions() ([]backup.ItemAction, error) {
|
||||
}
|
||||
|
||||
// GetBlockStore provides a mock function with given fields: name
|
||||
func (_m *Manager) GetBlockStore(name string) (cloudprovider.BlockStore, error) {
|
||||
func (_m *Manager) GetBlockStore(name string) (velero.BlockStore, error) {
|
||||
ret := _m.Called(name)
|
||||
|
||||
var r0 cloudprovider.BlockStore
|
||||
if rf, ok := ret.Get(0).(func(string) cloudprovider.BlockStore); ok {
|
||||
var r0 velero.BlockStore
|
||||
if rf, ok := ret.Get(0).(func(string) velero.BlockStore); ok {
|
||||
r0 = rf(name)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(cloudprovider.BlockStore)
|
||||
r0 = ret.Get(0).(velero.BlockStore)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,15 +102,15 @@ func (_m *Manager) GetBlockStore(name string) (cloudprovider.BlockStore, error)
|
||||
}
|
||||
|
||||
// GetObjectStore provides a mock function with given fields: name
|
||||
func (_m *Manager) GetObjectStore(name string) (cloudprovider.ObjectStore, error) {
|
||||
func (_m *Manager) GetObjectStore(name string) (velero.ObjectStore, error) {
|
||||
ret := _m.Called(name)
|
||||
|
||||
var r0 cloudprovider.ObjectStore
|
||||
if rf, ok := ret.Get(0).(func(string) cloudprovider.ObjectStore); ok {
|
||||
var r0 velero.ObjectStore
|
||||
if rf, ok := ret.Get(0).(func(string) velero.ObjectStore); ok {
|
||||
r0 = rf(name)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(cloudprovider.ObjectStore)
|
||||
r0 = ret.Get(0).(velero.ObjectStore)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,15 +125,15 @@ func (_m *Manager) GetObjectStore(name string) (cloudprovider.ObjectStore, error
|
||||
}
|
||||
|
||||
// GetRestoreItemAction provides a mock function with given fields: name
|
||||
func (_m *Manager) GetRestoreItemAction(name string) (restore.ItemAction, error) {
|
||||
func (_m *Manager) GetRestoreItemAction(name string) (velero.RestoreItemAction, error) {
|
||||
ret := _m.Called(name)
|
||||
|
||||
var r0 restore.ItemAction
|
||||
if rf, ok := ret.Get(0).(func(string) restore.ItemAction); ok {
|
||||
var r0 velero.RestoreItemAction
|
||||
if rf, ok := ret.Get(0).(func(string) velero.RestoreItemAction); ok {
|
||||
r0 = rf(name)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(restore.ItemAction)
|
||||
r0 = ret.Get(0).(velero.RestoreItemAction)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,15 +148,15 @@ func (_m *Manager) GetRestoreItemAction(name string) (restore.ItemAction, error)
|
||||
}
|
||||
|
||||
// GetRestoreItemActions provides a mock function with given fields:
|
||||
func (_m *Manager) GetRestoreItemActions() ([]restore.ItemAction, error) {
|
||||
func (_m *Manager) GetRestoreItemActions() ([]velero.RestoreItemAction, error) {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 []restore.ItemAction
|
||||
if rf, ok := ret.Get(0).(func() []restore.ItemAction); ok {
|
||||
var r0 []velero.RestoreItemAction
|
||||
if rf, ok := ret.Get(0).(func() []velero.RestoreItemAction); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]restore.ItemAction)
|
||||
r0 = ret.Get(0).([]velero.RestoreItemAction)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ import (
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/heptio/velero/pkg/cloudprovider"
|
||||
proto "github.com/heptio/velero/pkg/plugin/generated"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
const byteChunkSize = 16384
|
||||
@@ -56,7 +56,7 @@ func (p *ObjectStorePlugin) GRPCClient(c *grpc.ClientConn) (interface{}, error)
|
||||
|
||||
}
|
||||
|
||||
// ObjectStoreGRPCClient implements the cloudprovider.ObjectStore interface and uses a
|
||||
// ObjectStoreGRPCClient implements the ObjectStore interface and uses a
|
||||
// gRPC client to make calls to the plugin server.
|
||||
type ObjectStoreGRPCClient struct {
|
||||
*clientBase
|
||||
@@ -199,13 +199,13 @@ type ObjectStoreGRPCServer struct {
|
||||
mux *serverMux
|
||||
}
|
||||
|
||||
func (s *ObjectStoreGRPCServer) getImpl(name string) (cloudprovider.ObjectStore, error) {
|
||||
func (s *ObjectStoreGRPCServer) getImpl(name string) (velero.ObjectStore, error) {
|
||||
impl, err := s.mux.getHandler(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
itemAction, ok := impl.(cloudprovider.ObjectStore)
|
||||
itemAction, ok := impl.(velero.ObjectStore)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("%T is not an object store", impl)
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func (r *process) dispense(key kindAndName) (interface{}, error) {
|
||||
if key.name == "" {
|
||||
return nil, errors.Errorf("%s plugin requested but name is missing", key.kind.String())
|
||||
}
|
||||
// Get the instance that implements our plugin interface (e.g. cloudprovider.ObjectStore) that is a gRPC-based
|
||||
// Get the instance that implements our plugin interface (e.g. ObjectStore) that is a gRPC-based
|
||||
// client
|
||||
dispensed = clientDispenser.clientFor(key.name)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
api "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
"github.com/heptio/velero/pkg/backup"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
// restartableBackupItemAction is a backup item action for a given implementation (such as "pod"). It is associated with
|
||||
@@ -43,22 +43,22 @@ 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() (backup.ItemAction, error) {
|
||||
func (r *restartableBackupItemAction) getBackupItemAction() (velero.BackupItemAction, error) {
|
||||
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
backupItemAction, ok := plugin.(backup.ItemAction)
|
||||
backupItemAction, ok := plugin.(velero.BackupItemAction)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("%T is not a backup.ItemAction!", plugin)
|
||||
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 restartableBackupItemAction.
|
||||
func (r *restartableBackupItemAction) getDelegate() (backup.ItemAction, error) {
|
||||
func (r *restartableBackupItemAction) getDelegate() (velero.BackupItemAction, error) {
|
||||
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -67,17 +67,17 @@ func (r *restartableBackupItemAction) getDelegate() (backup.ItemAction, error) {
|
||||
}
|
||||
|
||||
// AppliesTo restarts the plugin's process if needed, then delegates the call.
|
||||
func (r *restartableBackupItemAction) AppliesTo() (backup.ResourceSelector, error) {
|
||||
func (r *restartableBackupItemAction) AppliesTo() (velero.ResourceSelector, error) {
|
||||
delegate, err := r.getDelegate()
|
||||
if err != nil {
|
||||
return backup.ResourceSelector{}, err
|
||||
return velero.ResourceSelector{}, err
|
||||
}
|
||||
|
||||
return delegate.AppliesTo()
|
||||
}
|
||||
|
||||
// Execute restarts the plugin's process if needed, then delegates the call.
|
||||
func (r *restartableBackupItemAction) Execute(item runtime.Unstructured, backup *api.Backup) (runtime.Unstructured, []backup.ResourceIdentifier, error) {
|
||||
func (r *restartableBackupItemAction) Execute(item runtime.Unstructured, backup *api.Backup) (runtime.Unstructured, []velero.ResourceIdentifier, error) {
|
||||
delegate, err := r.getDelegate()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
@@ -26,8 +26,8 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
v1 "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
"github.com/heptio/velero/pkg/backup"
|
||||
"github.com/heptio/velero/pkg/backup/mocks"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
func TestRestartableGetBackupItemAction(t *testing.T) {
|
||||
@@ -45,7 +45,7 @@ func TestRestartableGetBackupItemAction(t *testing.T) {
|
||||
{
|
||||
name: "wrong type",
|
||||
plugin: 3,
|
||||
expectedError: "int is not a backup.ItemAction!",
|
||||
expectedError: "int is not a BackupItemAction!",
|
||||
},
|
||||
{
|
||||
name: "happy path",
|
||||
@@ -113,7 +113,7 @@ func TestRestartableBackupItemActionDelegatedFunctions(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
additionalItems := []backup.ResourceIdentifier{
|
||||
additionalItems := []velero.ResourceIdentifier{
|
||||
{
|
||||
GroupResource: schema.GroupResource{Group: "velero.io", Resource: "backups"},
|
||||
},
|
||||
@@ -134,13 +134,13 @@ func TestRestartableBackupItemActionDelegatedFunctions(t *testing.T) {
|
||||
restartableDelegateTest{
|
||||
function: "AppliesTo",
|
||||
inputs: []interface{}{},
|
||||
expectedErrorOutputs: []interface{}{backup.ResourceSelector{}, errors.Errorf("reset error")},
|
||||
expectedDelegateOutputs: []interface{}{backup.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")},
|
||||
expectedErrorOutputs: []interface{}{velero.ResourceSelector{}, errors.Errorf("reset error")},
|
||||
expectedDelegateOutputs: []interface{}{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")},
|
||||
},
|
||||
restartableDelegateTest{
|
||||
function: "Execute",
|
||||
inputs: []interface{}{pv, b},
|
||||
expectedErrorOutputs: []interface{}{nil, ([]backup.ResourceIdentifier)(nil), errors.Errorf("reset error")},
|
||||
expectedErrorOutputs: []interface{}{nil, ([]velero.ResourceIdentifier)(nil), errors.Errorf("reset error")},
|
||||
expectedDelegateOutputs: []interface{}{pvToReturn, additionalItems, errors.Errorf("delegate error")},
|
||||
},
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
"github.com/heptio/velero/pkg/cloudprovider"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
// restartableBlockStore is an object store for a given implementation (such as "aws"). It is associated with
|
||||
@@ -48,31 +48,31 @@ func newRestartableBlockStore(name string, sharedPluginProcess RestartableProces
|
||||
|
||||
// reinitialize reinitializes a re-dispensed plugin using the initial data passed to Init().
|
||||
func (r *restartableBlockStore) reinitialize(dispensed interface{}) error {
|
||||
blockStore, ok := dispensed.(cloudprovider.BlockStore)
|
||||
blockStore, ok := dispensed.(velero.BlockStore)
|
||||
if !ok {
|
||||
return errors.Errorf("%T is not a cloudprovider.BlockStore!", dispensed)
|
||||
return errors.Errorf("%T is not a BlockStore!", dispensed)
|
||||
}
|
||||
return r.init(blockStore, r.config)
|
||||
}
|
||||
|
||||
// getBlockStore returns the block store for this restartableBlockStore. It does *not* restart the
|
||||
// plugin process.
|
||||
func (r *restartableBlockStore) getBlockStore() (cloudprovider.BlockStore, error) {
|
||||
func (r *restartableBlockStore) getBlockStore() (velero.BlockStore, error) {
|
||||
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blockStore, ok := plugin.(cloudprovider.BlockStore)
|
||||
blockStore, ok := plugin.(velero.BlockStore)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("%T is not a cloudprovider.BlockStore!", plugin)
|
||||
return nil, errors.Errorf("%T is not a BlockStore!", plugin)
|
||||
}
|
||||
|
||||
return blockStore, nil
|
||||
}
|
||||
|
||||
// getDelegate restarts the plugin process (if needed) and returns the block store for this restartableBlockStore.
|
||||
func (r *restartableBlockStore) getDelegate() (cloudprovider.BlockStore, error) {
|
||||
func (r *restartableBlockStore) getDelegate() (velero.BlockStore, error) {
|
||||
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func (r *restartableBlockStore) Init(config map[string]string) error {
|
||||
|
||||
// init calls Init on blockStore with config. This is split out from Init() so that both Init() and reinitialize() may
|
||||
// call it using a specific BlockStore.
|
||||
func (r *restartableBlockStore) init(blockStore cloudprovider.BlockStore, config map[string]string) error {
|
||||
func (r *restartableBlockStore) init(blockStore velero.BlockStore, config map[string]string) error {
|
||||
return blockStore.Init(config)
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestRestartableGetBlockStore(t *testing.T) {
|
||||
{
|
||||
name: "wrong type",
|
||||
plugin: 3,
|
||||
expectedError: "int is not a cloudprovider.BlockStore!",
|
||||
expectedError: "int is not a BlockStore!",
|
||||
},
|
||||
{
|
||||
name: "happy path",
|
||||
@@ -93,7 +93,7 @@ func TestRestartableBlockStoreReinitialize(t *testing.T) {
|
||||
}
|
||||
|
||||
err := r.reinitialize(3)
|
||||
assert.EqualError(t, err, "int is not a cloudprovider.BlockStore!")
|
||||
assert.EqualError(t, err, "int is not a BlockStore!")
|
||||
|
||||
blockStore := new(mocks.BlockStore)
|
||||
blockStore.Test(t)
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/heptio/velero/pkg/cloudprovider"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
// restartableObjectStore is an object store for a given implementation (such as "aws"). It is associated with
|
||||
@@ -52,9 +52,9 @@ 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.(cloudprovider.ObjectStore)
|
||||
objectStore, ok := dispensed.(velero.ObjectStore)
|
||||
if !ok {
|
||||
return errors.Errorf("%T is not a cloudprovider.ObjectStore!", dispensed)
|
||||
return errors.Errorf("%T is not a ObjectStore!", dispensed)
|
||||
}
|
||||
|
||||
return r.init(objectStore, r.config)
|
||||
@@ -62,22 +62,22 @@ 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() (cloudprovider.ObjectStore, error) {
|
||||
func (r *restartableObjectStore) getObjectStore() (velero.ObjectStore, error) {
|
||||
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
objectStore, ok := plugin.(cloudprovider.ObjectStore)
|
||||
objectStore, ok := plugin.(velero.ObjectStore)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("%T is not a cloudprovider.ObjectStore!", plugin)
|
||||
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 *restartableObjectStore) getDelegate() (cloudprovider.ObjectStore, error) {
|
||||
func (r *restartableObjectStore) getDelegate() (velero.ObjectStore, error) {
|
||||
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func (r *restartableObjectStore) Init(config map[string]string) error {
|
||||
|
||||
// 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 cloudprovider.ObjectStore, config map[string]string) error {
|
||||
func (r *restartableObjectStore) init(objectStore velero.ObjectStore, config map[string]string) error {
|
||||
return objectStore.Init(config)
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestRestartableGetObjectStore(t *testing.T) {
|
||||
{
|
||||
name: "wrong type",
|
||||
plugin: 3,
|
||||
expectedError: "int is not a cloudprovider.ObjectStore!",
|
||||
expectedError: "int is not a ObjectStore!",
|
||||
},
|
||||
{
|
||||
name: "happy path",
|
||||
@@ -94,7 +94,7 @@ func TestRestartableObjectStoreReinitialize(t *testing.T) {
|
||||
}
|
||||
|
||||
err := r.reinitialize(3)
|
||||
assert.EqualError(t, err, "int is not a cloudprovider.ObjectStore!")
|
||||
assert.EqualError(t, err, "int is not a ObjectStore!")
|
||||
|
||||
objectStore := new(cloudprovidermocks.ObjectStore)
|
||||
objectStore.Test(t)
|
||||
|
||||
@@ -18,7 +18,7 @@ package plugin
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/heptio/velero/pkg/restore"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
// restartableRestoreItemAction is a restore item action for a given implementation (such as "pod"). It is associated with
|
||||
@@ -42,22 +42,22 @@ 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() (restore.ItemAction, error) {
|
||||
func (r *restartableRestoreItemAction) getRestoreItemAction() (velero.RestoreItemAction, error) {
|
||||
plugin, err := r.sharedPluginProcess.getByKindAndName(r.key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
restoreItemAction, ok := plugin.(restore.ItemAction)
|
||||
restoreItemAction, ok := plugin.(velero.RestoreItemAction)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("%T is not a restore.ItemAction!", plugin)
|
||||
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 *restartableRestoreItemAction) getDelegate() (restore.ItemAction, error) {
|
||||
func (r *restartableRestoreItemAction) getDelegate() (velero.RestoreItemAction, error) {
|
||||
if err := r.sharedPluginProcess.resetIfNeeded(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -66,17 +66,17 @@ func (r *restartableRestoreItemAction) getDelegate() (restore.ItemAction, error)
|
||||
}
|
||||
|
||||
// AppliesTo restarts the plugin's process if needed, then delegates the call.
|
||||
func (r *restartableRestoreItemAction) AppliesTo() (restore.ResourceSelector, error) {
|
||||
func (r *restartableRestoreItemAction) AppliesTo() (velero.ResourceSelector, error) {
|
||||
delegate, err := r.getDelegate()
|
||||
if err != nil {
|
||||
return restore.ResourceSelector{}, err
|
||||
return velero.ResourceSelector{}, err
|
||||
}
|
||||
|
||||
return delegate.AppliesTo()
|
||||
}
|
||||
|
||||
// Execute restarts the plugin's process if needed, then delegates the call.
|
||||
func (r *restartableRestoreItemAction) Execute(input *restore.RestoreItemActionExecuteInput) (*restore.RestoreItemActionExecuteOutput, error) {
|
||||
func (r *restartableRestoreItemAction) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
|
||||
delegate, err := r.getDelegate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
|
||||
v1 "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
"github.com/heptio/velero/pkg/restore"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
"github.com/heptio/velero/pkg/restore/mocks"
|
||||
)
|
||||
|
||||
@@ -44,7 +44,7 @@ func TestRestartableGetRestoreItemAction(t *testing.T) {
|
||||
{
|
||||
name: "wrong type",
|
||||
plugin: 3,
|
||||
expectedError: "int is not a restore.ItemAction!",
|
||||
expectedError: "int is not a RestoreItemAction!",
|
||||
},
|
||||
{
|
||||
name: "happy path",
|
||||
@@ -104,13 +104,13 @@ func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
input := &restore.RestoreItemActionExecuteInput{
|
||||
input := &velero.RestoreItemActionExecuteInput{
|
||||
Item: pv,
|
||||
ItemFromBackup: pv,
|
||||
Restore: new(v1.Restore),
|
||||
}
|
||||
|
||||
output := &restore.RestoreItemActionExecuteOutput{
|
||||
output := &velero.RestoreItemActionExecuteOutput{
|
||||
UpdatedItem: &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"color": "green",
|
||||
@@ -134,8 +134,8 @@ func TestRestartableRestoreItemActionDelegatedFunctions(t *testing.T) {
|
||||
restartableDelegateTest{
|
||||
function: "AppliesTo",
|
||||
inputs: []interface{}{},
|
||||
expectedErrorOutputs: []interface{}{restore.ResourceSelector{}, errors.Errorf("reset error")},
|
||||
expectedDelegateOutputs: []interface{}{restore.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")},
|
||||
expectedErrorOutputs: []interface{}{velero.ResourceSelector{}, errors.Errorf("reset error")},
|
||||
expectedDelegateOutputs: []interface{}{velero.ResourceSelector{IncludedNamespaces: []string{"a"}}, errors.Errorf("delegate error")},
|
||||
},
|
||||
restartableDelegateTest{
|
||||
function: "Execute",
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
|
||||
api "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
proto "github.com/heptio/velero/pkg/plugin/generated"
|
||||
"github.com/heptio/velero/pkg/restore"
|
||||
"github.com/heptio/velero/pkg/plugin/velero"
|
||||
)
|
||||
|
||||
// RestoreItemActionPlugin is an implementation of go-plugin's Plugin
|
||||
@@ -38,7 +38,7 @@ type RestoreItemActionPlugin struct {
|
||||
*pluginBase
|
||||
}
|
||||
|
||||
var _ restore.ItemAction = &RestoreItemActionGRPCClient{}
|
||||
var _ velero.RestoreItemAction = &RestoreItemActionGRPCClient{}
|
||||
|
||||
// NewRestoreItemActionPlugin constructs a RestoreItemActionPlugin.
|
||||
func NewRestoreItemActionPlugin(options ...pluginOption) *RestoreItemActionPlugin {
|
||||
@@ -70,13 +70,13 @@ func newRestoreItemActionGRPCClient(base *clientBase, clientConn *grpc.ClientCon
|
||||
}
|
||||
}
|
||||
|
||||
func (c *RestoreItemActionGRPCClient) AppliesTo() (restore.ResourceSelector, error) {
|
||||
func (c *RestoreItemActionGRPCClient) AppliesTo() (velero.ResourceSelector, error) {
|
||||
res, err := c.grpcClient.AppliesTo(context.Background(), &proto.AppliesToRequest{Plugin: c.plugin})
|
||||
if err != nil {
|
||||
return restore.ResourceSelector{}, err
|
||||
return velero.ResourceSelector{}, err
|
||||
}
|
||||
|
||||
return restore.ResourceSelector{
|
||||
return velero.ResourceSelector{
|
||||
IncludedNamespaces: res.IncludedNamespaces,
|
||||
ExcludedNamespaces: res.ExcludedNamespaces,
|
||||
IncludedResources: res.IncludedResources,
|
||||
@@ -85,7 +85,7 @@ func (c *RestoreItemActionGRPCClient) AppliesTo() (restore.ResourceSelector, err
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *RestoreItemActionGRPCClient) Execute(input *restore.RestoreItemActionExecuteInput) (*restore.RestoreItemActionExecuteOutput, error) {
|
||||
func (c *RestoreItemActionGRPCClient) Execute(input *velero.RestoreItemActionExecuteInput) (*velero.RestoreItemActionExecuteOutput, error) {
|
||||
itemJSON, err := json.Marshal(input.Item.UnstructuredContent())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -123,7 +123,7 @@ func (c *RestoreItemActionGRPCClient) Execute(input *restore.RestoreItemActionEx
|
||||
warning = errors.New(res.Warning)
|
||||
}
|
||||
|
||||
return &restore.RestoreItemActionExecuteOutput{
|
||||
return &velero.RestoreItemActionExecuteOutput{
|
||||
UpdatedItem: &updatedItem,
|
||||
Warning: warning,
|
||||
}, nil
|
||||
@@ -145,13 +145,13 @@ type RestoreItemActionGRPCServer struct {
|
||||
mux *serverMux
|
||||
}
|
||||
|
||||
func (s *RestoreItemActionGRPCServer) getImpl(name string) (restore.ItemAction, error) {
|
||||
func (s *RestoreItemActionGRPCServer) getImpl(name string) (velero.RestoreItemAction, error) {
|
||||
impl, err := s.mux.getHandler(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
itemAction, ok := impl.(restore.ItemAction)
|
||||
itemAction, ok := impl.(velero.RestoreItemAction)
|
||||
if !ok {
|
||||
return nil, errors.Errorf("%T is not a restore item action", impl)
|
||||
}
|
||||
@@ -215,7 +215,7 @@ func (s *RestoreItemActionGRPCServer) Execute(ctx context.Context, req *proto.Re
|
||||
return nil, err
|
||||
}
|
||||
|
||||
executeOutput, err := impl.Execute(&restore.RestoreItemActionExecuteInput{
|
||||
executeOutput, err := impl.Execute(&velero.RestoreItemActionExecuteInput{
|
||||
Item: &item,
|
||||
ItemFromBackup: &itemFromBackup,
|
||||
Restore: &restoreObj,
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright 2017 the Heptio Ark 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 velero
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
|
||||
api "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
)
|
||||
|
||||
// BackupItemAction is an actor that performs an operation on an individual item being backed up.
|
||||
type BackupItemAction interface {
|
||||
// AppliesTo returns information about which resources this action should be invoked for.
|
||||
// A BackupItemAction's Execute function will only be invoked on items that match the returned
|
||||
// selector. A zero-valued ResourceSelector matches all resources.
|
||||
AppliesTo() (ResourceSelector, error)
|
||||
|
||||
// Execute allows the ItemAction to perform arbitrary logic with the item being backed up,
|
||||
// including mutating the item itself prior to backup. The item (unmodified or modified)
|
||||
// should be returned, along with an optional slice of ResourceIdentifiers specifying
|
||||
// additional related items that should be backed up.
|
||||
Execute(item runtime.Unstructured, backup *api.Backup) (runtime.Unstructured, []ResourceIdentifier, error)
|
||||
}
|
||||
|
||||
// ResourceIdentifier describes a single item by its group, resource, namespace, and name.
|
||||
type ResourceIdentifier struct {
|
||||
schema.GroupResource
|
||||
Namespace string
|
||||
Name string
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright 2017 the Heptio Ark 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 velero
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// BlockStore exposes basic block-storage operations required
|
||||
// by Velero.
|
||||
type BlockStore interface {
|
||||
// Init prepares the BlockStore for usage using the provided map of
|
||||
// configuration key-value pairs. It returns an error if the BlockStore
|
||||
// cannot be initialized from the provided config.
|
||||
Init(config map[string]string) error
|
||||
|
||||
// CreateVolumeFromSnapshot creates a new block volume in the specified
|
||||
// availability zone, initialized from the provided snapshot,
|
||||
// and with the specified type and IOPS (if using provisioned IOPS).
|
||||
CreateVolumeFromSnapshot(snapshotID, volumeType, volumeAZ string, iops *int64) (volumeID string, err error)
|
||||
|
||||
// GetVolumeID returns the cloud provider specific identifier for the PersistentVolume.
|
||||
GetVolumeID(pv runtime.Unstructured) (string, error)
|
||||
|
||||
// SetVolumeID sets the cloud provider specific identifier for the PersistentVolume.
|
||||
SetVolumeID(pv runtime.Unstructured, volumeID string) (runtime.Unstructured, error)
|
||||
|
||||
// GetVolumeInfo returns the type and IOPS (if using provisioned IOPS) for
|
||||
// the specified block volume in the given availability zone.
|
||||
GetVolumeInfo(volumeID, volumeAZ string) (string, *int64, error)
|
||||
|
||||
// CreateSnapshot creates a snapshot of the specified block volume, and applies the provided
|
||||
// set of tags to the snapshot.
|
||||
CreateSnapshot(volumeID, volumeAZ string, tags map[string]string) (snapshotID string, err error)
|
||||
|
||||
// DeleteSnapshot deletes the specified volume snapshot.
|
||||
DeleteSnapshot(snapshotID string) error
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Copyright 2017 the Heptio Ark 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 velero
|
||||
|
||||
import (
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ObjectStore exposes basic object-storage operations required
|
||||
// by Velero.
|
||||
type ObjectStore interface {
|
||||
// Init prepares the ObjectStore for usage using the provided map of
|
||||
// configuration key-value pairs. It returns an error if the ObjectStore
|
||||
// cannot be initialized from the provided config.
|
||||
Init(config map[string]string) error
|
||||
|
||||
// PutObject creates a new object using the data in body within the specified
|
||||
// object storage bucket with the given key.
|
||||
PutObject(bucket, key string, body io.Reader) error
|
||||
|
||||
// GetObject retrieves the object with the given key from the specified
|
||||
// bucket in object storage.
|
||||
GetObject(bucket, key string) (io.ReadCloser, error)
|
||||
|
||||
// ListCommonPrefixes gets a list of all object key prefixes that start with
|
||||
// the specified prefix and stop at the next instance of the provided delimiter.
|
||||
//
|
||||
// For example, if the bucket contains the following keys:
|
||||
// a-prefix/foo-1/bar
|
||||
// a-prefix/foo-1/baz
|
||||
// a-prefix/foo-2/baz
|
||||
// some-other-prefix/foo-3/bar
|
||||
// and the provided prefix arg is "a-prefix/", and the delimiter is "/",
|
||||
// this will return the slice {"a-prefix/foo-1/", "a-prefix/foo-2/"}.
|
||||
ListCommonPrefixes(bucket, prefix, delimiter string) ([]string, error)
|
||||
|
||||
// ListObjects gets a list of all keys in the specified bucket
|
||||
// that have the given prefix.
|
||||
ListObjects(bucket, prefix string) ([]string, error)
|
||||
|
||||
// DeleteObject removes the object with the specified key from the given
|
||||
// bucket.
|
||||
DeleteObject(bucket, key string) error
|
||||
|
||||
// CreateSignedURL creates a pre-signed URL for the given bucket and key that expires after ttl.
|
||||
CreateSignedURL(bucket, key string, ttl time.Duration) (string, error)
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
Copyright 2017 the Heptio Ark 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 velero
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
api "github.com/heptio/velero/pkg/apis/velero/v1"
|
||||
)
|
||||
|
||||
// RestoreItemAction is an actor that performs an operation on an individual item being restored.
|
||||
type RestoreItemAction interface {
|
||||
// AppliesTo returns information about which resources this action should be invoked for.
|
||||
// A RestoreItemAction's Execute function will only be invoked on items that match the returned
|
||||
// selector. A zero-valued ResourceSelector matches all resources.
|
||||
AppliesTo() (ResourceSelector, error)
|
||||
|
||||
// Execute allows the ItemAction to perform arbitrary logic with the item being restored,
|
||||
// including mutating the item itself prior to restore. The item (unmodified or modified)
|
||||
// should be returned, along with a warning (which will be logged but will not prevent
|
||||
// the item from being restored) or error (which will be logged and will prevent the item
|
||||
// from being restored) if applicable.
|
||||
Execute(input *RestoreItemActionExecuteInput) (*RestoreItemActionExecuteOutput, error)
|
||||
}
|
||||
|
||||
// RestoreItemActionExecuteInput contains the input parameters for the ItemAction's Execute function.
|
||||
type RestoreItemActionExecuteInput struct {
|
||||
// Item is the item being restored. It is likely different from the pristine backed up version
|
||||
// (metadata reset, changed by various restore item action plugins, etc.).
|
||||
Item runtime.Unstructured
|
||||
// ItemFromBackup is the item taken from the pristine backed up version of resource.
|
||||
ItemFromBackup runtime.Unstructured
|
||||
// Restore is the representation of the restore resource processed by Ark.
|
||||
Restore *api.Restore
|
||||
}
|
||||
|
||||
// RestoreItemActionExecuteOutput contains the output variables for the ItemAction's Execution function.
|
||||
type RestoreItemActionExecuteOutput struct {
|
||||
// UpdatedItem is the item being restored mutated by ItemAction.
|
||||
UpdatedItem runtime.Unstructured
|
||||
// Warning is an exceptional message returned from ItemAction
|
||||
// which is not preventing the item from being restored.
|
||||
Warning error
|
||||
}
|
||||
|
||||
// NewRestoreItemActionExecuteOutput creates a new RestoreItemActionExecuteOutput
|
||||
func NewRestoreItemActionExecuteOutput(item runtime.Unstructured) *RestoreItemActionExecuteOutput {
|
||||
return &RestoreItemActionExecuteOutput{
|
||||
UpdatedItem: item,
|
||||
}
|
||||
}
|
||||
|
||||
// WithWarning returns a warning for RestoreItemActionExecuteOutput
|
||||
func (r *RestoreItemActionExecuteOutput) WithWarning(err error) *RestoreItemActionExecuteOutput {
|
||||
r.Warning = err
|
||||
return r
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright 2019 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 velero contains the interfaces necessary to implement
|
||||
// all of the Velero plugins. Users create their own binary containing
|
||||
// implementations of the plugin kinds in this package. Multiple
|
||||
// plugins of any type can be implemented.
|
||||
package velero
|
||||
|
||||
// ResourceSelector is a collection of included/excluded namespaces,
|
||||
// included/excluded resources, and a label-selector that can be used
|
||||
// to match a set of items from a cluster.
|
||||
type ResourceSelector struct {
|
||||
// IncludedNamespaces is a slice of namespace names to match. All
|
||||
// namespaces in this slice, except those in ExcludedNamespaces,
|
||||
// will be matched. A nil/empty slice matches all namespaces.
|
||||
IncludedNamespaces []string
|
||||
// ExcludedNamespaces is a slice of namespace names to exclude.
|
||||
// All namespaces in IncludedNamespaces, *except* those in
|
||||
// this slice, will be matched.
|
||||
ExcludedNamespaces []string
|
||||
// IncludedResources is a slice of resources to match. Resources
|
||||
// may be specified as full names (e.g. "services") or abbreviations
|
||||
// (e.g. "svc"). All resources in this slice, except those in
|
||||
// ExcludedResources, will be matched. A nil/empty slice matches
|
||||
// all resources.
|
||||
IncludedResources []string
|
||||
// ExcludedResources is a slice of resources to exclude.
|
||||
// Resources may be specified as full names (e.g. "services") or
|
||||
// abbreviations (e.g. "svc"). All resources in IncludedResources,
|
||||
// *except* those in this slice, will be matched.
|
||||
ExcludedResources []string
|
||||
// LabelSelector is a string representation of a selector to apply
|
||||
// when matching resources. See "k8s.io/apimachinery/pkg/labels".Parse()
|
||||
// for details on syntax.
|
||||
LabelSelector string
|
||||
}
|
||||
Reference in New Issue
Block a user