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

feature(service list): Print NAMESPACE column as the first column when --all-namespaces is specified #366

Merged
merged 10 commits into from
Aug 22, 2019

Conversation

toVersus
Copy link
Contributor

/lint

Proposed Changes

kn service list should print NAMESPACE column when specifying --all-namespaces option, which follows the kubectl convention.

NAMESPACE should be displayed as the first column when --all-namespaces is specified

I know we can find a namespace we deployed our service by inspecting an URL column. It tells us a namespace by default because its FQDN is composed of {{.Name}}.{{.Namespace}}.{{.Domain}}. However, we can easily change this FQDN template by modifying domainTemplate field in config-network.yaml. In this case, we have no idea to see a namespace from the output of kn service list --all-namespace at a glance. Also, I think it is useful to see a bunch of services in the same namespace by sorting in alphabetical order.

  • Print NAMESPACE as the first column when --all-namespaces is specified in kn service list command
  • Show services in default namespace at the top of the list
  • Add unit tests using fake services as well as mock framework

Before:

$ ./kn service list -A
NAME    URL                                GENERATION   AGE     CONDITIONS   READY   REASON
bar     http://bar-bar.example.com         1            73m     3 OK / 3     True
echo    http://echo-bar.example.com        1            73m     3 OK / 3     True
echo    http://echo-default.example.com    1            6h10m   3 OK / 3     True
echo    http://echo-foo.example.com        1            74m     3 OK / 3     True
foo     http://foo-default.example.com     1            6h9m    3 OK / 3     True
foo     http://foo-foo.example.com         1            74m     3 OK / 3     True
hello   http://hello-bar.example.com       1            72m     3 OK / 3     True
hello   http://hello-default.example.com   1            42h     3 OK / 3     True
hello   http://hello-foo.example.com       1            73m     3 OK / 3     True

After:

$ ./kn service list -A
NAMESPACE   NAME    URL                                GENERATION   AGE     CONDITIONS   READY   REASON
default     echo    http://echo-default.example.com    1            5h51m   3 OK / 3     True
default     foo     http://foo-default.example.com     1            5h51m   3 OK / 3     True
default     hello   http://hello-default.example.com   1            42h     3 OK / 3     True
bar         bar     http://bar-bar.example.com         1            54m     3 OK / 3     True
bar         echo    http://echo-bar.example.com        1            54m     3 OK / 3     True
bar         hello   http://hello-bar.example.com       1            54m     3 OK / 3     True
foo         echo    http://echo-foo.example.com        1            55m     3 OK / 3     True
foo         foo     http://foo-foo.example.com         1            56m     3 OK / 3     True
foo         hello   http://hello-foo.example.com       1            55m     3 OK / 3     True

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Aug 15, 2019
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a comment

Choose a reason for hiding this comment

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

@toVersus: 1 warning.

In response to this:

/lint

Proposed Changes

kn service list should print NAMESPACE column when specifying --all-namespaces option, which follows the kubectl convention.

NAMESPACE should be displayed as the first column when --all-namespaces is specified

I know we can find a namespace we deployed our service by inspecting an URL column. It tells us a namespace by default because its FQDN is composed of {{.Name}}.{{.Namespace}}.{{.Domain}}. However, we can easily change this FQDN template by modifying domainTemplate field in config-network.yaml. In this case, we have no idea to see a namespace from the output of kn service list --all-namespace at a glance. Also, I think it is useful to see a bunch of services in the same namespace by sorting in alphabetical order.

  • Print NAMESPACE as the first column when --all-namespaces is specified in kn service list command
  • Show services in default namespace at the top of the list
  • Add unit tests using fake services as well as mock framework

Before:

$ ./kn service list -A
NAME    URL                                GENERATION   AGE     CONDITIONS   READY   REASON
bar     http://bar-bar.example.com         1            73m     3 OK / 3     True
echo    http://echo-bar.example.com        1            73m     3 OK / 3     True
echo    http://echo-default.example.com    1            6h10m   3 OK / 3     True
echo    http://echo-foo.example.com        1            74m     3 OK / 3     True
foo     http://foo-default.example.com     1            6h9m    3 OK / 3     True
foo     http://foo-foo.example.com         1            74m     3 OK / 3     True
hello   http://hello-bar.example.com       1            72m     3 OK / 3     True
hello   http://hello-default.example.com   1            42h     3 OK / 3     True
hello   http://hello-foo.example.com       1            73m     3 OK / 3     True

After:

