kubectl: use the factory properly for recording commands

This commit is contained in:
Michail Kargakis 2016-02-16 18:17:47 +01:00
parent ea0b040e81
commit 55f402c5a6

View File

@ -26,6 +26,7 @@ import (
"os" "os"
"os/user" "os/user"
"path" "path"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -63,7 +64,6 @@ const (
type Factory struct { type Factory struct {
clients *ClientCache clients *ClientCache
flags *pflag.FlagSet flags *pflag.FlagSet
cmd string
// Returns interfaces for dealing with arbitrary runtime.Objects. // Returns interfaces for dealing with arbitrary runtime.Objects.
Object func() (meta.RESTMapper, runtime.ObjectTyper) Object func() (meta.RESTMapper, runtime.ObjectTyper)
@ -190,7 +190,6 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return &Factory{ return &Factory{
clients: clients, clients: clients,
flags: flags, flags: flags,
cmd: recordCommand(os.Args),
Object: func() (meta.RESTMapper, runtime.ObjectTyper) { Object: func() (meta.RESTMapper, runtime.ObjectTyper) {
cfg, err := clientConfig.ClientConfig() cfg, err := clientConfig.ClientConfig()
@ -547,15 +546,16 @@ func GetFirstPod(client *client.Client, namespace string, selector labels.Select
return pod, nil return pod, nil
} }
func recordCommand(args []string) string { // Command will stringify and return all environment arguments ie. a command run by a client
if len(args) > 0 { // using the factory.
args[0] = "kubectl" // TODO: We need to filter out stuff like secrets.
}
return strings.Join(args, " ")
}
func (f *Factory) Command() string { func (f *Factory) Command() string {
return f.cmd if len(os.Args) == 0 {
return ""
}
base := filepath.Base(os.Args[0])
args := append([]string{base}, os.Args[1:]...)
return strings.Join(args, " ")
} }
// BindFlags adds any flags that are common to all kubectl sub commands. // BindFlags adds any flags that are common to all kubectl sub commands.