Skip to content

fix oci.WithImageConfigArgs for windows#2887

Merged
crosbymichael merged 3 commits intocontainerd:masterfrom
andrey-ko:args-fix
Jan 7, 2019
Merged

fix oci.WithImageConfigArgs for windows#2887
crosbymichael merged 3 commits intocontainerd:masterfrom
andrey-ko:args-fix

Conversation

@andrey-ko
Copy link
Copy Markdown
Contributor

fix parameters passing for windows when use oci.WithImageConfigArgs

@codecov-io
Copy link
Copy Markdown

codecov-io commented Dec 18, 2018

Codecov Report

Merging #2887 into master will decrease coverage by 3.3%.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2887      +/-   ##
==========================================
- Coverage    47.5%   44.19%   -3.31%     
==========================================
  Files          91      101      +10     
  Lines        8460    10808    +2348     
==========================================
+ Hits         4019     4777     +758     
- Misses       3717     5297    +1580     
- Partials      724      734      +10
Flag Coverage Δ
#linux 47.83% <93.75%> (+0.33%) ⬆️
#windows 41.41% <94.44%> (?)
Impacted Files Coverage Δ
oci/spec_opts.go 27.06% <94.44%> (+4.71%) ⬆️
snapshots/native/native.go 43.3% <0%> (-10%) ⬇️
metadata/snapshot.go 45.8% <0%> (-8.96%) ⬇️
archive/tar.go 43.79% <0%> (-7.07%) ⬇️
metadata/containers.go 47.97% <0%> (-6.62%) ⬇️
content/local/writer.go 57.84% <0%> (-6.36%) ⬇️
content/local/store.go 48.51% <0%> (-5.03%) ⬇️
archive/tar_opts.go 28.57% <0%> (-4.77%) ⬇️
archive/compression/compression.go 58.69% <0%> (-4.7%) ⬇️
metadata/images.go 58.46% <0%> (-4.7%) ⬇️
... and 58 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 06e04bc...1be86af. Read the comment docs.

Copy link
Copy Markdown

@ddebroy ddebroy left a comment

Choose a reason for hiding this comment

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

Couple of questions below.

Comment thread oci/spec_opts.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should there be a test for config.WorkingDir == "" to default it to C:\ for Windows as it's done from Linux above in L321?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought it make some sense to have "" value, assuming it has meaning "unspecified" to bypass it father and something later will know what exactly it means. In other words I wasn't sure if it is right place to do it. So should I add this test here?

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.

What do you need to change the existing code? Seems like all that is new is the s.Process.Cwd = config.WorkingDir. Doesn't config.Cmd... expand properly to zero automatically by golang?

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.

Seems the model is inconsistent already. We should likely be using replaceOrAppendEnvValues everywhere. But at a minimum I think yes we should be appending here too otherwise call order would really matter for env's.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmm, when we use replaceOrAppendEnvValues, what should override what? s.Process.Env should override config.Env or opposite config.Env overrides s.Process.Env ? In other words it should be:
s.Process.Env = replaceOrAppendEnvValues(s.Process.Env, config.Env)
or
s.Process.Env = replaceOrAppendEnvValues(config.Env, s.Process.Env)
?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

also should we check if current working directory was already set or override it no matter what?

cwd := config.WorkingDir
if cwd == "" {
   cwd = "/"
}
s.Process.Cwd = cwd

or

if s.Process.Cwd != "" {
  s.Process.Cwd = config.WorkingDir
}

more specifically, say we have image:

FROM ...
...
WORKDIR "/bin"

then we create container with options:

opts := []oci.SpecOpts{
  WithProcessCwd("/app"),
  WithImageConfig(image)
}

what should be current working directory for this container "/app" or "/bin"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added following changes:
WithImageConfigArgs will override env,args,cwd of all previous WithXxx calls.
env will be merged using replaceOrAppendEnvValues instead of append.
args,cwd will be just replaced

Comment thread oci/spec_opts.go Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should s.Process.Env be appended to ^ as done for Linux in L313?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hard to answer for me actually, as I have arguments "for" and "against". So on one hand it was like this before but on other hand why do we have different behavior for linux and windows? Also why do we have different "merge"/"apply" behaviors, so all other parameters we replace/override, but for env we use "append" behavior, what are use cases to have this exception?

@andrey-ko andrey-ko force-pushed the args-fix branch 4 times, most recently from c8b400d to bfda164 Compare December 20, 2018 00:01
@andrey-ko andrey-ko force-pushed the args-fix branch 5 times, most recently from 7f28ff6 to cb140b8 Compare December 21, 2018 00:09
Signed-off-by: Andrey Kolomentsev <[email protected]>
@ddebroy
Copy link
Copy Markdown

ddebroy commented Dec 21, 2018

LGTM from me. @crosbymichael @jterry75 PTAL

Copy link
Copy Markdown
Contributor

@jterry75 jterry75 left a comment

Choose a reason for hiding this comment

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

LGTM. Appreciate the tests!

@crosbymichael
Copy link
Copy Markdown
Member

LGTM

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.

6 participants