kubectl icon indicating copy to clipboard operation
kubectl copied to clipboard

Fetching previous container logs using kubectl logs --previous --all-containers --ignore-errors is showing error messages for the pods which doesn't have previous containers

Open madhugarimilla opened this issue 5 months ago • 6 comments

What happened?

I am running the below command to collect all logs from previous containers in my namespace. It is fetching the logs for those pods that have previous containers but in addition it is printing error messages for those pods that doesn't have previous containers(which are not restarted). I was expecting the --ignore-errors would skip such messages from the output. Is there a way to achieve that?

Command: kubectl logs -n "mynamespace" -l "label=examplelabel" --previous --all-containers --ignore-errors --prefix --timestamps=true --max-log-requests=40 --since=0s --tail=-1

Result error: previous terminated container "somecontainer" in pod "somepod" not found

What did you expect to happen?

Skip the error messages for those pods that doesn't have previous containers

How can we reproduce it (as minimally and precisely as possible)?

kubectl logs --previous --all-containers --ignore-errors --prefix --timestamps=true --max-log-requests=40 --since=0s --tail=-1

Anything else we need to know?

No response

Kubernetes version

$ kubectl version
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.3", GitCommit:"434bfd82814af038ad94d62ebe59b133fcb50506", GitTreeState:"clean", BuildDate:"2022-10-12T10:57:26Z", GoVersion:"go1.19.2", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.7
Server Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.8-gke.1067000", GitCommit:"3936242da351c64ea89912f00faa0b28fb7eab76", GitTreeState:"clean", BuildDate:"2023-12-06T20:41:34Z", GoVersion:"go1.20.11 X:boringcrypto", Compiler:"gc", Platform:"linux/amd64"}
WARNING: version difference between client (1.25) and server (1.27) exceeds the supported minor version skew of +/-1

Cloud provider

GKE

OS version

# On Linux:
$ cat /etc/os-release
CentOS Linux release 7.9.2009 (Core)
$ uname -a
Linux <masking my hostname> 3.10.0-1160.71.1.el7.x86_64 kubernetes/kubernetes#1 SMP Tue Jun 28 15:37:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

# On Windows:
C:\> wmic os get Caption, Version, BuildNumber, OSArchitecture
# paste output here

Install tools

Container runtime (CRI) and version (if applicable)

Related plugins (CNI, CSI, ...) and versions (if applicable)

madhugarimilla avatar Feb 01 '24 14:02 madhugarimilla

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Feb 01 '24 14:02 k8s-ci-robot

/sig cli /area kubectl

Ritikaa96 avatar Feb 01 '24 15:02 Ritikaa96

JFYI, The flag --ignore-errors is as stated : --ignore-errors=false: If watching / following pod logs, allow for any errors that occur to be non-fatal Are you sure this will skip pods without previous containers?

Ritikaa96 avatar Feb 01 '24 16:02 Ritikaa96

No. It won't skip pods without previous containers. Is there any way i can skip pods without previous containers from the output?

madhugarimilla avatar Feb 02 '24 03:02 madhugarimilla

/transfer kubectl

brianpursley avatar Apr 23 '24 18:04 brianpursley

As stated in the description text of --ignore-errors flag in here;

If watching / following pod logs, allow for any errors that occur to be non-fatal

Previous pod not found error is fatal which is affecting the command's execution. I think, there seems to be no bug in here.

ardaguclu avatar May 08 '24 16:05 ardaguclu