Skip to content

cli: add --selector flag to proxy-metrics and multi-resource support to routes#15228

Open
mail2sudheerobbu-oss wants to merge 2 commits into
linkerd:mainfrom
mail2sudheerobbu-oss:feat/2734-kubectl-style-selectors
Open

cli: add --selector flag to proxy-metrics and multi-resource support to routes#15228
mail2sudheerobbu-oss wants to merge 2 commits into
linkerd:mainfrom
mail2sudheerobbu-oss:feat/2734-kubectl-style-selectors

Conversation

@mail2sudheerobbu-oss
Copy link
Copy Markdown

Closes #2734

What

Two additions toward full kubectl-style resource selector support in the Linkerd CLI:

1. linkerd viz routes — multi-resource support

Previously routes accepted exactly one resource argument. This PR changes Args from cobra.ExactArgs(1) to cobra.MinimumNArgs(1), allowing multiple resources to be queried in one call:

linkerd viz routes svc/webapp svc/api -n test

The gRPC client is constructed once before the loop; each resource produces one TopRoutesRequest and the outputs are concatenated.

2. linkerd diagnostics proxy-metrics--selector / -l flag

Previously the command required a TYPE/NAME positional argument. This PR adds a --selector/-l flag so pods can be selected by label without specifying a resource name:

linkerd diagnostics proxy-metrics -n emojivoto -l app=web

A new GetPodsBySelector helper is added to pkg/k8s (wrapping CoreV1().Pods().List() with a label selector), consistent with the existing private getPods in cli/cmd/identity.go. When a positional argument is also provided it takes precedence (existing behaviour preserved). Omitting both is a validation error.

Testing

  • viz routes with a single resource continues to work as before (backward compatible)
  • viz routes svc/A svc/B queries both resources and concatenates output
  • proxy-metrics deploy/foo continues to work (backward compatible)
  • proxy-metrics -l app=web -n emojivoto selects pods by label
  • proxy-metrics with no args and no selector returns a clear error message

Related

@mail2sudheerobbu-oss mail2sudheerobbu-oss requested a review from a team as a code owner May 1, 2026 17:21
@mail2sudheerobbu-oss
Copy link
Copy Markdown
Author

Hi team — gentle ping on this PR. It adds --selector flag support to proxy-metrics and multi-resource support to routes, following the kubectl-style selector pattern (closes #2734). Branch is synced with main. Would appreciate a review when convenient! 🙏

@cratelyn
Copy link
Copy Markdown
Member

cratelyn commented May 4, 2026

Hi team — gentle ping on this PR. It adds --selector flag support to proxy-metrics and multi-resource support to routes, following the kubectl-style selector pattern (closes #2734). Branch is synced with main. Would appreciate a review when convenient! 🙏

hi @mail2sudheerobbu-oss, i'll say the same thing here that was noted in #15197 (comment). we're excited to take a look at this, but we are a busy team and review bandwidth can sometimes take a few days. please refrain from repeated pings, especially after barely one business day.

@cratelyn
Copy link
Copy Markdown
Member

cratelyn commented May 4, 2026

in the meantime, the DCO check is failing. please push commits that include a DCO signoff.

@mail2sudheerobbu-oss
Copy link
Copy Markdown
Author

@unleashed — I sincerely apologize. You gave clear guidance and I kept pinging anyway — that was inconsiderate of your time and I'm sorry. I'll stop.

I'm also fixing the DCO signoff now and will push the corrected commits as my only update. I'll wait quietly from there.

@mail2sudheerobbu-oss mail2sudheerobbu-oss force-pushed the feat/2734-kubectl-style-selectors branch 2 times, most recently from 3479049 to 1ab22a1 Compare May 5, 2026 01:29
Closes linkerd#2734

Two additions toward full kubectl-style resource selector support:

1. viz routes — multi-resource support
   Change Args from ExactArgs(1) to MinimumNArgs(1) so that multiple
   resources can be specified:

     linkerd viz routes svc/webapp svc/api -n test

   The API client is constructed once before the loop; each resource
   produces one TopRoutesRequest and the outputs are concatenated.

2. diagnostics proxy-metrics — --selector / -l flag
   Add a labelSelector field to metricsOptions and register the
   --selector/-l flag. When no positional argument is given but a
   selector is provided, GetPodsBySelector (new helper in pkg/k8s) is
   called to list matching pods directly:

     linkerd diagnostics proxy-metrics -n emojivoto -l app=web

   GetPodsBySelector wraps a plain CoreV1().Pods().List() call with
   the label-selector string, consistent with the existing getPods()
   helper in cli/cmd/identity.go.

   A positional argument is still accepted and takes precedence when
   both are given; omitting both is an error.

Signed-off-by: Sudheer Obbu <mail2sudheerobbu@gmail.com>
@mail2sudheerobbu-oss mail2sudheerobbu-oss force-pushed the feat/2734-kubectl-style-selectors branch from f536f27 to 5f5b5c6 Compare May 7, 2026 12:33
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.

cli: Support kubectl-style resource selectors

2 participants