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

Add --node flag to filter on a specific node #243

Merged
merged 1 commit into from
Mar 5, 2023
Merged

Conversation

tksm
Copy link
Contributor

@tksm tksm commented Mar 5, 2023

ref #242

This PR adds --node flag to filter on a specific node. This flag will be helpful when we debug pods on the specific node.

# Print a DaemonSet pod on the specific node
stern --node <NODE_NAME> daemonsets/<DS_NAME>

# Print all pods on the specific node
stern --node <NODE_NAME> --all-namespaces --no-follow --max-log-requests 1 .

I will implement a completion for this flag after this PR is merged.

Example

Let's say we have four nodes.

$ kubectl get nodes
NAME                 STATUS   ROLES           AGE   VERSION
kind-control-plane   Ready    control-plane   14m   v1.25.3
kind-worker          Ready    <none>          13m   v1.25.3
kind-worker2         Ready    <none>          13m   v1.25.3
kind-worker3         Ready    <none>          13m   v1.25.3

Without --node, stern shows all pods that the DaemonSet created.

$ stern -n kube-system --tail 1 --no-follow --only-log-lines daemonset/kindnet
kindnet-flqlg kindnet-cni I0305 01:34:00.843821       1 main.go:250] Node kind-worker3 has CIDR [10.244.1.0/24]
kindnet-5f4ms kindnet-cni I0305 01:33:59.442694       1 main.go:250] Node kind-worker3 has CIDR [10.244.1.0/24]
kindnet-bdgk4 kindnet-cni I0305 01:33:59.039534       1 main.go:227] handling current node
kindnet-hqn2k kindnet-cni I0305 01:33:59.268987       1 main.go:250] Node kind-worker3 has CIDR [10.244.1.0/24]

With --node kind-worker2, stern shows only the pod on the node kind-worker2.

$ stern --node kind-worker2 -n kube-system --tail 1 --no-follow --only-log-lines daemonset/kindnet
kindnet-hqn2k kindnet-cni I0305 01:36:19.251494       1 main.go:250] Node kind-worker3 has CIDR [10.244.1.0/24]

Copy link
Member

@rkmathi rkmathi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very useful 😄

@tksm tksm merged commit f90f70f into stern:master Mar 5, 2023
@tksm tksm deleted the node-flag branch March 5, 2023 04:08
@tksm
Copy link
Contributor Author

tksm commented Mar 5, 2023

Thank you for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants