Skip to content

Conversation

@brendandburns
Copy link
Contributor

@brendandburns brendandburns commented Feb 4, 2017

@kubernetes/sig-cli-pr-reviews

This PR adds an initial path for optional color support.

Currently:

kubectl get pods --color

Will print colorized output.

Eventually, I will add an environment variable as well. (and colors for other things)

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 4, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-github-robot k8s-github-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. release-note-label-needed labels Feb 4, 2017
@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

The following people have approved this PR: brendandburns

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 4, 2017
@brendandburns
Copy link
Contributor Author

colors

@smarterclayton
Copy link
Contributor

Why color the name column instead of the status column? The users eye will need to go the status column anyway on a failure, and so this actually makes it harder to spot invalid items in that case (makes the user do more work, because the color will pull the eye). Likewise, for normal operation the color against a black background makes the name harder to read in the "normal" case, which makes the user do more work to scan a list.

@smarterclayton
Copy link
Contributor

Generally you want color to pull the eye to the spot that is abnormal, not to anchor it on the things that are "normal". I might suggest we want the entire row to be bold on error, and normal weight on normal status.

Finally, all this is moving to the server side, so doing this now is putting extra weight on clients now that complicates that design (or is at minimum an extra requirement). How is this going to work for third party resources? I'd like to keep this really minimal for right now, and not complicate those other efforts that are actually required in the short term.

@brendandburns
Copy link
Contributor Author

@smarterclayton we're moving human readable printing server side? That can't be right...

Feedback on the colors and coloring the name vs. the status makes sense to me, though I think there's a degree to wanting a measure of the pod "health" in general.

e.g. number of restarts, number of containers running, etc. all contribute to a pods "healthiness"

I worry that we'll end up with lots of different colors if we don't focus on coloring the entire row a single shade...

