Skip to content

Conversation

@rhatdan
Copy link
Member

@rhatdan rhatdan commented Nov 6, 2017

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

@rhatdan rhatdan force-pushed the generate branch 5 times, most recently from 03a39d5 to e62e915 Compare November 6, 2017 23:37
@rh-atomic-bot
Copy link
Collaborator

☔ The latest upstream changes (presumably a39ec62) made this pull request unmergeable. Please resolve the merge conflicts.

@rhatdan rhatdan force-pushed the generate branch 2 times, most recently from 6d8b817 to f32d70f Compare November 8, 2017 20:51
@rhatdan rhatdan changed the title Fix up handling of environment variables [WIP] Fix up handling of environment variables Nov 9, 2017
@rhatdan rhatdan force-pushed the generate branch 2 times, most recently from a8d798b to 89a39a1 Compare November 12, 2017 11:34
@rhatdan rhatdan mentioned this pull request Nov 13, 2017
@rh-atomic-bot
Copy link
Collaborator

☔ The latest upstream changes (presumably #47) made this pull request unmergeable. Please resolve the merge conflicts.

@rhatdan rhatdan changed the title [WIP] Fix up handling of environment variables Fix up handling of environment variables Nov 15, 2017
@rhatdan
Copy link
Member Author

rhatdan commented Nov 15, 2017

@baude @mheon @umohnani8 PTAL

@@ -26,25 +26,6 @@ func getAllLabels(labelFile, inputLabels []string) (map[string]string, error) {
return labels, nil
}

func getAllEnvironmentVariables(envFiles, envInput []string) ([]string, error) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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 {
Copy link
Member

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.

Copy link
Member Author

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...)
    

Copy link
Member

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

Copy link
Member

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 "run environment test" {

# run bash -c "${KPOD_BINARY} ${KPOD_OPTIONS} run ${ALPINE} sh -c printenv | grep HOSTNAME"
Copy link
Member

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?

Copy link
Member Author

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.

if err != nil {
return &createConfig{}, errors.Wrapf(err, "unable to process environment variables")
}
env = append(defaultEnvVariables, env...)
Copy link
Member

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

Copy link
Member Author

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.

@mheon
Copy link
Member

mheon commented Nov 16, 2017

One nit, otherwise LGTM. Though I am also curious why part of the environment tests is commented out.

@rhatdan
Copy link
Member Author

rhatdan commented Nov 16, 2017

I reworked the function to setupEnvironment in spec.go, added a comment about the HOSTNAME check being commented out.
Added a test to make sure PATH= is overriden defaultEnvironment.

@TomSweeneyRedHat
Copy link
Member

@rhatdan looks like you're getting bit by some travis environment bogosity.

Copy link
Member

@TomSweeneyRedHat TomSweeneyRedHat left a 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.

@rhatdan
Copy link
Member Author

rhatdan commented Nov 17, 2017

bot retest

@rhatdan
Copy link
Member Author

rhatdan commented Nov 17, 2017

bot retry please

@rhatdan rhatdan force-pushed the generate branch 13 times, most recently from d99a6f6 to bd56d9f Compare November 18, 2017 12:08
@rhatdan
Copy link
Member Author

rhatdan commented Nov 19, 2017

@jlebon @cgwalters Is there a way to keep the test image around, so we can log in and take a look around.
We are getting strange behaviour on the Centos test AMI, we think there could be a mismatch or some issue with the runc being used on this box.

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.

@jlebon
Copy link
Contributor

jlebon commented Nov 19, 2017

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 centos/7/atomic/alpha? It's no longer updated and the image there is pretty old 🕸 by now. Try centos/7/atomic/smoketested ✨ instead!

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>
@rhatdan
Copy link
Member Author

rhatdan commented Nov 20, 2017

Ok trying with smoketested

@rhatdan
Copy link
Member Author

rhatdan commented Nov 20, 2017

@baude @mheon PTAL

@baude
Copy link
Member

baude commented Nov 20, 2017

@rh-atomic-bot r+ da86799

@rh-atomic-bot
Copy link
Collaborator

⚡ Test exempted: merge already tested.

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants