Skip to content

Conversation

@aslafy-z
Copy link
Contributor

@aslafy-z aslafy-z commented Dec 6, 2025

What this PR does / why we need it:
This PR restores Helm settings environment variables for getter plugins.

Commits:

  1. Pass environment variables from CLI settings to getter plugins - Calls settings.EnvVars() in collectGetterPlugins() to pass Helm environment to plugins
  2. Fix nil pointer dereference in EnvSettings.Namespace() - Pre-existing bug triggered when EnvVars() is called on uninitialized EnvSettings (e.g., &cli.EnvSettings{} instead of cli.New())

Fixes #31612
Closes #31611

Special notes for your reviewer:
The nil check fix addresses a pre-existing bug in main - calling EnvVars() on &cli.EnvSettings{} panics because s.config is nil. Existing tests using &cli.EnvSettings{} didn't trigger this because they never entered a code path that called EnvVars().

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

@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 6, 2025
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 6, 2025
Copy link
Contributor

@benoittgt benoittgt left a comment

Choose a reason for hiding this comment

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

Thanks for the clear issue. Maybe we could add tests.

@aslafy-z aslafy-z marked this pull request as draft December 7, 2025 09:00
@aslafy-z aslafy-z marked this pull request as ready for review December 7, 2025 16:22
@aslafy-z aslafy-z requested a review from benoittgt December 7, 2025 16:22
require.True(t, ok, "expected getter to be a *getterPlugin")

require.NotEmpty(t, gp.env, "expected env to be set on getterPlugin")
envMap := plugin.ParseEnv(gp.env)
Copy link
Contributor

Choose a reason for hiding this comment

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

ParseEnv is exposed just for this test. It is an internal package though, so not as big a deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you want me to duplicate the logic instead, I can. I thought it would not be an issue to publish it as it is an internal package.

@benoittgt
Copy link
Contributor

I just tested on macOS, and it works as expected with the patch. I used the reproduction script from the issue: #31612 (comment)

LGTM

@aslafy-z
Copy link
Contributor Author

Hi maintainers,

This PR fixes the downloader plugin env regression introduced by #31145 (missing HELM_* env vars), which is currently blocking some downloader plugins (example + repro in #31612).

Do you have an ETA for merge, and (if accepted) is this something you would consider backporting to the next 4.0.x patch release? The v4.0.4 release notes say 4.0.5 is planned for Jan 14, 2026 (and 4.1.0 for Jan 21, 2026). If a backport is needed, I'm happy to help prepare it.

@benoittgt would you agree to mention some other maintainer?

Thanks!

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes getter plugins to properly receive Helm settings environment variables and prevents a nil pointer dereference in EnvSettings.Namespace(). The changes ensure that environment variables like HELM_DEBUG, HELM_PLUGINS, and others are correctly propagated to getter plugins during execution.

Key Changes:

  • Environment variables from CLI settings are now passed to getter plugins via the plugin.Input.Env field
  • Added nil check for s.config in EnvSettings.Namespace() to prevent panic when method is called on uninitialized instances
  • Exported parseEnv and formatEnv functions to ParseEnv and FormatEnv for external package usage

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/getter/plugingetter.go Captures environment variables from settings and passes them to getter plugins through the getterPlugin struct
pkg/getter/plugingetter_test.go Adds test to verify environment variables are correctly passed to getter plugins and accessible
pkg/cli/environment.go Adds nil check for config field to prevent panic in Namespace() when called via EnvVars() on uninitialized instances
internal/plugin/runtime.go Exports parseEnv and formatEnv functions to ParseEnv and FormatEnv with added documentation
internal/plugin/runtime_test.go Updates test calls to use exported ParseEnv and FormatEnv function names
internal/plugin/runtime_subprocess.go Updates all call sites to use exported ParseEnv and FormatEnv functions
internal/plugin/runtime_subprocess_getter.go Updates call sites to use exported ParseEnv and FormatEnv functions
internal/plugin/runtime_extismv1.go Updates call site to use exported ParseEnv function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +277 to +280
if s.config != nil {
if ns, _, err := s.config.ToRawKubeConfigLoader().Namespace(); err == nil {
return ns
}
Copy link

Copilot AI Dec 14, 2025

Choose a reason for hiding this comment

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

The nil check for s.config prevents a panic when EnvVars() is called on an uninitialized EnvSettings instance. Consider adding a test case that verifies this behavior, such as calling (&EnvSettings{}).EnvVars() or (&EnvSettings{}).Namespace() to ensure the nil check works correctly and doesn't panic.

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@TerryHowe TerryHowe left a comment

Choose a reason for hiding this comment

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

/lgtm

@aslafy-z
Copy link
Contributor Author

aslafy-z commented Jan 7, 2026

/cc @banjoh @gjenkins8 @joejulian @mattfarina @robertsirc @sabre1041 @scottrigby @technosophos @TerryHowe

Can you please give it a look?
Sorry for this massive ping, I'm not aware of another way to increase visibility before the release date hits.

@robertsirc
Copy link
Member

You can find us on slack you know.

Copy link
Contributor

@banjoh banjoh left a comment

Choose a reason for hiding this comment

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

LGTM

@TerryHowe TerryHowe merged commit 429ce93 into helm:main Jan 7, 2026
11 checks passed
@aslafy-z aslafy-z deleted the feat/getter-env branch January 7, 2026 14:54
@aslafy-z
Copy link
Contributor Author

aslafy-z commented Jan 7, 2026

Thank you @TerryHowe @banjoh
Will it be automatically included into the next patch?

@banjoh
Copy link
Contributor

banjoh commented Jan 7, 2026

Will it be automatically included into the next patch?

It should

@scottrigby scottrigby added bug Categorizes issue or PR as related to a bug. needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. labels Jan 12, 2026
@scottrigby scottrigby added this to the 4.0.5 milestone Jan 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Categorizes issue or PR as related to a bug. needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in downloader plugins environment

6 participants