-
-
Notifications
You must be signed in to change notification settings - Fork 44
fix(env): ensure BackendRuntimeConfig.Envs overrides base Envs #341
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
Conversation
| result := make([]corev1.EnvVar, 0, len(envMap)) | ||
| for _, env := range envMap { | ||
| result = append(result, env) | ||
| } | ||
| return result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import maps and then
| result := make([]corev1.EnvVar, 0, len(envMap)) | |
| for _, env := range envMap { | |
| result = append(result, env) | |
| } | |
| return result | |
| return maps.Values(envMap) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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| envs := parser.Envs() | ||
| if playground.Spec.BackendRuntimeConfig != nil { | ||
| envs = append(envs, playground.Spec.BackendRuntimeConfig.Envs...) | ||
| envs = util.MergeEnvs(envs, playground.Spec.BackendRuntimeConfig.Envs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"}, // 被覆盖 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No chinese here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad... remove
Signed-off-by: googs1025 <[email protected]>
|
/lgtm |
|
/kind cleanup |
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?