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

Missing colors in diff #2043

Closed
z0rc opened this issue Jan 10, 2022 · 23 comments
Closed

Missing colors in diff #2043

z0rc opened this issue Jan 10, 2022 · 23 comments

Comments

@z0rc
Copy link

z0rc commented Jan 10, 2022

After upgrading helm-diff to 3.2.0 or newer, running helmfile diff produces output with no colors when running in regular terminal (not CI, TERM=xterm-256color). In the same time running helm diff in the same terminal produces colors as expected.

My guess is that after databus23/helm-diff#240, there is check https://github.com/databus23/helm-diff/blob/master/cmd/root.go#L47-L50 which always true due to how helmfile executes helm-diff. helm-diff's stdout is captured/redirected in separate file descriptor which isn't considered as terminal.

I tried passing running helmfile --no-color=false diff, but it didn't enable color in diff output. Only way to enforce colors I found was helmfile diff --args="--no-color=false", but it's problematic in way where this arg passed to helm list execution and fails there.

@mumoshu
Copy link
Collaborator

mumoshu commented Jan 10, 2022

@z0rc Ah good catch. Probably helm-diff should have an option to force enabling color, and external tools like helmfile that calls helm-diff should specify that force-color flag when it detects a terminal. WDYT?

@z0rc
Copy link
Author

z0rc commented Jan 10, 2022

@mumoshu proposed logic look correct, just need to take into account helmfile's own --no-colors argument.

@mumoshu
Copy link
Collaborator

mumoshu commented Jan 10, 2022

Merged databus23/helm-diff#344 on helm-diff. The next action item would be to enhance helmfile to set HELM_DIFF_COLOR appropriately.

@evgkrsk
Copy link
Contributor

evgkrsk commented Jan 14, 2022

Seems like HELM_DIFF_COLOR=true dont working in CICD env (without control terminal) with helm-diff-3.3.2. I tried to "export TERM=xterm256" or alike, but it has no effect.

@z0rc
Copy link
Author

z0rc commented Jan 14, 2022

@evgkrsk HELM_DIFF_COLOR=true won't work with helm-diff 3.3.2. Linked changes haven't been released yet.

@evgkrsk
Copy link
Contributor

evgkrsk commented Jan 14, 2022

Oops, sorry, my fault. Waiting for helm-diff release...

@sjentzsch
Copy link
Contributor

@mumoshu Would it be possible to create a new release on databus23/helm-diff to have colors again? Really appreciated :-)

@wjentner
Copy link

I agree, the colors are very useful in CI. I personally use them to reduce the output of diff to only changed lines (after creating the full diff). It used to work beautifully before.

See example output here (gitlab CI):
image

@frank-berlin
Copy link

I would prefer that this can be done via helmDefaults.
for consistency in behavior for a team.
see #2060

there is an updated release databus23/helm-diff

@mumoshu
Copy link
Collaborator

mumoshu commented Jan 23, 2022

@frank-berlin I hear you, but I have never intended to include operational concerns into helmDefaults, so that everything included in helmfile.yaml can be entirely about releases. Probably we'll keep that, until there's any serious design discussion that convinces me.

@mumoshu
Copy link
Collaborator

mumoshu commented Jan 23, 2022

As @frank-berlin has kindly shared, the latest helm-diff release should work well with helmfile --color.
Closing as resolved but please feel free to reopen if necessary.
Thanks everyone for your cooperation!

@z0rc
Copy link
Author

z0rc commented Jan 25, 2022

the latest helm-diff release should work well with helmfile --color

I don't see this.

% helm diff version
3.4.0

% helmfile version
helmfile version v0.143.0

Running helmfile diff produces output without colors.

Running helmfile --color diff produces error Incorrect Usage. flag provided but not defined: -color and shows helmfile usage help.

Running helmfile diff --color produces error Incorrect Usage. flag provided but not defined: -color and shows helmfile diff usage help.

Running HELM_DIFF_COLOR=true helmfile diff produces colored output.

Is this expected resolution?


Additionally is it possible to make patch release of helmfile docker image, which includes updated helm-diff?

@mumoshu
Copy link
Collaborator

mumoshu commented Jan 26, 2022

Turns out I forgot the fact that it only has --no-color but --color

helmfile/pkg/state/state.go

Lines 1710 to 1712 in debd3c0

