mirror of https://github.com/k3s-io/k3s
Merge pull request #65545 from tvieira/kubectl_logs_msg
Automatic merge from submit-queue (batch tested with PRs 67578, 68154, 68162, 65545). If you want to cherry-pick this change to another branch, please follow the instructions here: https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md. fix usage string for the kubectl logs command Even though the use of an inline [CONTAINER] name is still accepted for, legacy purpose the error message does not match what the documentation or man page says. This commit aligns the usage string that is displayed when the `kubectl logs` command is called with more than one container name (with the use of the -c flag or not). ```release-note NONE ```pull/8/head
commit
380931aca7
|
@ -38,6 +38,10 @@ import (
|
|||
"k8s.io/kubernetes/pkg/kubectl/util/i18n"
|
||||
)
|
||||
|
||||
const (
|
||||
logsUsageStr = "logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]"
|
||||
)
|
||||
|
||||
var (
|
||||
logsExample = templates.Examples(i18n.T(`
|
||||
# Return snapshot logs from pod nginx with only one container
|
||||
|
@ -67,11 +71,8 @@ var (
|
|||
# Return snapshot logs from container nginx-1 of a deployment named nginx
|
||||
kubectl logs deployment/nginx -c nginx-1`))
|
||||
|
||||
selectorTail int64 = 10
|
||||
)
|
||||
|
||||
const (
|
||||
logsUsageStr = "expected 'logs (POD | TYPE/NAME) [CONTAINER_NAME]'.\nPOD or TYPE/NAME is a required argument for the logs command"
|
||||
selectorTail int64 = 10
|
||||
logsUsageErrStr = fmt.Sprintf("expected '%s'.\nPOD or TYPE/NAME is a required argument for the logs command", logsUsageStr)
|
||||
)
|
||||
|
||||
type LogsOptions struct {
|
||||
|
@ -118,7 +119,7 @@ func NewCmdLogs(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.C
|
|||
o := NewLogsOptions(streams, false)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "logs [-f] [-p] (POD | TYPE/NAME) [-c CONTAINER]",
|
||||
Use: logsUsageStr,
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: i18n.T("Print the logs for a container in a pod"),
|
||||
Long: "Print the logs for a container in a pod or specified resource. If the pod has only one container, the container name is optional.",
|
||||
|
@ -192,7 +193,7 @@ func (o *LogsOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []str
|
|||
switch len(args) {
|
||||
case 0:
|
||||
if len(o.Selector) == 0 {
|
||||
return cmdutil.UsageErrorf(cmd, "%s", logsUsageStr)
|
||||
return cmdutil.UsageErrorf(cmd, "%s", logsUsageErrStr)
|
||||
}
|
||||
case 1:
|
||||
o.ResourceArg = args[0]
|
||||
|
@ -203,7 +204,7 @@ func (o *LogsOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []str
|
|||
o.ResourceArg = args[0]
|
||||
o.Container = args[1]
|
||||
default:
|
||||
return cmdutil.UsageErrorf(cmd, "%s", logsUsageStr)
|
||||
return cmdutil.UsageErrorf(cmd, "%s", logsUsageErrStr)
|
||||
}
|
||||
var err error
|
||||
o.Namespace, _, err = f.ToRawKubeConfigLoader().Namespace()
|
||||
|
|
|
@ -244,13 +244,6 @@ func TestLogComplete(t *testing.T) {
|
|||
opts func(genericclioptions.IOStreams) *LogsOptions
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "No args case",
|
||||
opts: func(streams genericclioptions.IOStreams) *LogsOptions {
|
||||
return NewLogsOptions(streams, false)
|
||||
},
|
||||
expected: "'logs (POD | TYPE/NAME) [CONTAINER_NAME]'.\nPOD or TYPE/NAME is a required argument for the logs command",
|
||||
},
|
||||
{
|
||||
name: "One args case",
|
||||
args: []string{"foo"},
|
||||
|
@ -261,16 +254,6 @@ func TestLogComplete(t *testing.T) {
|
|||
},
|
||||
expected: "only a selector (-l) or a POD name is allowed",
|
||||
},
|
||||
{
|
||||
name: "More than two args case",
|
||||
args: []string{"foo", "foo1", "foo2"},
|
||||
opts: func(streams genericclioptions.IOStreams) *LogsOptions {
|
||||
o := NewLogsOptions(streams, false)
|
||||
o.Tail = 1
|
||||
return o
|
||||
},
|
||||
expected: "'logs (POD | TYPE/NAME) [CONTAINER_NAME]'.\nPOD or TYPE/NAME is a required argument for the logs command",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
cmd := NewCmdLogs(f, genericclioptions.NewTestIOStreamsDiscard())
|
||||
|
|
Loading…
Reference in New Issue