Skip to content

Commit

Permalink
Set plugin process log level to match ark server
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Goldstein <andy.goldstein@gmail.com>
  • Loading branch information
ncdc committed Jul 5, 2018
1 parent a70456f commit d1cd91d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
11 changes: 10 additions & 1 deletion pkg/cmd/server/plugin/plugin.go
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package plugin

import (
"fmt"
"strings"

plugin "github.com/hashicorp/go-plugin"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -30,17 +33,21 @@ import (
"github.com/heptio/ark/pkg/cmd"
arkplugin "github.com/heptio/ark/pkg/plugin"
"github.com/heptio/ark/pkg/restore"
"github.com/heptio/ark/pkg/util/logging"
)

func NewCommand(f client.Factory) *cobra.Command {
logger := arkplugin.NewLogger()
logLevelFlag := logging.LogLevelFlag(logrus.InfoLevel)

c := &cobra.Command{
Use: "run-plugin [KIND] [NAME]",
Hidden: true,
Short: "INTERNAL COMMAND ONLY - not intended to be run directly by users",
Args: cobra.ExactArgs(2),
Run: func(c *cobra.Command, args []string) {
logLevel := logLevelFlag.Parse()
logger := arkplugin.NewLogger(logLevel)

kind := args[0]
name := args[1]

Expand Down Expand Up @@ -123,5 +130,7 @@ func NewCommand(f client.Factory) *cobra.Command {
},
}

c.Flags().Var(logLevelFlag, "log-level", fmt.Sprintf("the level at which to log. Valid values are %s.", strings.Join(logLevelFlag.AllowedValues(), ", ")))

return c
}
4 changes: 3 additions & 1 deletion pkg/plugin/logger.go
Expand Up @@ -24,8 +24,10 @@ import (

// NewLogger returns a logger that is suitable for use within an
// Ark plugin.
func NewLogger() logrus.FieldLogger {
func NewLogger(level logrus.Level) logrus.FieldLogger {
logger := logrus.New()
logger.Level = level

/*
!!!DO NOT SET THE OUTPUT TO STDOUT!!!
Expand Down
18 changes: 9 additions & 9 deletions pkg/plugin/manager.go
Expand Up @@ -184,16 +184,16 @@ func (m *manager) registerPlugins() error {

// first, register internal plugins
for _, provider := range []string{"aws", "gcp", "azure"} {
m.pluginRegistry.register(provider, arkCommand, []string{"run-plugin", "cloudprovider", provider}, PluginKindObjectStore, PluginKindBlockStore)
m.pluginRegistry.register(provider, arkCommand, []string{"run-plugin", "cloudprovider", provider, "--log-level", m.logLevel.String()}, PluginKindObjectStore, PluginKindBlockStore)
}
m.pluginRegistry.register("pv", arkCommand, []string{"run-plugin", string(PluginKindBackupItemAction), "pv"}, PluginKindBackupItemAction)
m.pluginRegistry.register("backup-pod", arkCommand, []string{"run-plugin", string(PluginKindBackupItemAction), "pod"}, PluginKindBackupItemAction)
m.pluginRegistry.register("serviceaccount", arkCommand, []string{"run-plugin", string(PluginKindBackupItemAction), "serviceaccount"}, PluginKindBackupItemAction)

m.pluginRegistry.register("job", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "job"}, PluginKindRestoreItemAction)
m.pluginRegistry.register("restore-pod", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "pod"}, PluginKindRestoreItemAction)
m.pluginRegistry.register("svc", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "svc"}, PluginKindRestoreItemAction)
m.pluginRegistry.register("restic", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "restic"}, PluginKindRestoreItemAction)
m.pluginRegistry.register("pv", arkCommand, []string{"run-plugin", string(PluginKindBackupItemAction), "pv", "--log-level", m.logLevel.String()}, PluginKindBackupItemAction)
m.pluginRegistry.register("backup-pod", arkCommand, []string{"run-plugin", string(PluginKindBackupItemAction), "pod", "--log-level", m.logLevel.String()}, PluginKindBackupItemAction)
m.pluginRegistry.register("serviceaccount", arkCommand, []string{"run-plugin", string(PluginKindBackupItemAction), "serviceaccount", "--log-level", m.logLevel.String()}, PluginKindBackupItemAction)

m.pluginRegistry.register("job", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "job", "--log-level", m.logLevel.String()}, PluginKindRestoreItemAction)
m.pluginRegistry.register("restore-pod", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "pod", "--log-level", m.logLevel.String()}, PluginKindRestoreItemAction)
m.pluginRegistry.register("svc", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "svc", "--log-level", m.logLevel.String()}, PluginKindRestoreItemAction)
m.pluginRegistry.register("restic", arkCommand, []string{"run-plugin", string(PluginKindRestoreItemAction), "restic", "--log-level", m.logLevel.String()}, PluginKindRestoreItemAction)

// second, register external plugins (these will override internal plugins, if applicable)
if _, err := os.Stat(m.pluginDir); err != nil {
Expand Down

0 comments on commit d1cd91d

Please sign in to comment.