Skip to content

cli: Support kubectl-style resource selectors #2734

@olix0r

Description

@olix0r

The various Linkerd subcommands that operate on kubernetes resources all work somewhat differently, and none of them support Kubernetes label selection.

Anywhere where the linkerd CLI operates on a list of resources (tap, top, routes, stat, metrics, etc), linkerd should accept resource selections exactly like kubectl.

Furthermore the --linkerd-namespace flag should be changed so that its short flag is -L, so that the -l flag can be used for label selection (like other kubernetes-related tools).

For example, kubectl supports the following:

:; kubectl get -n linkerd svc/linkerd-web deploy/linkerd-web
NAME                  TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)             AGE
service/linkerd-web   ClusterIP   10.0.238.66   <none>        8084/TCP,9994/TCP   11d

NAME                                DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
deployment.extensions/linkerd-web   1         1         1            1           11d
:; kubectl -n linkerd get po -l linkerd.io/control-plane-component    
NAME                                   READY     STATUS    RESTARTS   AGE
linkerd-controller-58fb7787b-kxhw5     4/4       Running   0          11d
linkerd-grafana-659c48d67-h8lx6        2/2       Running   0          11d
linkerd-identity-84fd9b78b-g9h4c       2/2       Running   0          11d
linkerd-prometheus-644698f444-zg9fn    2/2       Running   0          11d
linkerd-sp-validator-c4965d44c-8qqmb   2/2       Running   0          4d
linkerd-web-7f46b9cfcb-6c6kv           2/2       Running   0          4d
:; kubectl -n linkerd get deploy linkerd-controller linkerd-identity
NAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
linkerd-controller   1         1         1            1           11d
NAME                 DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
linkerd-identity     1         1         1            1           11d

linkerd should accept resource lists similarly.


linkerd stat accepts multiple resources, like kubectl, but does not accept label selectors:

:; linkerd -n linkerd stat deploy linkerd-controller linkerd-identity
NAME                 MESHED   SUCCESS      RPS   LATENCY_P50   LATENCY_P95   LATENCY_P99   TCP_CONN
linkerd-controller      1/1    81.82%   1.1rps           1ms           2ms           3ms         17
linkerd-identity        1/1   100.00%   0.3rps           1ms           1ms           1ms         13

linkerd tap, linkerd top, and likerd routes do not accept a list of resources

:; linkerd -n linkerd tap deploy linkerd-controller linkerd-identity
Error: accepts between 1 and 2 arg(s), received 3
Usage:
  linkerd tap [flags] (RESOURCE)

But there is no technical reason for this, since they all accept all resources of a given type:

:; linkerd -n linkerd tap deploy
req id=0:1 proxy=out src=10.244.3.83:46802 dst=10.244.0.214:4191 tls=no_authority_in_http_request :method=GET :authority=10.244.0.214:4191 :path=/metrics
rsp id=0:1 proxy=out src=10.244.3.83:46802 dst=10.244.0.214:4191 tls=no_authority_in_http_request :status=200 latency=3853µs
end id=0:1 proxy=out src=10.244.3.83:46802 dst=10.244.0.214:4191 tls=no_authority_in_http_request duration=39µs response-length=5635B                                    

The linkerd metrics command does not accept any resource lists, though it supports expanding group types like deploy/foo.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions