Commit 95354490 authored by k8s-merge-robot's avatar k8s-merge-robot

Merge pull request #21318 from kargakis/record-command-factory-method-tweak

Auto commit by PR queue bot
parents 2c3b3d57 55f402c5
......@@ -26,6 +26,7 @@ import (
"os"
"os/user"
"path"
"path/filepath"
"strconv"
"strings"
"time"
......@@ -65,7 +66,6 @@ const (
type Factory struct {
clients *ClientCache
flags *pflag.FlagSet
cmd string
// Returns interfaces for dealing with arbitrary runtime.Objects.
Object func() (meta.RESTMapper, runtime.ObjectTyper)
......@@ -193,7 +193,6 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return &Factory{
clients: clients,
flags: flags,
cmd: recordCommand(os.Args),
Object: func() (meta.RESTMapper, runtime.ObjectTyper) {
cfg, err := clientConfig.ClientConfig()
......@@ -554,17 +553,18 @@ func GetFirstPod(client *client.Client, namespace string, selector labels.Select
return pod, nil
}
func recordCommand(args []string) string {
if len(args) > 0 {
args[0] = "kubectl"
// Command will stringify and return all environment arguments ie. a command run by a client
// using the factory.
// TODO: We need to filter out stuff like secrets.
func (f *Factory) Command() string {
if len(os.Args) == 0 {
return ""
}
base := filepath.Base(os.Args[0])
args := append([]string{base}, os.Args[1:]...)
return strings.Join(args, " ")
}
func (f *Factory) Command() string {
return f.cmd
}
// BindFlags adds any flags that are common to all kubectl sub commands.
func (f *Factory) BindFlags(flags *pflag.FlagSet) {
// any flags defined by external projects (not part of pflags)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment