Refactor BackupItemAction to backupitemaction/v1

Signed-off-by: Hoang, Phuong <phuong.n.hoang@dell.com>
This commit is contained in:
Hoang, Phuong
2022-08-25 17:10:09 -04:00
committed by Scott Seago
parent e8494418d4
commit b54424bdc6
27 changed files with 259 additions and 492 deletions
+6 -6
View File
@@ -22,10 +22,10 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
isv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/item_snapshotter/v1"
"github.com/vmware-tanzu/velero/pkg/discovery"
"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"
"github.com/vmware-tanzu/velero/pkg/util/collections"
)
@@ -98,11 +98,11 @@ func resolveAction(helper discovery.Helper, action velero.Applicable) (resources
}
type BackupItemResolvedAction struct {
velero.BackupItemAction
biav1.BackupItemAction
resolvedAction
}
func NewBackupItemActionResolver(actions []velero.BackupItemAction) BackupItemActionResolver {
func NewBackupItemActionResolver(actions []biav1.BackupItemAction) BackupItemActionResolver {
return BackupItemActionResolver{
actions: actions,
}
@@ -131,7 +131,7 @@ type ActionResolver interface {
}
type BackupItemActionResolver struct {
actions []velero.BackupItemAction
actions []biav1.BackupItemAction
}
func (recv BackupItemActionResolver) ResolveActions(helper discovery.Helper) ([]BackupItemResolvedAction, error) {
+2 -2
View File
@@ -21,7 +21,7 @@ import (
"golang.org/x/net/context"
"google.golang.org/grpc"
proto "github.com/vmware-tanzu/velero/pkg/plugin/generated"
protobiav1 "github.com/vmware-tanzu/velero/pkg/plugin/generated/backupitemaction/v1"
)
// BackupItemActionPlugin is an implementation of go-plugin's Plugin
@@ -39,6 +39,6 @@ func (p *BackupItemActionPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBro
// GRPCServer registers a BackupItemAction gRPC server.
func (p *BackupItemActionPlugin) GRPCServer(_ *plugin.GRPCBroker, server *grpc.Server) error {
proto.RegisterBackupItemActionServer(server, &BackupItemActionGRPCServer{mux: p.serverMux})
protobiav1.RegisterBackupItemActionServer(server, &BackupItemActionGRPCServer{mux: p.serverMux})
return nil
}
@@ -27,7 +27,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
proto "github.com/vmware-tanzu/velero/pkg/plugin/generated"
protobiav1 "github.com/vmware-tanzu/velero/pkg/plugin/generated/backupitemaction/v1"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
)
@@ -42,18 +42,18 @@ func NewBackupItemActionPlugin(options ...PluginOption) *BackupItemActionPlugin
// gRPC client to make calls to the plugin server.
type BackupItemActionGRPCClient struct {
*clientBase
grpcClient proto.BackupItemActionClient
grpcClient protobiav1.BackupItemActionClient
}
func newBackupItemActionGRPCClient(base *clientBase, clientConn *grpc.ClientConn) interface{} {
return &BackupItemActionGRPCClient{
clientBase: base,
grpcClient: proto.NewBackupItemActionClient(clientConn),
grpcClient: protobiav1.NewBackupItemActionClient(clientConn),
}
}
func (c *BackupItemActionGRPCClient) AppliesTo() (velero.ResourceSelector, error) {
req := &proto.BackupItemActionAppliesToRequest{
req := &protobiav1.BackupItemActionAppliesToRequest{
Plugin: c.plugin,
}
@@ -86,7 +86,7 @@ func (c *BackupItemActionGRPCClient) Execute(item runtime.Unstructured, backup *
return nil, nil, errors.WithStack(err)
}
req := &proto.ExecuteRequest{
req := &protobiav1.ExecuteRequest{
Plugin: c.plugin,
Item: itemJSON,
Backup: backupJSON,
@@ -25,7 +25,9 @@ import (
api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
proto "github.com/vmware-tanzu/velero/pkg/plugin/generated"
protobiav1 "github.com/vmware-tanzu/velero/pkg/plugin/generated/backupitemaction/v1"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
biav1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/backupitemaction/v1"
)
// BackupItemActionGRPCServer implements the proto-generated BackupItemAction interface, and accepts
@@ -34,13 +36,13 @@ type BackupItemActionGRPCServer struct {
mux *serverMux
}
func (s *BackupItemActionGRPCServer) getImpl(name string) (velero.BackupItemAction, error) {
func (s *BackupItemActionGRPCServer) getImpl(name string) (biav1.BackupItemAction, error) {
impl, err := s.mux.getHandler(name)
if err != nil {
return nil, err
}
itemAction, ok := impl.(velero.BackupItemAction)
itemAction, ok := impl.(biav1.BackupItemAction)
if !ok {
return nil, errors.Errorf("%T is not a backup item action", impl)
}
@@ -48,7 +50,9 @@ func (s *BackupItemActionGRPCServer) getImpl(name string) (velero.BackupItemActi
return itemAction, nil
}
func (s *BackupItemActionGRPCServer) AppliesTo(ctx context.Context, req *proto.BackupItemActionAppliesToRequest) (response *proto.BackupItemActionAppliesToResponse, err error) {
func (s *BackupItemActionGRPCServer) AppliesTo(
ctx context.Context, req *protobiav1.BackupItemActionAppliesToRequest) (
response *protobiav1.BackupItemActionAppliesToResponse, err error) {
defer func() {
if recoveredErr := handlePanic(recover()); recoveredErr != nil {
err = recoveredErr
@@ -65,7 +69,7 @@ func (s *BackupItemActionGRPCServer) AppliesTo(ctx context.Context, req *proto.B
return nil, newGRPCError(err)
}
return &proto.BackupItemActionAppliesToResponse{
return &protobiav1.BackupItemActionAppliesToResponse{
&proto.ResourceSelector{
IncludedNamespaces: resourceSelector.IncludedNamespaces,
ExcludedNamespaces: resourceSelector.ExcludedNamespaces,
@@ -76,7 +80,8 @@ func (s *BackupItemActionGRPCServer) AppliesTo(ctx context.Context, req *proto.B
}, nil
}
func (s *BackupItemActionGRPCServer) Execute(ctx context.Context, req *proto.ExecuteRequest) (response *proto.ExecuteResponse, err error) {
func (s *BackupItemActionGRPCServer) Execute(
ctx context.Context, req *protobiav1.ExecuteRequest) (response *protobiav1.ExecuteResponse, err error) {
defer func() {
if recoveredErr := handlePanic(recover()); recoveredErr != nil {
err = recoveredErr
@@ -115,7 +120,7 @@ func (s *BackupItemActionGRPCServer) Execute(ctx context.Context, req *proto.Exe
}
}
res := &proto.ExecuteResponse{
res := &protobiav1.ExecuteResponse{
Item: updatedItemJSON,
}
@@ -31,6 +31,7 @@ import (
v1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"github.com/vmware-tanzu/velero/pkg/backup/mocks"
proto "github.com/vmware-tanzu/velero/pkg/plugin/generated"
protobiav1 "github.com/vmware-tanzu/velero/pkg/plugin/generated/backupitemaction/v1"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
velerotest "github.com/vmware-tanzu/velero/pkg/test"
)
@@ -160,7 +161,7 @@ func TestBackupItemActionGRPCServerExecute(t *testing.T) {
},
}}
req := &proto.ExecuteRequest{
req := &protobiav1.ExecuteRequest{
Plugin: "xyz",
Item: test.item,
Backup: test.backup,
@@ -21,14 +21,13 @@ import (
"encoding/json"
"time"
isv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/item_snapshotter/v1"
"github.com/pkg/errors"
"google.golang.org/grpc"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
proto "github.com/vmware-tanzu/velero/pkg/plugin/generated"
"github.com/vmware-tanzu/velero/pkg/plugin/velero"
isv1 "github.com/vmware-tanzu/velero/pkg/plugin/velero/item_snapshotter/v1"
)
// NewItemSnapshotterPlugin constructs a ItemSnapshotterPlugin.