Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"kubectl logs" ignores "--tail" option when "--selector" is given #70554

Closed
jpetazzo opened this issue Nov 1, 2018 · 4 comments · Fixed by #70577
Closed

"kubectl logs" ignores "--tail" option when "--selector" is given #70554

jpetazzo opened this issue Nov 1, 2018 · 4 comments · Fixed by #70577
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/cli Categorizes an issue or PR as relevant to SIG CLI.

Comments

@jpetazzo
Copy link
Contributor

jpetazzo commented Nov 1, 2018

What happened:

I do kubectl logs --tail 1 --selector run=foo.

I see the last 10 lines of output of each pod matching run=foo.

What you expected to happen:

I was expecting to see only the last line of output of each pod.

How to reproduce it (as minimally and precisely as possible):

kubectl run clock --image=jpetazzo/clock --replicas=2
sleep 3
kubectl logs --tail 1 --selector run=clock

The jpetazzo/clock image prints the date every second.

Normally we should just see two lines of output; instead we see 20.

Anything else we need to know?:

This seems to be a regression in Kubernetes 1.12, as this worked correctly from 1.8 to 1.11.

(I observed this problem starting with k8s 1.12.0 and it's still present in 1.12.2)

Environment:

  • Kubernetes version (use kubectl version): 1.12.2
  • Cloud provider or hardware configuration: AWS
  • OS (e.g. from /etc/os-release): Ubuntu
  • Kernel (e.g. uname -a): 4.4.0
  • Install tools: kubeadm
  • Others:

/kind bug

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 1, 2018
@jpetazzo
Copy link
Contributor Author

jpetazzo commented Nov 1, 2018

It looks like the issue was introduced by commit 3a3633a, specifically here.

If I understand that code correctly, it forces the number of lines to selectorTail (10) even if o.Tail is set.

Since that seems to be in kubectl:

/sig cli

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Nov 1, 2018
jpetazzo added a commit to jpetazzo/container.training that referenced this issue Nov 2, 2018
kubectl logs -l ... --tail ... is buggy.
(It always returns 10 lines of output instead
of the requested number.)

This works around the problem, by adding extra
explanations of the issue and providing a shell
function as a workaround.

See kubernetes/kubernetes#70554 for details.
jpetazzo added a commit to jpetazzo/container.training that referenced this issue Nov 2, 2018
(It always returns 10 lines of output instead
of the requested number.)

This works around the problem, by adding extra
explanations of the issue and providing a shell
function as a workaround.

See kubernetes/kubernetes#70554 for details.
jpetazzo added a commit to jpetazzo/container.training that referenced this issue Nov 2, 2018
(It always returns 10 lines of output instead
of the requested number.)

This works around the problem, by adding extra
explanations of the issue and providing a shell
function as a workaround.

See kubernetes/kubernetes#70554 for details.
@WanLinghao
Copy link
Contributor

/assign

@liggitt
Copy link
Member

liggitt commented Nov 2, 2018

It looks like the issue was introduced by commit 3a3633a, specifically here.

didn't that commit just move the code from 3a3633a#diff-0fabd226d454fe805719db043ac4e46bL203 ?

@jpetazzo
Copy link
Contributor Author

jpetazzo commented Nov 2, 2018

didn't that commit just move the code from 3a3633a#diff-0fabd226d454fe805719db043ac4e46bL203 ?

Not quite; the old code was:

		if logOptions.TailLines == nil && tail != -1 {
			logOptions.TailLines = &selectorTail
		}

The new code is:

	if len(o.Selector) > 0 && o.Tail != -1 {
		logOptions.TailLines = &selectorTail
	} else if o.Tail != -1 {
		logOptions.TailLines = &o.Tail
	}

I don't know why it was changed, but the new logic reads as "if the user specified a selector and a number of lines different from -1, then set the number of lines to 10".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. sig/cli Categorizes an issue or PR as relevant to SIG CLI.
Projects
None yet
4 participants