Merge pull request #17702 from hurf/logs_cleanup

Auto commit by PR queue bot
pull/6/head
k8s-merge-robot 2015-11-26 19:13:12 -08:00
commit b9537245ec
3 changed files with 14 additions and 14 deletions

View File

@ -157,7 +157,7 @@ Find more information at https://github.com/kubernetes/kubernetes.`,
cmds.AddCommand(NewCmdApply(f, out))
cmds.AddCommand(NewCmdNamespace(out))
cmds.AddCommand(NewCmdLog(f, out))
cmds.AddCommand(NewCmdLogs(f, out))
cmds.AddCommand(NewCmdRollingUpdate(f, out))
cmds.AddCommand(NewCmdScale(f, out))

View File

@ -35,7 +35,7 @@ import (
)
const (
log_example = `# Return snapshot logs from pod nginx with only one container
logs_example = `# Return snapshot logs from pod nginx with only one container
$ kubectl logs nginx
# Return snapshot of previous terminated ruby container logs from pod web-1
@ -65,14 +65,14 @@ type LogsOptions struct {
Out io.Writer
}
// NewCmdLog creates a new pod log command
func NewCmdLog(f *cmdutil.Factory, out io.Writer) *cobra.Command {
// NewCmdLog creates a new pod logs command
func NewCmdLogs(f *cmdutil.Factory, out io.Writer) *cobra.Command {
o := &LogsOptions{}
cmd := &cobra.Command{
Use: "logs [-f] [-p] POD [-c CONTAINER]",
Short: "Print the logs for a container in a pod.",
Long: "Print the logs for a container in a pod. If the pod has only one container, the container name is optional.",
Example: log_example,
Example: logs_example,
PreRun: func(cmd *cobra.Command, args []string) {
if len(os.Args) > 1 && os.Args[1] == "log" {
printDeprecationWarning("logs", "log")
@ -83,7 +83,7 @@ func NewCmdLog(f *cmdutil.Factory, out io.Writer) *cobra.Command {
if err := o.Validate(); err != nil {
cmdutil.CheckErr(cmdutil.UsageError(cmd, err.Error()))
}
_, err := o.RunLog()
_, err := o.RunLogs()
cmdutil.CheckErr(err)
},
Aliases: []string{"log"},
@ -163,19 +163,19 @@ func (o LogsOptions) Validate() error {
if len(o.ResourceArg) == 0 {
return errors.New("a pod must be specified")
}
logOptions, ok := o.Options.(*api.PodLogOptions)
logsOptions, ok := o.Options.(*api.PodLogOptions)
if !ok {
return errors.New("unexpected log options object")
return errors.New("unexpected logs options object")
}
if errs := validation.ValidatePodLogOptions(logOptions); len(errs) > 0 {
if errs := validation.ValidatePodLogOptions(logsOptions); len(errs) > 0 {
return errs.ToAggregate()
}
return nil
}
// RunLog retrieves a pod log
func (o LogsOptions) RunLog() (int64, error) {
// RunLogs retrieves a pod log
func (o LogsOptions) RunLogs() (int64, error) {
infos, err := resource.NewBuilder(o.Mapper, o.Typer, o.ClientMapper).
NamespaceParam(o.Namespace).DefaultNamespace().
ResourceNames("pods", o.ResourceArg).

View File

@ -69,7 +69,7 @@ func TestLog(t *testing.T) {
tf.ClientConfig = &client.Config{GroupVersion: &unversioned.GroupVersion{Version: test.version}}
buf := bytes.NewBuffer([]byte{})
cmd := NewCmdLog(f, buf)
cmd := NewCmdLogs(f, buf)
cmd.Flags().Set("namespace", "test")
cmd.Run(cmd, []string{"foo"})
@ -119,7 +119,7 @@ func TestValidateLogFlags(t *testing.T) {
},
}
for _, test := range tests {
cmd := NewCmdLog(f, bytes.NewBuffer([]byte{}))
cmd := NewCmdLogs(f, bytes.NewBuffer([]byte{}))
out := ""
for flag, value := range test.flags {
cmd.Flags().Set(flag, value)
@ -130,7 +130,7 @@ func TestValidateLogFlags(t *testing.T) {
cmd.Run = func(cmd *cobra.Command, args []string) {
o.Complete(f, os.Stdout, cmd, args)
out = o.Validate().Error()
o.RunLog()
o.RunLogs()
}
cmd.Run(cmd, []string{"foo"})