fix(env): ensure BackendRuntimeConfig.Envs overrides base Envs#341
Merged
InftyAI-Agent merged 1 commit intoInftyAI:mainfrom Apr 17, 2025
Merged
fix(env): ensure BackendRuntimeConfig.Envs overrides base Envs#341InftyAI-Agent merged 1 commit intoInftyAI:mainfrom
InftyAI-Agent merged 1 commit intoInftyAI:mainfrom
Conversation
nayihz
reviewed
Apr 15, 2025
Comment on lines
+55
to
+59
| result := make([]corev1.EnvVar, 0, len(envMap)) | ||
| for _, env := range envMap { | ||
| result = append(result, env) | ||
| } | ||
| return result |
Contributor
There was a problem hiding this comment.
import maps and then
Suggested change
| result := make([]corev1.EnvVar, 0, len(envMap)) | |
| for _, env := range envMap { | |
| result = append(result, env) | |
| } | |
| return result | |
| return maps.Values(envMap) |
Member
Author
There was a problem hiding this comment.
maps.Values(envMap) returns an iterator instead of a slice object, we still need to iterate over it, something like this.
result := make([]corev1.EnvVar, 0, len(envMap))
for env := range maps.Values(envMap) {
result = append(result, env)
}
return result
kerthcet
reviewed
Apr 17, 2025
| envs := parser.Envs() | ||
| if playground.Spec.BackendRuntimeConfig != nil { | ||
| envs = append(envs, playground.Spec.BackendRuntimeConfig.Envs...) | ||
| envs = util.MergeEnvs(envs, playground.Spec.BackendRuntimeConfig.Envs) |
Member
There was a problem hiding this comment.
I think even we didn't merge them, still work here because the latter env will overwrite the former ones, but merge them makes it more clear. Thanks!
pkg/util/util_test.go
Outdated
| }, | ||
| want: []corev1.EnvVar{ | ||
| {Name: "VAR1", Value: "value1"}, | ||
| {Name: "VAR2", Value: "new_value2"}, // 被覆盖 |
Signed-off-by: googs1025 <googs1025@gmail.com>
Member
|
/lgtm |
Member
|
/kind cleanup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it
playground.Spec.BackendRuntimeConfig.Envsis set by the user. There is a high probability that Envs is the same asBackendRuntime.Spec.Envs. We should use the overwrite method instead of just appending.Which issue(s) this PR fixes
Fixes None
Special notes for your reviewer
Does this PR introduce a user-facing change?