rename BlockStore to VolumeSnapshotter

Signed-off-by: Steve Kriss <krisss@vmware.com>
This commit is contained in:
Steve Kriss
2019-03-27 12:22:04 -06:00
parent 3f2c28f6bb
commit bb9c3f6a1a
50 changed files with 591 additions and 590 deletions

View File

@@ -21,30 +21,30 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)
func ExampleNewServer_blockStore() {
func ExampleNewServer_volumeSnapshotter() {
NewServer(). // call the server
RegisterBlockStore("example-blockstore", newBlockStore). // register the plugin
Serve() // serve the plugin
RegisterVolumeSnapshotter("example-volumesnapshotter", newVolumeSnapshotter). // register the plugin
Serve() // serve the plugin
}
func newBlockStore(logger logrus.FieldLogger) (interface{}, error) {
return &BlockStore{FieldLogger: logger}, nil
func newVolumeSnapshotter(logger logrus.FieldLogger) (interface{}, error) {
return &VolumeSnapshotter{FieldLogger: logger}, nil
}
type BlockStore struct {
type VolumeSnapshotter struct {
FieldLogger logrus.FieldLogger
}
// Implement all methods for the BlockStore interface...
func (b *BlockStore) Init(config map[string]string) error {
b.FieldLogger.Infof("BlockStore.Init called")
// Implement all methods for the VolumeSnapshotter interface...
func (b *VolumeSnapshotter) Init(config map[string]string) error {
b.FieldLogger.Infof("VolumeSnapshotter.Init called")
// ...
return nil
}
func (b *BlockStore) CreateVolumeFromSnapshot(snapshotID, volumeType, volumeAZ string, iops *int64) (volumeID string, err error) {
func (b *VolumeSnapshotter) CreateVolumeFromSnapshot(snapshotID, volumeType, volumeAZ string, iops *int64) (volumeID string, err error) {
b.FieldLogger.Infof("CreateVolumeFromSnapshot called")
// ...
@@ -52,7 +52,7 @@ func (b *BlockStore) CreateVolumeFromSnapshot(snapshotID, volumeType, volumeAZ s
return "volumeID", nil
}
func (b *BlockStore) GetVolumeID(pv runtime.Unstructured) (string, error) {
func (b *VolumeSnapshotter) GetVolumeID(pv runtime.Unstructured) (string, error) {
b.FieldLogger.Infof("GetVolumeID called")
// ...
@@ -60,7 +60,7 @@ func (b *BlockStore) GetVolumeID(pv runtime.Unstructured) (string, error) {
return "volumeID", nil
}
func (b *BlockStore) SetVolumeID(pv runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
func (b *VolumeSnapshotter) SetVolumeID(pv runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
b.FieldLogger.Infof("SetVolumeID called")
// ...
@@ -68,7 +68,7 @@ func (b *BlockStore) SetVolumeID(pv runtime.Unstructured, volumeID string) (runt
return nil, nil
}
func (b *BlockStore) GetVolumeInfo(volumeID, volumeAZ string) (string, *int64, error) {
func (b *VolumeSnapshotter) GetVolumeInfo(volumeID, volumeAZ string) (string, *int64, error) {
b.FieldLogger.Infof("GetVolumeInfo called")
// ...
@@ -76,7 +76,7 @@ func (b *BlockStore) GetVolumeInfo(volumeID, volumeAZ string) (string, *int64, e
return "volumeFilesystemType", nil, nil
}
func (b *BlockStore) CreateSnapshot(volumeID, volumeAZ string, tags map[string]string) (snapshotID string, err error) {
func (b *VolumeSnapshotter) CreateSnapshot(volumeID, volumeAZ string, tags map[string]string) (snapshotID string, err error) {
b.FieldLogger.Infof("CreateSnapshot called")
// ...
@@ -84,7 +84,7 @@ func (b *BlockStore) CreateSnapshot(volumeID, volumeAZ string, tags map[string]s
return "snapshotID", nil
}
func (b *BlockStore) DeleteSnapshot(snapshotID string) error {
func (b *VolumeSnapshotter) DeleteSnapshot(snapshotID string) error {
b.FieldLogger.Infof("DeleteSnapshot called")
// ...

View File

@@ -33,8 +33,8 @@ const (
// PluginKindObjectStore represents an object store plugin.
PluginKindObjectStore PluginKind = "ObjectStore"
// PluginKindBlockStore represents a block store plugin.
PluginKindBlockStore PluginKind = "BlockStore"
// PluginKindVolumeSnapshotter represents a volume snapshotter plugin.
PluginKindVolumeSnapshotter PluginKind = "VolumeSnapshotter"
// PluginKindBackupItemAction represents a backup item action plugin.
PluginKindBackupItemAction PluginKind = "BackupItemAction"
@@ -50,7 +50,7 @@ const (
// kind that a developer would ever need to implement (it's handled by Velero and the Velero plugin library code).
var allPluginKinds = sets.NewString(
PluginKindObjectStore.String(),
PluginKindBlockStore.String(),
PluginKindVolumeSnapshotter.String(),
PluginKindBackupItemAction.String(),
PluginKindRestoreItemAction.String(),
)

View File

@@ -25,7 +25,7 @@ import (
func TestAllPluginKinds(t *testing.T) {
expected := sets.NewString(
PluginKindObjectStore.String(),
PluginKindBlockStore.String(),
PluginKindVolumeSnapshotter.String(),
PluginKindBackupItemAction.String(),
PluginKindRestoreItemAction.String(),
)

View File

@@ -25,7 +25,7 @@ import (
func TestPluginImplementationsAreGRPCPlugins(t *testing.T) {
pluginImpls := []interface{}{
new(BlockStorePlugin),
new(VolumeSnapshotterPlugin),
new(BackupItemActionPlugin),
new(ObjectStorePlugin),
new(PluginListerPlugin),

View File

@@ -54,11 +54,11 @@ type Server interface {
// RegisterBackupItemActions registers multiple backup item actions.
RegisterBackupItemActions(map[string]HandlerInitializer) Server
// RegisterBlockStore registers a block store.
RegisterBlockStore(name string, initializer HandlerInitializer) Server
// RegisterVolumeSnapshotter registers a volume snapshotter.
RegisterVolumeSnapshotter(name string, initializer HandlerInitializer) Server
// RegisterBlockStores registers multiple block stores.
RegisterBlockStores(map[string]HandlerInitializer) Server
// RegisterVolumeSnapshotters registers multiple volume snapshotters.
RegisterVolumeSnapshotters(map[string]HandlerInitializer) Server
// RegisterObjectStore registers an object store.
RegisterObjectStore(name string, initializer HandlerInitializer) Server
@@ -82,7 +82,7 @@ type server struct {
logLevelFlag *logging.LevelFlag
flagSet *pflag.FlagSet
backupItemAction *BackupItemActionPlugin
blockStore *BlockStorePlugin
volumeSnapshotter *VolumeSnapshotterPlugin
objectStore *ObjectStorePlugin
restoreItemAction *RestoreItemActionPlugin
}
@@ -95,7 +95,7 @@ func NewServer() Server {
log: log,
logLevelFlag: logging.LogLevelFlag(log.Level),
backupItemAction: NewBackupItemActionPlugin(serverLogger(log)),
blockStore: NewBlockStorePlugin(serverLogger(log)),
volumeSnapshotter: NewVolumeSnapshotterPlugin(serverLogger(log)),
objectStore: NewObjectStorePlugin(serverLogger(log)),
restoreItemAction: NewRestoreItemActionPlugin(serverLogger(log)),
}
@@ -120,14 +120,14 @@ func (s *server) RegisterBackupItemActions(m map[string]HandlerInitializer) Serv
return s
}
func (s *server) RegisterBlockStore(name string, initializer HandlerInitializer) Server {
s.blockStore.register(name, initializer)
func (s *server) RegisterVolumeSnapshotter(name string, initializer HandlerInitializer) Server {
s.volumeSnapshotter.register(name, initializer)
return s
}
func (s *server) RegisterBlockStores(m map[string]HandlerInitializer) Server {
func (s *server) RegisterVolumeSnapshotters(m map[string]HandlerInitializer) Server {
for name := range m {
s.RegisterBlockStore(name, m[name])
s.RegisterVolumeSnapshotter(name, m[name])
}
return s
}
@@ -181,7 +181,7 @@ func (s *server) Serve() {
var pluginIdentifiers []PluginIdentifier
pluginIdentifiers = append(pluginIdentifiers, getNames(command, PluginKindBackupItemAction, s.backupItemAction)...)
pluginIdentifiers = append(pluginIdentifiers, getNames(command, PluginKindBlockStore, s.blockStore)...)
pluginIdentifiers = append(pluginIdentifiers, getNames(command, PluginKindVolumeSnapshotter, s.volumeSnapshotter)...)
pluginIdentifiers = append(pluginIdentifiers, getNames(command, PluginKindObjectStore, s.objectStore)...)
pluginIdentifiers = append(pluginIdentifiers, getNames(command, PluginKindRestoreItemAction, s.restoreItemAction)...)
@@ -191,7 +191,7 @@ func (s *server) Serve() {
HandshakeConfig: Handshake,
Plugins: map[string]plugin.Plugin{
string(PluginKindBackupItemAction): s.backupItemAction,
string(PluginKindBlockStore): s.blockStore,
string(PluginKindVolumeSnapshotter): s.volumeSnapshotter,
string(PluginKindObjectStore): s.objectStore,
string(PluginKindPluginLister): NewPluginListerPlugin(pluginLister),
string(PluginKindRestoreItemAction): s.restoreItemAction,

View File

@@ -23,7 +23,7 @@ import (
)
// HandlerInitializer is a function that initializes and returns a new instance of one of Velero's plugin interfaces
// (ObjectStore, BlockStore, BackupItemAction, RestoreItemAction).
// (ObjectStore, VolumeSnapshotter, BackupItemAction, RestoreItemAction).
type HandlerInitializer func(logger logrus.FieldLogger) (interface{}, error)
// serverMux manages multiple implementations of a single plugin kind, such as pod and pvc BackupItemActions.

View File

@@ -24,21 +24,21 @@ import (
proto "github.com/heptio/velero/pkg/plugin/generated"
)
// BlockStorePlugin is an implementation of go-plugin's Plugin
// interface with support for gRPC for the cloudprovider/BlockStore
// VolumeSnapshotterPlugin is an implementation of go-plugin's Plugin
// interface with support for gRPC for the cloudprovider/VolumeSnapshotter
// interface.
type BlockStorePlugin struct {
type VolumeSnapshotterPlugin struct {
plugin.NetRPCUnsupportedPlugin
*pluginBase
}
// GRPCClient returns a BlockStore gRPC client.
func (p *BlockStorePlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) {
return newClientDispenser(p.clientLogger, clientConn, newBlockStoreGRPCClient), nil
// GRPCClient returns a VolumeSnapshotter gRPC client.
func (p *VolumeSnapshotterPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, clientConn *grpc.ClientConn) (interface{}, error) {
return newClientDispenser(p.clientLogger, clientConn, newVolumeSnapshotterGRPCClient), nil
}
// GRPCServer registers a BlockStore gRPC server.
func (p *BlockStorePlugin) GRPCServer(_ *plugin.GRPCBroker, server *grpc.Server) error {
proto.RegisterBlockStoreServer(server, &BlockStoreGRPCServer{mux: p.serverMux})
// GRPCServer registers a VolumeSnapshotter gRPC server.
func (p *VolumeSnapshotterPlugin) GRPCServer(_ *plugin.GRPCBroker, server *grpc.Server) error {
proto.RegisterVolumeSnapshotterServer(server, &VolumeSnapshotterGRPCServer{mux: p.serverMux})
return nil
}

View File

@@ -28,31 +28,31 @@ import (
proto "github.com/heptio/velero/pkg/plugin/generated"
)
// NewBlockStorePlugin constructs a BlockStorePlugin.
func NewBlockStorePlugin(options ...PluginOption) *BlockStorePlugin {
return &BlockStorePlugin{
// NewVolumeSnapshotterPlugin constructs a VolumeSnapshotterPlugin.
func NewVolumeSnapshotterPlugin(options ...PluginOption) *VolumeSnapshotterPlugin {
return &VolumeSnapshotterPlugin{
pluginBase: newPluginBase(options...),
}
}
// BlockStoreGRPCClient implements the cloudprovider.BlockStore interface and uses a
// VolumeSnapshotterGRPCClient implements the cloudprovider.VolumeSnapshotter interface and uses a
// gRPC client to make calls to the plugin server.
type BlockStoreGRPCClient struct {
type VolumeSnapshotterGRPCClient struct {
*clientBase
grpcClient proto.BlockStoreClient
grpcClient proto.VolumeSnapshotterClient
}
func newBlockStoreGRPCClient(base *clientBase, clientConn *grpc.ClientConn) interface{} {
return &BlockStoreGRPCClient{
func newVolumeSnapshotterGRPCClient(base *clientBase, clientConn *grpc.ClientConn) interface{} {
return &VolumeSnapshotterGRPCClient{
clientBase: base,
grpcClient: proto.NewBlockStoreClient(clientConn),
grpcClient: proto.NewVolumeSnapshotterClient(clientConn),
}
}
// Init prepares the BlockStore for usage using the provided map of
// configuration key-value pairs. It returns an error if the BlockStore
// Init prepares the VolumeSnapshotter for usage using the provided map of
// configuration key-value pairs. It returns an error if the VolumeSnapshotter
// cannot be initialized from the provided config.
func (c *BlockStoreGRPCClient) Init(config map[string]string) error {
func (c *VolumeSnapshotterGRPCClient) Init(config map[string]string) error {
req := &proto.InitRequest{
Plugin: c.plugin,
Config: config,
@@ -67,7 +67,7 @@ func (c *BlockStoreGRPCClient) Init(config map[string]string) error {
// CreateVolumeFromSnapshot creates a new block volume, initialized from the provided snapshot,
// and with the specified type and IOPS (if using provisioned IOPS).
func (c *BlockStoreGRPCClient) CreateVolumeFromSnapshot(snapshotID, volumeType, volumeAZ string, iops *int64) (string, error) {
func (c *VolumeSnapshotterGRPCClient) CreateVolumeFromSnapshot(snapshotID, volumeType, volumeAZ string, iops *int64) (string, error) {
req := &proto.CreateVolumeRequest{
Plugin: c.plugin,
SnapshotID: snapshotID,
@@ -91,7 +91,7 @@ func (c *BlockStoreGRPCClient) CreateVolumeFromSnapshot(snapshotID, volumeType,
// GetVolumeInfo returns the type and IOPS (if using provisioned IOPS) for a specified block
// volume.
func (c *BlockStoreGRPCClient) GetVolumeInfo(volumeID, volumeAZ string) (string, *int64, error) {
func (c *VolumeSnapshotterGRPCClient) GetVolumeInfo(volumeID, volumeAZ string) (string, *int64, error) {
req := &proto.GetVolumeInfoRequest{
Plugin: c.plugin,
VolumeID: volumeID,
@@ -113,7 +113,7 @@ func (c *BlockStoreGRPCClient) GetVolumeInfo(volumeID, volumeAZ string) (string,
// CreateSnapshot creates a snapshot of the specified block volume, and applies the provided
// set of tags to the snapshot.
func (c *BlockStoreGRPCClient) CreateSnapshot(volumeID, volumeAZ string, tags map[string]string) (string, error) {
func (c *VolumeSnapshotterGRPCClient) CreateSnapshot(volumeID, volumeAZ string, tags map[string]string) (string, error) {
req := &proto.CreateSnapshotRequest{
Plugin: c.plugin,
VolumeID: volumeID,
@@ -130,7 +130,7 @@ func (c *BlockStoreGRPCClient) CreateSnapshot(volumeID, volumeAZ string, tags ma
}
// DeleteSnapshot deletes the specified volume snapshot.
func (c *BlockStoreGRPCClient) DeleteSnapshot(snapshotID string) error {
func (c *VolumeSnapshotterGRPCClient) DeleteSnapshot(snapshotID string) error {
req := &proto.DeleteSnapshotRequest{
Plugin: c.plugin,
SnapshotID: snapshotID,
@@ -143,7 +143,7 @@ func (c *BlockStoreGRPCClient) DeleteSnapshot(snapshotID string) error {
return nil
}
func (c *BlockStoreGRPCClient) GetVolumeID(pv runtime.Unstructured) (string, error) {
func (c *VolumeSnapshotterGRPCClient) GetVolumeID(pv runtime.Unstructured) (string, error) {
encodedPV, err := json.Marshal(pv.UnstructuredContent())
if err != nil {
return "", errors.WithStack(err)
@@ -162,7 +162,7 @@ func (c *BlockStoreGRPCClient) GetVolumeID(pv runtime.Unstructured) (string, err
return resp.VolumeID, nil
}
func (c *BlockStoreGRPCClient) SetVolumeID(pv runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
func (c *VolumeSnapshotterGRPCClient) SetVolumeID(pv runtime.Unstructured, volumeID string) (runtime.Unstructured, error) {
encodedPV, err := json.Marshal(pv.UnstructuredContent())
if err != nil {
return nil, errors.WithStack(err)

View File

@@ -27,30 +27,30 @@ import (
"github.com/heptio/velero/pkg/plugin/velero"
)
// BlockStoreGRPCServer implements the proto-generated BlockStoreServer interface, and accepts
// VolumeSnapshotterGRPCServer implements the proto-generated VolumeSnapshotterServer interface, and accepts
// gRPC calls and forwards them to an implementation of the pluggable interface.
type BlockStoreGRPCServer struct {
type VolumeSnapshotterGRPCServer struct {
mux *serverMux
}
func (s *BlockStoreGRPCServer) getImpl(name string) (velero.BlockStore, error) {
func (s *VolumeSnapshotterGRPCServer) getImpl(name string) (velero.VolumeSnapshotter, error) {
impl, err := s.mux.getHandler(name)
if err != nil {
return nil, err
}
blockStore, ok := impl.(velero.BlockStore)
volumeSnapshotter, ok := impl.(velero.VolumeSnapshotter)
if !ok {
return nil, errors.Errorf("%T is not a block store", impl)
return nil, errors.Errorf("%T is not a volume snapshotter", impl)
}
return blockStore, nil
return volumeSnapshotter, nil
}
// Init prepares the BlockStore for usage using the provided map of
// configuration key-value pairs. It returns an error if the BlockStore
// Init prepares the VolumeSnapshotter for usage using the provided map of
// configuration key-value pairs. It returns an error if the VolumeSnapshotter
// cannot be initialized from the provided config.
func (s *BlockStoreGRPCServer) Init(ctx context.Context, req *proto.InitRequest) (response *proto.Empty, err error) {
func (s *VolumeSnapshotterGRPCServer) Init(ctx context.Context, req *proto.InitRequest) (response *proto.Empty, err error) {
defer func() {
if recoveredErr := handlePanic(recover()); recoveredErr != nil {
err = recoveredErr
@@ -71,7 +71,7 @@ func (s *BlockStoreGRPCServer) Init(ctx context.Context, req *proto.InitRequest)
// CreateVolumeFromSnapshot creates a new block volume, initialized from the provided snapshot,
// and with the specified type and IOPS (if using provisioned IOPS).
func (s *BlockStoreGRPCServer) CreateVolumeFromSnapshot(ctx context.Context, req *proto.CreateVolumeRequest) (response *proto.CreateVolumeResponse, err error) {
func (s *VolumeSnapshotterGRPCServer) CreateVolumeFromSnapshot(ctx context.Context, req *proto.CreateVolumeRequest) (response *proto.CreateVolumeResponse, err error) {
defer func() {
if recoveredErr := handlePanic(recover()); recoveredErr != nil {
err = recoveredErr
@@ -102,7 +102,7 @@ func (s *BlockStoreGRPCServer) CreateVolumeFromSnapshot(ctx context.Context, req
// GetVolumeInfo returns the type and IOPS (if using provisioned IOPS) for a specified block
// volume.
func (s *BlockStoreGRPCServer) GetVolumeInfo(ctx context.Context, req *proto.GetVolumeInfoRequest) (response *proto.GetVolumeInfoResponse, err error) {
func (s *VolumeSnapshotterGRPCServer) GetVolumeInfo(ctx context.Context, req *proto.GetVolumeInfoRequest) (response *proto.GetVolumeInfoResponse, err error) {
defer func() {
if recoveredErr := handlePanic(recover()); recoveredErr != nil {
err = recoveredErr
@@ -132,7 +132,7 @@ func (s *BlockStoreGRPCServer) GetVolumeInfo(ctx context.Context, req *proto.Get
// CreateSnapshot creates a snapshot of the specified block volume, and applies the provided
// set of tags to the snapshot.
func (s *BlockStoreGRPCServer) CreateSnapshot(ctx context.Context, req *proto.CreateSnapshotRequest) (response *proto.CreateSnapshotResponse, err error) {
func (s *VolumeSnapshotterGRPCServer) CreateSnapshot(ctx context.Context, req *proto.CreateSnapshotRequest) (response *proto.CreateSnapshotResponse, err error) {
defer func() {
if recoveredErr := handlePanic(recover()); recoveredErr != nil {
err = recoveredErr
@@ -153,7 +153,7 @@ func (s *BlockStoreGRPCServer) CreateSnapshot(ctx context.Context, req *proto.Cr
}
// DeleteSnapshot deletes the specified volume snapshot.
func (s *BlockStoreGRPCServer) DeleteSnapshot(ctx context.Context, req *proto.DeleteSnapshotRequest) (response *proto.Empty, err error) {
func (s *VolumeSnapshotterGRPCServer) DeleteSnapshot(ctx context.Context, req *proto.DeleteSnapshotRequest) (response *proto.Empty, err error) {
defer func() {
if recoveredErr := handlePanic(recover()); recoveredErr != nil {
err = recoveredErr
@@ -172,7 +172,7 @@ func (s *BlockStoreGRPCServer) DeleteSnapshot(ctx context.Context, req *proto.De
return &proto.Empty{}, nil
}
func (s *BlockStoreGRPCServer) GetVolumeID(ctx context.Context, req *proto.GetVolumeIDRequest) (response *proto.GetVolumeIDResponse, err error) {
func (s *VolumeSnapshotterGRPCServer) GetVolumeID(ctx context.Context, req *proto.GetVolumeIDRequest) (response *proto.GetVolumeIDResponse, err error) {
defer func() {
if recoveredErr := handlePanic(recover()); recoveredErr != nil {
err = recoveredErr
@@ -198,7 +198,7 @@ func (s *BlockStoreGRPCServer) GetVolumeID(ctx context.Context, req *proto.GetVo
return &proto.GetVolumeIDResponse{VolumeID: volumeID}, nil
}
func (s *BlockStoreGRPCServer) SetVolumeID(ctx context.Context, req *proto.SetVolumeIDRequest) (response *proto.SetVolumeIDResponse, err error) {
func (s *VolumeSnapshotterGRPCServer) SetVolumeID(ctx context.Context, req *proto.SetVolumeIDRequest) (response *proto.SetVolumeIDResponse, err error) {
defer func() {
if recoveredErr := handlePanic(recover()); recoveredErr != nil {
err = recoveredErr