Skip to content
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

Pass cwd for hooks exec run function #4871

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fangpenlin
Copy link

@fangpenlin fangpenlin commented Jun 16, 2023

What type of PR is this?

For fixing the wrong cwd bug in podman:

containers/podman#18907

/kind bug

What this PR does / why we need it:

I added a new cwd argument for run hooks in common package:

containers/common#1514

for fixing cwd not set bug of poststop hook exec run in podman:

containers/podman#18907

It seems like buildah also depends on the same function and also call hooks exec, so this PR fixes the issue altogether.

How to verify it

Run unit tests

Which issue(s) this PR fixes:

Fixes containers/podman#18907

Special notes for your reviewer:

This PR depends on containers/common#1514 to be merged. Sorry first time contributor, I am not sure what's the correct workflow to make changes in upstream common repo. I assume I should create a new PR in common repo first, then wait for a new release from common then update the vendor file in this repo to make it depends on the changes I made in common?

Does this PR introduce a user-facing change?

Yes, after this PR merged, the cwd of hook exec called by buildah will be the bundle dir (the one containing OCI spec config.json file) instead of current cwd from invoking buildah command.

Hook executables invoked by buildah run command now come with the correct working directory pointing to the container bundle directory

@fangpenlin fangpenlin changed the title WIP: Pass cwd for hooks exec run function Pass cwd for hooks exec run function Jun 17, 2023
@fangpenlin fangpenlin force-pushed the pass-cwd-for-hooks-exec-run-func branch from 3289545 to 4092e4e Compare June 23, 2023 18:31
@TomSweeneyRedHat
Copy link
Member

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 26, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fangpenlin, TomSweeneyRedHat

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@TomSweeneyRedHat
Copy link
Member

Now that containers/common#1521 has merged, are there adjustments necessary for this PR?

@fangpenlin
Copy link
Author

@TomSweeneyRedHat yeah, changes are needed, I will update it later tonight

@fangpenlin fangpenlin force-pushed the pass-cwd-for-hooks-exec-run-func branch from 4092e4e to d4204e8 Compare June 27, 2023 06:40
@fangpenlin
Copy link
Author

@TomSweeneyRedHat I have updated the PR with the new method I added in common lib.
But it seems like a new release was not made yet from there

containers/common#1524

I guess I can only wait until they merge it and make a new one then? By the way, should I check-in vendor changes in my PR? I saw that they were not excluded from the Git repo

@rhatdan
Copy link
Member

rhatdan commented Jun 27, 2023

@fangpenlin This needs a rebase.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 28, 2023
@fangpenlin fangpenlin force-pushed the pass-cwd-for-hooks-exec-run-func branch from d4204e8 to 66d5fe4 Compare June 28, 2023 16:59
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 28, 2023
@fangpenlin
Copy link
Author

@rhatdan Rebased. But I saw there's a //nolint:staticcheck comment seems like disabling lint check or what? Not sure what's it for, should I add the same thing to my changes?

@rhatdan
Copy link
Member

rhatdan commented Jun 28, 2023

I would only worry about the lint check if lint is blowing up. Looks like tests are failing though.

@fangpenlin fangpenlin force-pushed the pass-cwd-for-hooks-exec-run-func branch 2 times, most recently from 6185ee6 to 715ae4d Compare June 28, 2023 19:05
@TomSweeneyRedHat
Copy link
Member

@fangpenlin c/common v0.54.0 has been created fwiw. I'm trying to vendor it now into Buildah, but I'm having some machine issues. doing so.

@rhatdan
Copy link
Member

rhatdan commented Jul 14, 2023

@fangpenlin Still working on this?

@fangpenlin
Copy link
Author

Oh, sorry, forgot this one. Just rebased

@fangpenlin fangpenlin force-pushed the pass-cwd-for-hooks-exec-run-func branch from 715ae4d to e3adeb1 Compare July 14, 2023 19:11
@rhatdan
Copy link
Member

rhatdan commented Jul 17, 2023

LGTM
@flouthoc @giuseppe @vrothberg @nalind @umohnani8 PTAL

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

Commit subject is too long, CI is blocked because of it. Could you please amend commit subject.

@rhatdan
Copy link
Member

rhatdan commented Jul 17, 2023

Remove [NO NEW TESTS NEEDED] from commit message, you should be all set then.

@fangpenlin fangpenlin force-pushed the pass-cwd-for-hooks-exec-run-func branch from e3adeb1 to b38a391 Compare July 18, 2023 05:06
@fangpenlin
Copy link
Author

Okay, done. What about now?

@fangpenlin
Copy link
Author

@rhatdan the Smoke Test says this

pr-should-include-tests: PR does not include changes in the 'tests' directory

Should I add the [NO NEW TESTS NEEDED] back and make the comment shorter?

@flouthoc
Copy link
Collaborator

@fangpenlin bud.bats contains some tests for hooks do you think they can be expected to test this addition ?

@fangpenlin
Copy link
Author

fangpenlin commented Jul 19, 2023

@flouthoc

I am not too familiar with buildah code base. But I did a quick search and it seems like the Run method is called from the paths of major buildah functions, like from, run and others:

if err := builder.Run(args, buildah.RunOptions{Stdout: stdout}); err != nil {

runerr := builder.Run(args, options)

err = s.builder.Run(args, options)

So I guess as long as the existing tests run very basic building image stuff, that path should be touched at some point. The only thing missing is that we didn't test specifically for the cwd part. Personally I would rely more on the test cases from upstream project common for this case

https://github.com/containers/common/blob/74c49fcec3ef8a08d0437eea3fea6eb20787a33a/pkg/hooks/exec/exec_test.go#L146-L166

However, if a specific test is really needed, I can find a time to add it. Maybe test against setupOCIHooks? The code lives in run_linux.go, looks like linux specific implementation. Not sure how to write test for it tho, might need to look it up a bit more for that part.

@github-actions
Copy link

A friendly reminder that this PR had no activity for 30 days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong CWD value set when calling OCI poststop hook executable
5 participants