Skip to content

Stern shows the same logs multiple times when a container is terminated #217

@tksm

Description

@tksm

What happened:

Stern shows the same logs multiple times when a container is terminated.

$ stern --container-state running --container-state terminated myjob
+ myjob-xz9vh › myjob
myjob-xz9vh myjob done
- myjob-xz9vh › myjob
+ myjob-xz9vh › myjob
myjob-xz9vh myjob done
- myjob-xz9vh › myjob
+ myjob-xz9vh › myjob
myjob-xz9vh myjob done

What you expected to happen:

Logs should be shown only once.

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

  1. Run stern with --container-state flags.
stern --container-state running --container-state terminated myjob
  1. Create a job that will immediately complete with a log "done".
kubectl create job myjob --image busybox -- echo "done"
  1. The same logs are shown multiple times.
$ stern --container-state running --container-state terminated myjob
+ myjob-xz9vh › myjob
myjob-xz9vh myjob done
- myjob-xz9vh › myjob
+ myjob-xz9vh › myjob
myjob-xz9vh myjob done
- myjob-xz9vh › myjob
+ myjob-xz9vh › myjob
myjob-xz9vh myjob done

Anything else we need to know?:

The tails of terminated containers will be inactive immediately, so they will be added back again when stern handles modified events. I think that is why the same logs are shown multiple times.

Maybe stern should ignore terminated containers on modified events.

Environment:

  • stern version (use stern --version): 1.22.0
  • OS (e.g: cat /etc/os-release): macOS 12.2
  • Install tools (e.g: Homebrew) Homebrew
  • Others:

Metadata

Metadata

Assignees

Labels

kind/bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions