migrate backup actions to plugins

Signed-off-by: Steve Kriss <steve@heptio.com>
This commit is contained in:
Steve Kriss
2017-11-21 10:03:03 -08:00
parent 2ce15de2f8
commit 0f2d1ab82b
27 changed files with 1817 additions and 678 deletions
+32 -12
View File
@@ -18,8 +18,10 @@ package plugin
import (
plugin "github.com/hashicorp/go-plugin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/heptio/ark/pkg/backup"
"github.com/heptio/ark/pkg/cloudprovider"
"github.com/heptio/ark/pkg/cloudprovider/aws"
"github.com/heptio/ark/pkg/cloudprovider/azure"
@@ -42,6 +44,10 @@ func NewCommand() *cobra.Command {
"azure": azure.NewBlockStore(),
}
backupActions := map[string]backup.ItemAction{
"backup_pv": backup.NewBackupPVAction(logger),
}
c := &cobra.Command{
Use: "plugin [KIND] [NAME]",
Hidden: true,
@@ -54,31 +60,45 @@ func NewCommand() *cobra.Command {
kind := args[0]
name := args[1]
logger.Debugf("Running plugin command for kind=%s, name=%s", kind, name)
logger = logger.WithFields(logrus.Fields{"kind": kind, "name": name})
serveConfig := &plugin.ServeConfig{
HandshakeConfig: arkplugin.Handshake,
GRPCServer: plugin.DefaultGRPCServer,
}
logger.Debugf("Running plugin command")
switch kind {
case "cloudprovider":
objectStore, found := objectStores[name]
if !found {
logger.Fatalf("Unrecognized plugin name %q", name)
logger.Fatalf("Unrecognized plugin name")
}
blockStore, found := blockStores[name]
if !found {
logger.Fatalf("Unrecognized plugin name %q", name)
logger.Fatalf("Unrecognized plugin name")
}
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: arkplugin.Handshake,
Plugins: map[string]plugin.Plugin{
string(arkplugin.PluginKindObjectStore): arkplugin.NewObjectStorePlugin(objectStore),
string(arkplugin.PluginKindBlockStore): arkplugin.NewBlockStorePlugin(blockStore),
},
GRPCServer: plugin.DefaultGRPCServer,
})
serveConfig.Plugins = map[string]plugin.Plugin{
string(arkplugin.PluginKindObjectStore): arkplugin.NewObjectStorePlugin(objectStore),
string(arkplugin.PluginKindBlockStore): arkplugin.NewBlockStorePlugin(blockStore),
}
case arkplugin.PluginKindBackupItemAction.String():
action, found := backupActions[name]
if !found {
logger.Fatalf("Unrecognized plugin name")
}
serveConfig.Plugins = map[string]plugin.Plugin{
arkplugin.PluginKindBackupItemAction.String(): arkplugin.NewBackupItemActionPlugin(action),
}
default:
logger.Fatalf("Unsupported plugin kind %q", kind)
logger.Fatalf("Unsupported plugin kind")
}
plugin.Serve(serveConfig)
},
}
+9 -16
View File
@@ -162,6 +162,11 @@ func newServer(kubeconfig, baseName string, logger *logrus.Logger) (*server, err
return nil, errors.WithStack(err)
}
pluginManager, err := plugin.NewManager(logger, logger.Level)
if err != nil {
return nil, err
}
ctx, cancelFunc := context.WithCancel(context.Background())
s := &server{
@@ -174,7 +179,7 @@ func newServer(kubeconfig, baseName string, logger *logrus.Logger) (*server, err
ctx: ctx,
cancelFunc: cancelFunc,
logger: logger,
pluginManager: plugin.NewManager(logger, logger.Level),
pluginManager: pluginManager,
}
return s, nil
@@ -444,6 +449,7 @@ func (s *server) runControllers(config *api.Config) error {
config.BackupStorageProvider.Bucket,
s.snapshotService != nil,
s.logger,
s.pluginManager,
)
wg.Add(1)
go func() {
@@ -545,24 +551,11 @@ func newBackupper(
kubeClientConfig *rest.Config,
kubeCoreV1Client kcorev1client.CoreV1Interface,
) (backup.Backupper, error) {
actions := map[string]backup.Action{}
dynamicFactory := client.NewDynamicFactory(clientPool)
if snapshotService != nil {
action, err := backup.NewVolumeSnapshotAction(snapshotService)
if err != nil {
return nil, err
}
actions["persistentvolumes"] = action
actions["persistentvolumeclaims"] = backup.NewBackupPVAction()
}
return backup.NewKubernetesBackupper(
discoveryHelper,
dynamicFactory,
actions,
client.NewDynamicFactory(clientPool),
backup.NewPodCommandExecutor(kubeClientConfig, kubeCoreV1Client.RESTClient()),
snapshotService,
)
}