mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 10:33:35 +00:00
vendor update for CSI 0.3.0
This commit is contained in:
45
vendor/k8s.io/kubernetes/pkg/kubectl/cmd/plugin.go
generated
vendored
45
vendor/k8s.io/kubernetes/pkg/kubectl/cmd/plugin.go
generated
vendored
@ -18,7 +18,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
@ -28,6 +27,7 @@ import (
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||
"k8s.io/kubernetes/pkg/kubectl/plugins"
|
||||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||
)
|
||||
@ -42,9 +42,9 @@ var (
|
||||
)
|
||||
|
||||
// NewCmdPlugin creates the command that is the top-level for plugin commands.
|
||||
func NewCmdPlugin(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Command {
|
||||
func NewCmdPlugin(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
|
||||
// Loads plugins and create commands for each plugin identified
|
||||
loadedPlugins, loadErr := f.PluginLoader().Load()
|
||||
loadedPlugins, loadErr := pluginLoader().Load()
|
||||
if loadErr != nil {
|
||||
glog.V(1).Infof("Unable to load plugins: %v", loadErr)
|
||||
}
|
||||
@ -58,14 +58,14 @@ func NewCmdPlugin(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Co
|
||||
if len(loadedPlugins) == 0 {
|
||||
cmdutil.CheckErr(fmt.Errorf("no plugins installed."))
|
||||
}
|
||||
cmdutil.DefaultSubCommandRun(err)(cmd, args)
|
||||
cmdutil.DefaultSubCommandRun(streams.ErrOut)(cmd, args)
|
||||
},
|
||||
}
|
||||
|
||||
if len(loadedPlugins) > 0 {
|
||||
pluginRunner := f.PluginRunner()
|
||||
pluginRunner := pluginRunner()
|
||||
for _, p := range loadedPlugins {
|
||||
cmd.AddCommand(NewCmdForPlugin(f, p, pluginRunner, in, out, err))
|
||||
cmd.AddCommand(NewCmdForPlugin(f, p, pluginRunner, streams))
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ func NewCmdPlugin(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Co
|
||||
}
|
||||
|
||||
// NewCmdForPlugin creates a command capable of running the provided plugin.
|
||||
func NewCmdForPlugin(f cmdutil.Factory, plugin *plugins.Plugin, runner plugins.PluginRunner, in io.Reader, out, errout io.Writer) *cobra.Command {
|
||||
func NewCmdForPlugin(f cmdutil.Factory, plugin *plugins.Plugin, runner plugins.PluginRunner, streams genericclioptions.IOStreams) *cobra.Command {
|
||||
if !plugin.IsValid() {
|
||||
return nil
|
||||
}
|
||||
@ -85,7 +85,7 @@ func NewCmdForPlugin(f cmdutil.Factory, plugin *plugins.Plugin, runner plugins.P
|
||||
Example: templates.Examples(plugin.Example),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(plugin.Command) == 0 {
|
||||
cmdutil.DefaultSubCommandRun(errout)(cmd, args)
|
||||
cmdutil.DefaultSubCommandRun(streams.ErrOut)(cmd, args)
|
||||
return
|
||||
}
|
||||
|
||||
@ -104,9 +104,7 @@ func NewCmdForPlugin(f cmdutil.Factory, plugin *plugins.Plugin, runner plugins.P
|
||||
}
|
||||
|
||||
runningContext := plugins.RunningContext{
|
||||
In: in,
|
||||
Out: out,
|
||||
ErrOut: errout,
|
||||
IOStreams: streams,
|
||||
Args: args,
|
||||
EnvProvider: envProvider,
|
||||
WorkingDir: plugin.Dir,
|
||||
@ -117,7 +115,7 @@ func NewCmdForPlugin(f cmdutil.Factory, plugin *plugins.Plugin, runner plugins.P
|
||||
// check for (and exit with) the correct exit code
|
||||
// from a failed plugin command execution
|
||||
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
|
||||
fmt.Fprintf(errout, "error: %v\n", err)
|
||||
fmt.Fprintf(streams.ErrOut, "error: %v\n", err)
|
||||
os.Exit(status.ExitStatus())
|
||||
}
|
||||
}
|
||||
@ -132,7 +130,7 @@ func NewCmdForPlugin(f cmdutil.Factory, plugin *plugins.Plugin, runner plugins.P
|
||||
}
|
||||
|
||||
for _, childPlugin := range plugin.Tree {
|
||||
cmd.AddCommand(NewCmdForPlugin(f, childPlugin, runner, in, out, errout))
|
||||
cmd.AddCommand(NewCmdForPlugin(f, childPlugin, runner, streams))
|
||||
}
|
||||
|
||||
return cmd
|
||||
@ -160,7 +158,7 @@ type factoryAttrsPluginEnvProvider struct {
|
||||
}
|
||||
|
||||
func (p *factoryAttrsPluginEnvProvider) Env() (plugins.EnvList, error) {
|
||||
cmdNamespace, _, err := p.factory.DefaultNamespace()
|
||||
cmdNamespace, _, err := p.factory.ToRawKubeConfigLoader().Namespace()
|
||||
if err != nil {
|
||||
return plugins.EnvList{}, err
|
||||
}
|
||||
@ -168,3 +166,22 @@ func (p *factoryAttrsPluginEnvProvider) Env() (plugins.EnvList, error) {
|
||||
plugins.Env{N: "KUBECTL_PLUGINS_CURRENT_NAMESPACE", V: cmdNamespace},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// pluginLoader loads plugins from a path set by the KUBECTL_PLUGINS_PATH env var.
|
||||
// If this env var is not set, it defaults to
|
||||
// "~/.kube/plugins", plus
|
||||
// "./kubectl/plugins" directory under the "data dir" directory specified by the XDG
|
||||
// system directory structure spec for the given platform.
|
||||
func pluginLoader() plugins.PluginLoader {
|
||||
if len(os.Getenv("KUBECTL_PLUGINS_PATH")) > 0 {
|
||||
return plugins.KubectlPluginsPathPluginLoader()
|
||||
}
|
||||
return plugins.TolerantMultiPluginLoader{
|
||||
plugins.XDGDataDirsPluginLoader(),
|
||||
plugins.UserDirPluginLoader(),
|
||||
}
|
||||
}
|
||||
|
||||
func pluginRunner() plugins.PluginRunner {
|
||||
return &plugins.ExecPluginRunner{}
|
||||
}
|
||||
|
Reference in New Issue
Block a user