if opts.NoColor {
flags = append(flags, "--no-color")
}

That said, HELM_DIFF_COLOR=true helmfile diff might be the right way to force color! Thanks for pointing it out.

@z0rc
Copy link
Author

z0rc commented Jan 26, 2022

@mumoshu any chance to restore helmfile diff behaviour to emit colors by default when running in regular terminal? Also documentation needs an update too.

Also helmfile's --no-color is confusing and doesn't have a meaningful effect. Because helmfile doesn't emit colors anymore and HELM_DIFF_COLOR=true takes precedence when specified together with --no-color, which is just ¯\_(ツ)_/¯.

@mumoshu
Copy link
Collaborator

mumoshu commented Jan 26, 2022

@z0rc I don't have much slack in my life these days to allow me to work on it soon, but anyway, yeah I'm convinced that we should address this in helmfile side!

Almost certainly we'd need to do the term detection thing that formerly done only in helm-diff:

https://github.com/databus23/helm-diff/blob/916891fac6033c9bf1bb482041ba2066e1341ebb/cmd/root.go#L45-L65

So that helmfile is able to configure HELM_DIFF_COLOR appropriately according to the detected terminal.

@max-rocket-internet
Copy link
Contributor

Is there any workaround we can use now?

Running HELM_DIFF_COLOR=true helmfile diff produces colored output.

This does not work for me with helmdiff version 3.3.2:

export HELM_DIFF_COLOR=true
helmfile --file helmfiles/main.yaml --selector app=atlantis diff
<no color output>

@z0rc
Copy link
Author

z0rc commented Mar 29, 2022

@max-rocket-internet you need at least https://github.com/databus23/helm-diff/releases/tag/v3.4.0

@mumoshu
Copy link
Collaborator

mumoshu commented Apr 5, 2022

Hey everyone!
I don't remember the state-of-the-art of this problem but is this still the issue?
I mean, does Helmfile still needs to be enhanced to do term-detection on its own? #2043 (comment)

@lindhe
Copy link

lindhe commented Apr 5, 2022

A colleague complained about this last week, and I think he had the latest version installed. But I didn't double check, so I'm not sure...

@mumoshu
Copy link
Collaborator

mumoshu commented Apr 5, 2022

@lindhe Thanks! (Please feel free to submit a PR as always) Anyway, a known workaround would be to explicitly set HELM_DIFF_COLOR=true envvar when running helmfile.

@z0rc
Copy link
Author

z0rc commented Apr 5, 2022

I mean, does Helmfile still needs to be enhanced to do term-detection on its own? #2043 (comment)

Yes, this is still needed.

@lindhe
Copy link

lindhe commented Apr 5, 2022

Anyway, a known workaround would be to explicitly set HELM_DIFF_COLOR=true envvar when running helmfile.

Yeah. That works for me, but my colleague claims it didn't work for him. I'll double check if he did it right.

EDIT: Nope. He had a typo. It works.

mumoshu added a commit to helmfile/helmfile that referenced this issue Apr 6, 2022
Since helm-diff has added an ability to auto-detect the term to decide if it should output with color or not, helmfile had been defaulted to no-color.
This resoloves that, by adding a term-detection logic that is same as helm-diff.

As a part of this work, I have also implemented a new global flag `--color`, which is used for forcing color without relying on the term-detection logic implemented in helmfile or explicitly setting the HELM_DIFF_COLOR envvar. I hope it is useful for folks.

Ref roboll/helmfile#2043

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
Sajfer pushed a commit to Sajfer/helmfile that referenced this issue May 3, 2022
Since helm-diff has added an ability to auto-detect the term to decide if it should output with color or not, helmfile had been defaulted to no-color.
This resoloves that, by adding a term-detection logic that is same as helm-diff.

As a part of this work, I have also implemented a new global flag `--color`, which is used for forcing color without relying on the term-detection logic implemented in helmfile or explicitly setting the HELM_DIFF_COLOR envvar. I hope it is useful for folks.

Ref roboll/helmfile#2043

Signed-off-by: Yusuke Kuoka <ykuoka@gmail.com>
@mumoshu
Copy link
Collaborator

mumoshu commented Jun 5, 2022

Fixed via helmfile/helmfile#24

@mumoshu mumoshu closed this as completed Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants