Skip to content

Feat: Add color output functionality and tests for release statuses - #31034

Merged
gjenkins8 merged 10 commits into
helm:mainfrom
Mazafard:feat/color-output-and-test-fixes
Aug 5, 2025
Merged

gjenkins8 merged 10 commits into
helm:mainfrom
Mazafard:feat/color-output-and-test-fixes

Conversation

@Mazafard

@Mazafard Mazafard commented Jul 7, 2025 •

Copy link
Copy Markdown
Contributor

closes #31031

What this PR does / why we need it:

This PR introduces ANSI color support to Helm CLI output to improve human readability and align Helm with modern CLI UX practices. The implementation addresses the feature request in #31031 for colorful CLI output, which is now standard in many popular DevOps tools (e.g., kubectl, docker, git, terraform).

Note: This is a clean resubmission of PR #31032 which was closed due to merge conflicts with the main branch. This PR contains the same functionality but is properly rebased on the latest upstream/main.

Key Features:

  • Automatic color support: Colors are enabled by default for interactive terminals
  • Smart TTY detection: Automatically disables colors when output is piped to files or non-interactive contexts using term.IsTerminal()
  • Opt-out mechanism: Users can disable colors using the --no-color flag or NO_COLOR environment variable
  • Targeted implementation: Adds color support to release status displays across multiple commands

Implementation Details:

  • Added a new color output module (pkg/cli/output/color.go) with functions for colorizing status, headers, and namespaces
  • Integrated --no-color flag support in the CLI environment settings
  • Added color formatting to commands: helm status, helm list, helm install, helm upgrade, helm get all, and helm test
  • Created unit tests (219 lines) to ensure color formatting works correctly
  • Uses the fatih/color library for ANSI color support
  • Removed unused ColorEnabled() function to clean up the codebase

Benefits:

  • Improved readability: Visual distinction for release statuses (deployed in green, failed in red, pending in yellow)
  • Better debugging: Easier to spot issues during CI/CD or release debugging
  • Enhanced developer experience: Bold headers and colored namespaces help users quickly parse output
  • Modern CLI UX: Aligns Helm with other popular DevOps tools while maintaining backward compatibility

Special notes for your reviewer:

The current implementation provides a foundation for color support with the following color scheme:

  • Green: Deployed/successful releases
  • Red: Failed releases or unknown status
  • Yellow: Pending operations (install, upgrade, rollback, uninstalling)
  • Bold: Headers for better readability
  • Cyan: Namespaces to distinguish them from other text
  • Default: Uninstalled, superseded, and other statuses remain uncolored

The implementation respects terminal capabilities through TTY detection and honors the NO_COLOR environment variable standard. All color output can be disabled using the --no-color flag or by setting the NO_COLOR environment variable, ensuring full backward compatibility for automation and scripting use cases.

Note: While issue #31031 mentioned opt-in colors (disabled by default), this implementation enables colors by default for interactive terminals, following the pattern of modern CLI tools. The opt-out mechanism via --no-color flag provides the necessary control for users who prefer no colors.

Updated based on review feedback: Changed the default color mode from "never" to "auto" to enable colors by default for interactive terminals, following team consensus for the v4 release.

Changes Made

New Files:

  • pkg/cli/output/color.go - Color formatting functions
  • pkg/cli/output/color_test.go - Comprehensive unit tests

Modified Files:

  • pkg/cli/environment.go - Added ColorMode field, --color flag support, and envColorMode() function
  • Updated: Changed default color mode from "never" to "auto"
  • Updated: Removed unused ColorEnabled() function
  • cmd/helm/status.go - Colorized status output
  • cmd/helm/list.go - Colorized list output
  • cmd/helm/install.go - Colorized install status
  • cmd/helm/upgrade.go - Colorized upgrade status
  • cmd/helm/get_all.go - Colorized get all output
  • cmd/helm/release_testing.go - Colorized test results

Additional Fixes:

  • Replaced os.Setenv() with t.Setenv() in test files to comply with golangci-lint recommendations
  • Fixed usetesting linter warnings for better test isolation

If applicable:

  • this PR contains user facing changes (the docs needed label should be applied if so)
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

Testing

  • All unit tests pass
  • Tested with NO_COLOR environment variable
  • Tested with HELM_COLOR environment variable (never/auto/always)
  • Verified color output in different terminals (iTerm2, Terminal.app, VS Code terminal)
  • Tested piping output to files (colors correctly disabled)
  • Verified with golangci-lint v2.1.0
  • Tested --color flag with all values (never/auto/always)

@pull-request-size pull-request-size Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 7, 2025
@robertsirc

Copy link
Copy Markdown
Member

So, first thing thank you for the PR. I have a questions to the other maintainers on --no-color and if that should be on by default or off by default. Besides that this looks good from my side. I was able to test this and it works as expected.

robertsirc
robertsirc previously approved these changes Jul 8, 2025

@robertsirc robertsirc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@robertsirc robertsirc added the Has One Approval This PR has one approval. It still needs a second approval to be merged. label Jul 8, 2025

@gjenkins8 gjenkins8 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some initial comments.

Requesting change to make the output package internal (unless there is a very good reason we think it should be public?)

Comment thread pkg/cli/output/color.go Resolved
Comment thread pkg/cli/environment.go Resolved
Comment thread pkg/cli/output/color.go Resolved
Comment thread pkg/cli/output/color.go Resolved
Comment thread pkg/cli/output/color.go Resolved
@gjenkins8

Copy link
Copy Markdown
Member

So, first thing thank you for the PR. I have a questions to the other maintainers on --no-color and if that should be on by default or off by default. Besides that this looks good from my side. I was able to test this and it works as expected.

Loosely held opinion -- I think off by default, until the majority of Helm commands support colorized output.

@Mazafard

Copy link
Copy Markdown
Contributor Author

Some initial comments.

Requesting change to make the output package internal (unless there is a very good reason we think it should be public?)

Thank you for the review @gjenkins8 , Could you clarify what you mean by making the package public? The output package was already public. I just added functions to it since it seemed like the most relevant place for output-related code.
I don't think moving the output package would be wise as it would require extensive changes throughout the codebase.

Comment thread pkg/cli/environment.go Resolved
Comment thread pkg/cli/environment.go Resolved
@Mazafard
Mazafard requested review from gjenkins8 and joejulian July 23, 2025 22:07
@Mazafard

Copy link
Copy Markdown
Contributor Author

@gjenkins8 @joejulian @robertsirc Would you mind taking a look when you get a chance?

@robertsirc robertsirc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@gjenkins8
gjenkins8 merged commit 18b7d45 into helm:main Aug 5, 2025
@gjenkins8

Copy link
Copy Markdown
Member

thanks!

@scottrigby scottrigby removed the Has One Approval This PR has one approval. It still needs a second approval to be merged. label Nov 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature 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.

Add optional color support to Helm CLI output

5 participants