$ ./kn service list -A
NAMESPACE   NAME    URL                                GENERATION   AGE     CONDITIONS   READY   REASON
default     echo    http://echo-default.example.com    1            5h51m   3 OK / 3     True
default     foo     http://foo-default.example.com     1            5h51m   3 OK / 3     True
default     hello   http://hello-default.example.com   1            42h     3 OK / 3     True
bar         bar     http://bar-bar.example.com         1            54m     3 OK / 3     True
bar         echo    http://echo-bar.example.com        1            54m     3 OK / 3     True
bar         hello   http://hello-bar.example.com       1            54m     3 OK / 3     True
foo         echo    http://echo-foo.example.com        1            55m     3 OK / 3     True
foo         foo     http://foo-foo.example.com         1            56m     3 OK / 3     True
foo         hello   http://hello-foo.example.com       1            55m     3 OK / 3     True

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.

pkg/kn/commands/service/human_readable_flags.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Aug 15, 2019
@knative-prow-robot
Copy link
Contributor

Hi @toVersus. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 15, 2019
@duglin
Copy link
Contributor

duglin commented Aug 15, 2019

Clearly including the NS in there is +1 :-)

I'm just wondering about people using kn within scripts and possibly parsing the output, and whether having the number of columns change based on whether -A is used or not is a good or bad thing. Meaning, should NAMESPACE be there even w/o -A? Honestly, I can't decide. It might depend on whether people consider the use of -A to make it a totally new command or just a variant of service list and the same "output processor" should work for both.

I do parse output from cmds like this a lot, but I don't know if I'm in a very small minority.

@toVersus
Copy link
Contributor Author

toVersus commented Aug 15, 2019

@duglin I'm not an enthusiast to use kn within my custom scripts, so I'm not sure about this :)

Meaning, should NAMESPACE be there even w/o -A

I think it feels redundant because kn service list or kn service list -n <namespace> will only print the services in specific namespace. It is clear for the users without NAMESPACE column.

It might depend on whether people consider the use of -A to make it a totally new command or just a variant of service list and the same "output processor" should work for both.

IMO, the motivation of -A option is to ensure the human readability, which is the same as -o wide option. It is not designed for improving machine readability for the use in scripts, so it is acceptable to change the number of columns.

if err != nil {
fmt.Fprintln(c.OutOrStdout(), err)
}
f.AllNamespaces = all
Copy link
Collaborator

@navidshaikh navidshaikh Aug 16, 2019

Choose a reason for hiding this comment

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

Can we make this other way round and handle it in more generic way ?

As in, flags defined in HumanPrintFlags, gets added to all resource listing commands.

ToPrinter handles it for services, revisions and routes.

WDYT ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I can handle it in more generic way, but I changed to handle --all-namespace option in a similar way to kubectl get.

pkg/kn/commands/service/human_readable_flags.go Outdated Show resolved Hide resolved
pkg/kn/commands/service/service_list_flags.go Outdated Show resolved Hide resolved
`kn service list` should print NAMESPACE column when specifying `--all-namespace` option, which follows the kubectl convention.
A priority field is handled as follows:
- priority 0: print namespace column
- priority 1: print default columns
- priority 2: print additional columns for wide option
Copy link
Collaborator

@navidshaikh navidshaikh left a comment

Choose a reason for hiding this comment

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

Few things to clean up and a suggestion to add --with-namespace for kn service list command (not to be implemented right now but up for discussion).

pkg/kn/commands/human_readable_flags.go Show resolved Hide resolved
pkg/kn/commands/service/service_list.go Outdated Show resolved Hide resolved
pkg/kn/commands/service/human_readable_flags.go Outdated Show resolved Hide resolved
pkg/kn/commands/human_readable_flags.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@navidshaikh navidshaikh left a comment

Choose a reason for hiding this comment

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

@toVersus a minor change request, we're good then. Thanks!

pkg/kn/commands/service/service_list_flags.go Outdated Show resolved Hide resolved
pkg/kn/commands/service/service_list_mock_test.go Outdated Show resolved Hide resolved
pkg/kn/commands/service/service_list_test.go Show resolved Hide resolved
Copy link
Collaborator

@navidshaikh navidshaikh left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 22, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: navidshaikh, toVersus

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 22, 2019
@knative-metrics-robot
Copy link

The following is the coverage report on pkg/.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/service/human_readable_flags.go 95.0% 92.5% -2.5
pkg/kn/commands/service/service_list.go 87.5% 88.2% 0.7

@knative-prow-robot knative-prow-robot merged commit d0dc3b7 into knative:master Aug 22, 2019
@toVersus toVersus deleted the feat/all-namespaces branch August 25, 2019 13:48
coryrc pushed a commit to coryrc/client that referenced this pull request May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants