Skip to content

fix: correct lookup for environment variables in cache#808

Open
Skywalkr-dev wants to merge 1 commit into
opencontainers:masterfrom
Skywalkr-dev:fix-env-lookup
Open

fix: correct lookup for environment variables in cache#808
Skywalkr-dev wants to merge 1 commit into
opencontainers:masterfrom
Skywalkr-dev:fix-env-lookup

Conversation

@Skywalkr-dev
Copy link
Copy Markdown

@Skywalkr-dev Skywalkr-dev commented May 22, 2026

The current implementation keys the environment cache by the full "NAME=VALUE" string. This causes the generator to treat updates to existing variables as new entries, leading to duplicate environment variables in the final configuration.

This change switches the cache key to use only the variable name, ensuring that AddProcessEnv correctly updates existing values instead of appending them.

FIXES: #798
Signed-off-by: Skywalkr-dev snaveenbharath2005@gmail.com

Copy link
Copy Markdown
Contributor

@kolyshkin kolyshkin left a comment

Choose a reason for hiding this comment

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

You need to fix the commit subject.

@Skywalkr-dev Skywalkr-dev force-pushed the fix-env-lookup branch 2 times, most recently from 432d54b to 5fcbb0f Compare May 22, 2026 19:57
@Skywalkr-dev
Copy link
Copy Markdown
Author

@kolyshkin sorry about the commit, does the current commit subject work

Comment thread generate/generate.go Outdated
Comment on lines +325 to +330
name, _, found := strings.Cut(val, "=")
if found {
envMap[name] = i
} else {
// Fallback for variables without an '=' (rare, but possible)
envMap[val] = i
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: this can be simplified to a one-line patch:

 for i, val := range env {
+  val, _, _ = strings.Cut(val, "=")
   envMap[val] = i

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

nit: this can be simplified to a one-line patch:

 for i, val := range env {
+  val, _, _ = strings.Cut(val, "=")
   envMap[val] = i

yup, that's much cleaner. I've updated the PR to use strings.Cut as suggested.

The current implementation keys the environment cache by the full
"NAME=VALUE" string. This causes the generator to treat updates to
existing variables as new entries, leading to duplicate environment
variables in the final configuration.

This change switches the cache key to use only the variable name,
ensuring that AddProcessEnv correctly updates existing values
instead of appending them.

Fixes opencontainers#798

Signed-off-by: Skywalkr-dev <snaveenbharath2005@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in createEnvCacheMap()

2 participants