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

Add workingdir integration test #1625

Merged

Conversation

chmouel
Copy link
Member

@chmouel chmouel commented Nov 26, 2019

Add an integration test checking the workingdirs

Following on review #1609 (review) we realised that there wasn't any integration test for the workingdir step, let's add some tests for this.

Closes #1624

Changes

We didn't check previously if workingdir really worked properly, let's add tests
for this.

/cc @imjasonh

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

@tekton-robot tekton-robot requested review from dibyom and a user November 26, 2019 15:57
@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Nov 26, 2019
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 26, 2019
@chmouel
Copy link
Member Author

chmouel commented Nov 26, 2019

I could not find a way to do a TestBad I need to figure out how to not being able to write to /workspace since it's volume mounted, fs mode rights are assigned to our running user (so having a new SA with non elevated priv would not work.

@imjasonh
Copy link
Member

Would it be possible to phrase at least some of this test as a YAML test?

steps:
- image: ubuntu
  command: ['touch', 'foo']
  workingDir: 'foo'  # implicitly mkdir's /workspace/foo
- image: ubuntu
  command: ['cat', '/workspace/foo/foo']
...

This has the benefit of being easier (I think) to read and understand in isolation.

@chmouel
Copy link
Member Author

chmouel commented Nov 26, 2019

Good idea, updating the existing workdir.yaml with something like this? :

diff --git a/examples/taskruns/workingdir.yaml b/examples/taskruns/workingdir.yaml
index e8a7d87f..73229cf8 100644
--- a/examples/taskruns/workingdir.yaml
+++ b/examples/taskruns/workingdir.yaml
@@ -12,6 +12,14 @@ spec:
       - '-c'
       - '[[ $PWD == /workspace ]]'
 
+    - name: default
+      image: ubuntu
+      command: ['bash']
+      workingDir: "foo"  # implicitly mkdir's /workspace/foo
+      args:
+      - '-c'
+      - '[[ $PWD == /workspace/foo ]]'
+
     - name: override
       image: ubuntu
       command: ['bash']

@imjasonh
Copy link
Member

Yeah that sounds great. Is there anything else left in the Go test that can be YAMLified?

@chmouel
Copy link
Member Author

chmouel commented Nov 26, 2019

@imjasonh I think the go test are still useful they make it implicit what should be expected, I

I meant we need to make sure no output is coming back out of the mkdir -p and i don't thin kthe YAML would catch this?

There is another test in there too which make sure that workingdir with absolute path (ie /foo) that are not starting with /workspace.

@imjasonh
Copy link
Member

@imjasonh I think the go test are still useful they make it implicit what should be expected, I

I meant we need to make sure no output is coming back out of the mkdir -p and i don't thin kthe YAML would catch this?

It wouldn't. I'm just not sure how much that matters though. The test implicitly checks that the directory exists as expected, that's all I really care about.

@chmouel chmouel force-pushed the add-workingdir-integration-test branch 2 times, most recently from 421d512 to 0b04943 Compare November 27, 2019 13:40
@bobcatfish
Copy link
Collaborator

@chmouel could you add some more detail in the commit message about what this commit is for? at the moment it just says "Add workingdir integration test" but it's hard to understand without context. I don't know what "workingdir integration test" is, and even from #1624 I'm not really sure what the workingdir feature is :S

Sorry for the nitpicking!! But having a lot of info in our commit messages and in our issues is really important to me, and makes it a lot easier to make sure all the contributors can be on the same page.

@chmouel (or anyone) feel free to remove this hold once we have some more details:
/hold

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 27, 2019
@chmouel chmouel force-pushed the add-workingdir-integration-test branch from 0b04943 to 39155d2 Compare November 27, 2019 14:18
@chmouel
Copy link
Member Author

chmouel commented Nov 27, 2019

@bobcatfish I kinda rephrased it, but would you like me to explain what the workingdir step is doing in the commit message? I think that would be a documentation update, isnt it ?

@chmouel
Copy link
Member Author

chmouel commented Nov 27, 2019

CI error is unrelated to this commit but this #1634 would fix it,

@bobcatfish
Copy link
Collaborator

Thanks for the update! 🙏

@bobcatfish I kinda rephrased it, but would you like me to explain what the workingdir step is doing in the commit message? I think that would be a documentation update, isnt it ?

I mean I would! I like to err on the side of being verbose, cuz it's really hard to know how much you'll know later - for example, say someone is looking at this commit message 2 years from now and the workingdir step is long gone but some of the lines of code remain, they'll have a really hard time understanding this change

@chmouel
Copy link
Member Author

chmouel commented Nov 27, 2019

@bobcatfish I understand and if I could I would have link to the documentation from the commit message to explains what the workingdir but unfortunately it's not there :(

@chmouel chmouel force-pushed the add-workingdir-integration-test branch from 39155d2 to 34db59d Compare November 27, 2019 14:36
@chmouel
Copy link
Member Author

chmouel commented Nov 27, 2019

/retest

@chmouel
Copy link
Member Author

chmouel commented Nov 28, 2019

It doesnt not seem that a relative path for workingdir can actually work 🤔

35s Warning Failed pod/workingdir-2hcbb-pod-366869 Error: container create failed: Cwd must be an absolute path

@vdemeester
Copy link
Member

It doesnt not seem that a relative path for workingdir can actually work thinking

35s Warning Failed pod/workingdir-2hcbb-pod-366869 Error: container create failed: Cwd must be an absolute path

Yeah that make sense 👼

@chmouel
Copy link
Member Author

chmouel commented Nov 28, 2019

I guess this code is not doing what expected then :

https://github.com/chmouel/tektoncd-pipeline/blob/34db59dd10f6407de6427992b2d2b04c4208027b/pkg/pod/workingdir_init.go#L60-L65

It should be

	if filepath.IsAbs(p) || strings.HasPrefix(p, "/workspace/") {

(currently it skips the absolute path like /foo and catch the non absolute path like foo)

@chmouel chmouel force-pushed the add-workingdir-integration-test branch from 34db59d to 7e272d7 Compare December 2, 2019 16:38
@chmouel
Copy link
Member Author

chmouel commented Dec 3, 2019

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 3, 2019
@chmouel
Copy link
Member Author

chmouel commented Dec 3, 2019

CB> I guess this code is not doing what expected then :

I'll work on a following PR to fix the code,

test/workingdir_test.go Outdated Show resolved Hide resolved
@chmouel chmouel force-pushed the add-workingdir-integration-test branch from 7e272d7 to 826d591 Compare December 3, 2019 13:42
We didn't check previously if workingdir step really worked properly.

The workingdir container steps is taking care to make sure the workingdir
directory is created into the workspace,

Signed-off-by: Chmouel Boudjnah <[email protected]>
@chmouel chmouel force-pushed the add-workingdir-integration-test branch from 826d591 to ef799ca Compare December 3, 2019 14:51
Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 3, 2019
@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vdemeester

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

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 3, 2019
@tekton-robot tekton-robot merged commit 4f2bb9d into tektoncd:master Dec 3, 2019
@chmouel chmouel deleted the add-workingdir-integration-test branch December 3, 2019 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add missing integration test for workingdir
6 participants