-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix up handling of environment variables #21
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
03a39d5 to
e62e915
Compare
|
☔ The latest upstream changes (presumably a39ec62) made this pull request unmergeable. Please resolve the merge conflicts. |
6d8b817 to
f32d70f
Compare
a8d798b to
89a39a1
Compare
|
☔ The latest upstream changes (presumably #47) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@baude @mheon @umohnani8 PTAL |
cmd/kpod/create_cli.go
Outdated
| @@ -26,25 +26,6 @@ func getAllLabels(labelFile, inputLabels []string) (map[string]string, error) { | |||
| return labels, nil | |||
| } | |||
|
|
|||
| func getAllEnvironmentVariables(envFiles, envInput []string) ([]string, error) { | |||
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.
Curious as to why you're breaking this up. It doesn't seem necessary to completely refactor it out - can we just pass in a spec generator and not return anything?
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 am not breaking anything up? I removed a non useful function, that was throwing errors on
--env foo, commands, If you want me to make a separate function for the spec file generation, I can do that.
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.
Alright, fair enough. Would be difficult to test anyways, given that we'd only be modifying the spec generator.
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.
@mheon These three lines replace the getAllEnvironmentVariables.
- env, err := getAllEnvironmentVariables(c.StringSlice("env-file"), c.StringSlice("env"))
+ env, err := readKVStrings(c.StringSlice("env-file"), c.StringSlice("env"))
if err != nil {
return &createConfig{}, errors.Wrapf(err, "unable to process environment variables")
}
+ env = append(defaultEnvVariables, env...)
cmd/kpod/spec.go
Outdated
| @@ -124,6 +128,22 @@ func createConfigToOCISpec(config *createConfig) (*spec.Spec, error) { | |||
| g.AddTmpfsMount(spliti[0], options) | |||
| } | |||
|
|
|||
| for _, i := range config.env { | |||
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.
Did you decide to not append the defaultEnvVariables if none were found? i.e. line 34 from the deleted section of create_cli.go above.
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.
We are always setting the default environment above in the patch.
-
env = append(defaultEnvVariables, env...)
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 don't think the check is necessary, given that appending an empty array is a no-op
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.
Missed that, thx, I'll blame the cold meds.
test/kpod_run.bats
Outdated
|
|
||
| @test "run environment test" { | ||
|
|
||
| # run bash -c "${KPOD_BINARY} ${KPOD_OPTIONS} run ${ALPINE} sh -c printenv | grep HOSTNAME" |
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.
Curious why this is commented out?
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.
We don't set the hostname in our containers since we are not using networks yet. As soon as we have network support for kpod run, we can uncomment this. I will add a comment on this.
cmd/kpod/create.go
Outdated
| if err != nil { | ||
| return &createConfig{}, errors.Wrapf(err, "unable to process environment variables") | ||
| } | ||
| env = append(defaultEnvVariables, env...) |
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.
Nit: this seems a little backward - usually would do append(env, defaultEnvVariables...) to make it more clear. Doesn't actually effect the results just a style preference
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 did it this way so that if path is defined in defaultEnvVariables and in --env path, then the second path will replace the first path.
If I reverse then the user would not be able to override the defaults.
|
One nit, otherwise LGTM. Though I am also curious why part of the environment tests is commented out. |
|
I reworked the function to setupEnvironment in spec.go, added a comment about the HOSTNAME check being commented out. |
|
@rhatdan looks like you're getting bit by some travis environment bogosity. |
TomSweeneyRedHat
left a comment
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.
LGTM once Travis gets happy. I don't think it's issues are due to this change.
|
bot retest |
|
bot retry please |
d99a6f6 to
bd56d9f
Compare
|
@jlebon @cgwalters Is there a way to keep the test image around, so we can log in and take a look around. We can not seem to get this failure on the centos machine we run and the error does not happen in travis or in the Fedora test machine. The error we are seeing happens when the runc RuntimeSpec version does not match the kpod RunTime Spec version, and yet the rpm values look correct. |
|
Not currently, though you should be able to reproduce the same environment by starting from the same image it uses. But maybe first, let's move away from The corresponding image can be downloaded here to test locally: https://ci.centos.org/artifacts/sig-atomic/centos-continuous/images-smoketested/cloud/latest/images/. |
The way docker works is if a user specifies a non `-e Name=Value`, IE just a `-e Name`, then the environment variable Name from the clients OS.ENV is used. Also by default Docker containers run with the HOSTNAME environment set to the HOSTNAME specified for the container. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
|
Ok trying with smoketested |
|
⚡ Test exempted: merge already tested. |
The way docker works is if a user specifies a non
-e Name=Value, IEjust a
-e Name, then the environment variable Name from the clientsOS.ENV is used.
Also by default Docker containers run with the HOSTNAME environment set
to the HOSTNAME specified for the container.
Signed-off-by: Daniel J Walsh dwalsh@redhat.com