mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-14 21:53:52 +00:00
Cleanup logs command
use 'logs' instead of 'log'
This commit is contained in:
@@ -157,7 +157,7 @@ Find more information at https://github.com/kubernetes/kubernetes.`,
|
|||||||
cmds.AddCommand(NewCmdApply(f, out))
|
cmds.AddCommand(NewCmdApply(f, out))
|
||||||
|
|
||||||
cmds.AddCommand(NewCmdNamespace(out))
|
cmds.AddCommand(NewCmdNamespace(out))
|
||||||
cmds.AddCommand(NewCmdLog(f, out))
|
cmds.AddCommand(NewCmdLogs(f, out))
|
||||||
cmds.AddCommand(NewCmdRollingUpdate(f, out))
|
cmds.AddCommand(NewCmdRollingUpdate(f, out))
|
||||||
cmds.AddCommand(NewCmdScale(f, out))
|
cmds.AddCommand(NewCmdScale(f, out))
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
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
|
$ kubectl logs nginx
|
||||||
|
|
||||||
# Return snapshot of previous terminated ruby container logs from pod web-1
|
# Return snapshot of previous terminated ruby container logs from pod web-1
|
||||||
@@ -65,14 +65,14 @@ type LogsOptions struct {
|
|||||||
Out io.Writer
|
Out io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdLog creates a new pod log command
|
// NewCmdLog creates a new pod logs command
|
||||||
func NewCmdLog(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
func NewCmdLogs(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
||||||
o := &LogsOptions{}
|
o := &LogsOptions{}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "logs [-f] [-p] POD [-c CONTAINER]",
|
Use: "logs [-f] [-p] POD [-c CONTAINER]",
|
||||||
Short: "Print the logs for a container in a pod.",
|
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.",
|
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) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
if len(os.Args) > 1 && os.Args[1] == "log" {
|
if len(os.Args) > 1 && os.Args[1] == "log" {
|
||||||
printDeprecationWarning("logs", "log")
|
printDeprecationWarning("logs", "log")
|
||||||
@@ -83,7 +83,7 @@ func NewCmdLog(f *cmdutil.Factory, out io.Writer) *cobra.Command {
|
|||||||
if err := o.Validate(); err != nil {
|
if err := o.Validate(); err != nil {
|
||||||
cmdutil.CheckErr(cmdutil.UsageError(cmd, err.Error()))
|
cmdutil.CheckErr(cmdutil.UsageError(cmd, err.Error()))
|
||||||
}
|
}
|
||||||
_, err := o.RunLog()
|
_, err := o.RunLogs()
|
||||||
cmdutil.CheckErr(err)
|
cmdutil.CheckErr(err)
|
||||||
},
|
},
|
||||||
Aliases: []string{"log"},
|
Aliases: []string{"log"},
|
||||||
@@ -163,19 +163,19 @@ func (o LogsOptions) Validate() error {
|
|||||||
if len(o.ResourceArg) == 0 {
|
if len(o.ResourceArg) == 0 {
|
||||||
return errors.New("a pod must be specified")
|
return errors.New("a pod must be specified")
|
||||||
}
|
}
|
||||||
logOptions, ok := o.Options.(*api.PodLogOptions)
|
logsOptions, ok := o.Options.(*api.PodLogOptions)
|
||||||
if !ok {
|
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 errs.ToAggregate()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunLog retrieves a pod log
|
// RunLogs retrieves a pod log
|
||||||
func (o LogsOptions) RunLog() (int64, error) {
|
func (o LogsOptions) RunLogs() (int64, error) {
|
||||||
infos, err := resource.NewBuilder(o.Mapper, o.Typer, o.ClientMapper).
|
infos, err := resource.NewBuilder(o.Mapper, o.Typer, o.ClientMapper).
|
||||||
NamespaceParam(o.Namespace).DefaultNamespace().
|
NamespaceParam(o.Namespace).DefaultNamespace().
|
||||||
ResourceNames("pods", o.ResourceArg).
|
ResourceNames("pods", o.ResourceArg).
|
@@ -69,7 +69,7 @@ func TestLog(t *testing.T) {
|
|||||||
tf.ClientConfig = &client.Config{GroupVersion: &unversioned.GroupVersion{Version: test.version}}
|
tf.ClientConfig = &client.Config{GroupVersion: &unversioned.GroupVersion{Version: test.version}}
|
||||||
buf := bytes.NewBuffer([]byte{})
|
buf := bytes.NewBuffer([]byte{})
|
||||||
|
|
||||||
cmd := NewCmdLog(f, buf)
|
cmd := NewCmdLogs(f, buf)
|
||||||
cmd.Flags().Set("namespace", "test")
|
cmd.Flags().Set("namespace", "test")
|
||||||
cmd.Run(cmd, []string{"foo"})
|
cmd.Run(cmd, []string{"foo"})
|
||||||
|
|
||||||
@@ -119,7 +119,7 @@ func TestValidateLogFlags(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
cmd := NewCmdLog(f, bytes.NewBuffer([]byte{}))
|
cmd := NewCmdLogs(f, bytes.NewBuffer([]byte{}))
|
||||||
out := ""
|
out := ""
|
||||||
for flag, value := range test.flags {
|
for flag, value := range test.flags {
|
||||||
cmd.Flags().Set(flag, value)
|
cmd.Flags().Set(flag, value)
|
||||||
@@ -130,7 +130,7 @@ func TestValidateLogFlags(t *testing.T) {
|
|||||||
cmd.Run = func(cmd *cobra.Command, args []string) {
|
cmd.Run = func(cmd *cobra.Command, args []string) {
|
||||||
o.Complete(f, os.Stdout, cmd, args)
|
o.Complete(f, os.Stdout, cmd, args)
|
||||||
out = o.Validate().Error()
|
out = o.Validate().Error()
|
||||||
o.RunLog()
|
o.RunLogs()
|
||||||
}
|
}
|
||||||
cmd.Run(cmd, []string{"foo"})
|
cmd.Run(cmd, []string{"foo"})
|
||||||
|
|
Reference in New Issue
Block a user