mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #74943 from JishanXing/bug-fix
Fix #74900 - kubectl logs --selector supports --tail=-1
This commit is contained in:
commit
bf86300241
@ -115,6 +115,8 @@ type LogsOptions struct {
|
|||||||
LogsForObject polymorphichelpers.LogsForObjectFunc
|
LogsForObject polymorphichelpers.LogsForObjectFunc
|
||||||
|
|
||||||
genericclioptions.IOStreams
|
genericclioptions.IOStreams
|
||||||
|
|
||||||
|
TailSpecified bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogsOptions(streams genericclioptions.IOStreams, allContainers bool) *LogsOptions {
|
func NewLogsOptions(streams genericclioptions.IOStreams, allContainers bool) *LogsOptions {
|
||||||
@ -191,7 +193,7 @@ func (o *LogsOptions) ToLogOptions() (*corev1.PodLogOptions, error) {
|
|||||||
logOptions.SinceSeconds = &sec
|
logOptions.SinceSeconds = &sec
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(o.Selector) > 0 && o.Tail == -1 {
|
if len(o.Selector) > 0 && o.Tail == -1 && !o.TailSpecified {
|
||||||
logOptions.TailLines = &selectorTail
|
logOptions.TailLines = &selectorTail
|
||||||
} else if o.Tail != -1 {
|
} else if o.Tail != -1 {
|
||||||
logOptions.TailLines = &o.Tail
|
logOptions.TailLines = &o.Tail
|
||||||
@ -202,6 +204,7 @@ func (o *LogsOptions) ToLogOptions() (*corev1.PodLogOptions, error) {
|
|||||||
|
|
||||||
func (o *LogsOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
func (o *LogsOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
|
||||||
o.ContainerNameSpecified = cmd.Flag("container").Changed
|
o.ContainerNameSpecified = cmd.Flag("container").Changed
|
||||||
|
o.TailSpecified = cmd.Flag("tail").Changed
|
||||||
o.Resources = args
|
o.Resources = args
|
||||||
|
|
||||||
switch len(args) {
|
switch len(args) {
|
||||||
@ -290,8 +293,8 @@ func (o LogsOptions) Validate() error {
|
|||||||
return fmt.Errorf("--since must be greater than 0")
|
return fmt.Errorf("--since must be greater than 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
if logsOptions.TailLines != nil && *logsOptions.TailLines < 0 {
|
if logsOptions.TailLines != nil && *logsOptions.TailLines < -1 {
|
||||||
return fmt.Errorf("TailLines must be greater than or equal to 0")
|
return fmt.Errorf("--tail must be greater than or equal to -1")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -328,7 +328,7 @@ func TestValidateLogOptions(t *testing.T) {
|
|||||||
return o
|
return o
|
||||||
},
|
},
|
||||||
args: []string{"foo"},
|
args: []string{"foo"},
|
||||||
expected: "must be greater than or equal to 0",
|
expected: "--tail must be greater than or equal to -1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "container name combined with --all-containers",
|
name: "container name combined with --all-containers",
|
||||||
|
Loading…
Reference in New Issue
Block a user