(I'd be open to coloring the entire row, or restricting coloring only to "abnormal" rows)

@0xmichalis
Copy link
Contributor

Is this going to work consistently across different terminals? Is it something that has been discussed in @kubernetes/sig-cli-misc ?

podColor = "<fg 11>" // yellow
}
if readyContainers == 0 {
podColor = "<fg 1>" // red
Copy link
Contributor

Choose a reason for hiding this comment

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

@brendandburns

I worry that we'll end up with lots of different colors if we don't focus on coloring the entire row a single shade...

Based on this comment, and @smarterclayton's feedback, perhaps we could keep red for rows where the pod status is failing, and no color / how it is currently for any other case. 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.

Yeah, that works for me. I'd love to have yellow for "warning" (pending, some restarts recently, etc) and "red" for "not working"

I'll update the pr.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still haven't seen this one addressed. Additionally if I add watch flag I'm getting:

$ kubectl get pods --color -w
NAME          READY     STATUS    RESTARTS   AGE
<fg 2>hello-5b209<reset>   1/1       Running   0          18s

and that's definitely not what I'd expect.

Copy link
Member

Choose a reason for hiding this comment

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

I understand the benefit, but we need to reconcile this with kubernetes/community#363

@brendandburns
Copy link
Contributor Author

@Kargakis this should work across all Xterm capable terminals. It is off by default as well (and I think it will be off by default for a long time) so I think we don't have to have perfect fidelity everywhere, since it will only affect people who opt into it.

@brendandburns
Copy link
Contributor Author

Also, @smarterclayton considering the server side bits, the colors actually come as a markup language, so I think that will actually make it easier for the server side, since the server can return markup colors and the client can figure out how to render them.

@soltysh
Copy link
Contributor

soltysh commented Feb 9, 2017

My $0.02, why coloring would ever belong to server side? I can understand the desire to have a consistent output across client apps, but coloring should belong to client app, imho. The server side printing is a whole different story and I do have a mixed feelings about it, too.

👍 for having color emphasize the abnormal state and none for ok.

@brendandburns
Copy link
Contributor Author

@soltysh I agree entirely, and honestly this is why I have significant concerns about server-side printing.

However, if we move table-based printing to the server, the information needed to do the color-based decision making will be lost and stored on the server, not in the client, so the server would be the only place to make that decision.

@brendandburns
Copy link
Contributor Author

Friendly ping on this.

Thanks
--brendan

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 16, 2017
@fabianofranz
Copy link
Contributor

I like the idea of making it opt-in at least until it stabilizes.

Any strong reason for choosing that particular library? When I R&D about colors a few months ago I found https://github.com/fatih/color, it supports Windows cmd.exe and can also make the existing fmt printing functions colorizable (although I didn't check how that was implemented). Not strong about one or another though.

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 20, 2017
@fabianofranz
Copy link
Contributor

@k8s-bot test this

@k8s-ci-robot
Copy link
Contributor

@brendandburns: The following test(s) failed:

Test name Commit Details Rerun command
Jenkins unit/integration a583455 link @k8s-bot unit test this
Jenkins verification a583455 link @k8s-bot verify test this
Jenkins kops AWS e2e a583455 link @k8s-bot kops aws e2e test this
Jenkins GCI GCE e2e a583455 link @k8s-bot gci gce e2e test this
Jenkins non-CRI GCE e2e a583455 link @k8s-bot non-cri e2e test this
Jenkins GCE etcd3 e2e a583455 link @k8s-bot gce etcd3 e2e test this
Jenkins GCE e2e a583455 link @k8s-bot cvm gce e2e test this

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

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. I understand the commands that are listed here.

@soltysh
Copy link
Contributor

soltysh commented Feb 22, 2017

However, if we move table-based printing to the server, the information needed to do the color-based decision making will be lost and stored on the server, not in the client, so the server would be the only place to make that decision.

That will only be true for the extended printing options, that @smarterclayton is proposing, right?

podColor = "<fg 11>" // yellow
}
if readyContainers == 0 {
podColor = "<fg 1>" // red
Copy link
Contributor

Choose a reason for hiding this comment

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

Still haven't seen this one addressed. Additionally if I add watch flag I'm getting:

$ kubectl get pods --color -w
NAME          READY     STATUS    RESTARTS   AGE
<fg 2>hello-5b209<reset>   1/1       Running   0          18s

and that's definitely not what I'd expect.

@brendandburns
Copy link
Contributor Author

@fabianofranz I actually started this PR using https://github.com/fatih/color.

The trouble that I ran into was that the colorization characters broke the golang TabWriter class, see this question: http://stackoverflow.com/questions/35398497/how-do-i-get-colors-to-work-with-golang-tabwriter for someone who ran into the same problem.

Because this library uses markup, and you can train TabWriter to ignore HTML characters this library actually works and also does the right things with indents.

@soltysh will work on getting the comments/problems addressed.

Thanks!

@k8s-github-robot
Copy link

@brendandburns PR needs rebase

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 27, 2017
@brendandburns
Copy link
Contributor Author

@smarterclayton
Copy link
Contributor

smarterclayton commented Mar 13, 2017 via email

@smarterclayton
Copy link
Contributor

smarterclayton commented Mar 13, 2017 via email

@brendandburns
Copy link
Contributor Author

@smarterclayton where is the proposal for server-side printing?

I'm happy to pile on there.

@soltysh
Copy link
Contributor

soltysh commented Mar 15, 2017

@brendandburns proposal: kubernetes/community#363, prototype: #40848

ShowLabels: GetFlagBool(cmd, "show-labels"),
AbsoluteTimestamps: isWatch(cmd),
ColumnLabels: columnLabel,
Color: GetFlagBool(cmd, "color"),
Copy link
Member

Choose a reason for hiding this comment

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

Does this detect whether a terminal is attached or not, as well?

"k8s.io/kubernetes/pkg/util/i18n"
"k8s.io/kubernetes/pkg/util/interrupt"

"github.com/reconquest/loreley"
Copy link
Member

Choose a reason for hiding this comment

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

AFAICT, this doesn't have a license. We can't merge this.

We need a verify script to look for this type of thing. It's repeatedly caused us grief.

Copy link
Member

Choose a reason for hiding this comment

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

Filed #44505

@bgrant0607
Copy link
Member

BTW, I also want to nuke the kubeconfig preferences section, which contains only the colors preference currently. #10693

@k8s-github-robot k8s-github-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 5, 2017
@k8s-github-robot
Copy link

This PR hasn't been active in 90 days. Closing this PR. Please reopen if you would like to work towards merging this change, if/when the PR is ready for the next round of review.

cc @brendandburns @fabianofranz

You can add 'keep-open' label to prevent this from happening again, or add a comment to keep it open another 90 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants