Skip to content

Conversation

@kiashok
Copy link
Contributor

@kiashok kiashok commented Mar 2, 2023

This PR addresses windows images that are broken when created using the "shell form" entrypoint/cmd in Dockerfile. Associated bug - #5067
The approach taken to fix this bug is as discussed by @kevpar here - #6479 (comment)

Docker uses non-OCI field called ArgsEscaped to address how the image 'ENTRYPOINT' and 'CMD' are interpreted on windows. This PR adds support for ArgsEscaped in containerd without changes to the OCI spec and also adds changes to handle cases when image ENTRYPOINT and CMD can be overriden by 'Command' and 'Args' specified in the podspec.

The fix in this PR does the following:

Reads the ArgsEscaped value from the image got from docker without making OCI spec changes (In file image.go)
Image ENTRYPOINT and CMD fields can be overriden by the container 'Command' and 'Args' fields specified through the podspec. But the ArgsEscaped field should really only affect the behavior of the image values, and not the overall evaluation of args for the container. Therefore, we need to evaluate if the first arg in our list is coming from image entrypoint/cmd and only if it is coming from the image, we should we treat the first arg as already escaped. (in file spec.go spec_windows.go)
Regression tests have also been added to this PR.

@k8s-ci-robot
Copy link

Hi @kiashok. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@kiashok
Copy link
Contributor Author

kiashok commented Mar 2, 2023

Looks like I accidentally deleted the fork that had the branch with the changes in PR #7135 .
Addressed the following comments @dmcgowan left this morning and wanted to submit new changes and realized this.
#7135 (comment)
#7135 (comment)
#7135 (comment)

I was unable to add the new changes to the old PR #7135 , so I closed it and created this new one. Apologies for this!

@dmcgowan @dcantah The only changes this PR in addition to PR #7135 are the following:

  • Change function name WithProcessCommandLineOrArgs() to WithProcessCommandLineOrArgsForWindows()
  • In [pkg/cri/opts/spec_nonwindows.go] , panic() was removed from WithProcessCommandLineOrArgsForWindows() and updated to the following:

func WithProcessCommandLineOrArgsForWindows(config *runtime.ContainerConfig, image *imagespec.ImageConfig) oci.SpecOpts {
return func(ctx context.Context, client oci.Client, c *containers.Container, s *runtimespec.Spec) (err error) {
return errdefs.ErrNotImplemented
}
}

Could you please take a look at this PR instead for this work? Thanks a lot!

@dcantah dcantah added this to the 1.7 milestone Mar 2, 2023
@dcantah
Copy link
Member

dcantah commented Mar 3, 2023

@kiashok Can you look at the linter issues?

@dcantah dcantah requested review from dcantah, dmcgowan and kevpar March 3, 2023 00:16
@dcantah
Copy link
Member

dcantah commented Mar 3, 2023

@kevpar Added you as a reviewer as you were on the old one, lets try and land this for 1.7

@dcantah
Copy link
Member

dcantah commented Mar 3, 2023

Check failure on line 22 in pkg/cri/opts/spec_nonwindows.go
File is not `goimports`-ed (goimports)

The linter run wasn't loading for me, but the annotations did; that seems to be what the CI is whining about

@kiashok kiashok force-pushed the argsEscapedSupportInCri branch from 6db0bc0 to 8675e91 Compare March 3, 2023 17:46
@kiashok
Copy link
Contributor Author

kiashok commented Mar 3, 2023

Check failure on line 22 in pkg/cri/opts/spec_nonwindows.go
File is not `goimports`-ed (goimports)

The linter run wasn't loading for me, but the annotations did; that seems to be what the CI is whining about

@dcantah took care of this and the tests are passing

Comment on lines +90 to +93
// Ctr entrypoint ctr cmd image entrypoint image cmd firstArgFromImg
// --------------------------------------------------------------------------------
// nil nil exists nil true
// nil nil nil exists true
Copy link
Member

Choose a reason for hiding this comment

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

This is all oddly formatted

Copy link
Member

Choose a reason for hiding this comment

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

(spaces/tabs seem to be screwed up)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Shows up alright on vscode for me. Not sure whats happening in the PR

Copy link
Member

@dcantah dcantah left a comment

Choose a reason for hiding this comment

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

Two small things, LGTM

This commit adds supports for the ArgsEscaped
value for the image got from the dockerfile.
It is used to evaluate and process the image
entrypoint/cmd and container entrypoint/cmd
options got from the podspec.

Signed-off-by: Kirtana Ashok <[email protected]>
@kiashok kiashok force-pushed the argsEscapedSupportInCri branch from 8675e91 to 8137e41 Compare March 3, 2023 21:38
@fuweid fuweid merged commit 5ae3a7f into containerd:main Mar 7, 2023
@ericpaulsen
Copy link

@kiashok would this commit address the issue outlined here? coder/coder#6657

jsturtevant added a commit to jsturtevant/containerd that referenced this pull request Nov 1, 2023
The PR containerd#8198 fixed this for CRI but missed clearing the commandline in the forked SB server. This simply adds that back in

Signed-off-by: James Sturtevant <[email protected]>
juliusl pushed a commit to juliusl/containerd that referenced this pull request Jan 26, 2024
The PR containerd#8198 fixed this for CRI but missed clearing the commandline in the forked SB server. This simply adds that back in

Signed-off-by: James Sturtevant <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants