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

Rewrite git-clone as shell script #188

Closed
wants to merge 3 commits into from

Conversation

chmouel
Copy link
Member

@chmouel chmouel commented Feb 19, 2020

We are rewritting git-clone as a 'pure' bourne shell script with no dependence
on the git-init image.

I have rewritten almost word by word the go code from here https://git.io/JvBCr

Error handling are handled by shell's set -e so if any command fails it will
just exit 1,

There is some bugs in go code submodules which is done always so i have handled
this differently to properly be conditional to the parameter.

Changes

Submitter Checklist

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

See the contribution guide
for more details.

@tekton-robot tekton-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 19, 2020
if [[ ${DEPTH} > 0 ]];then
fetchArgs="${fetchArgs} --depth=${DEPTH}"
fi
if git ${fetchArgs};then
Copy link

Choose a reason for hiding this comment

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

Missing [[ ]]?

Copy link

Choose a reason for hiding this comment

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

Actually maybe I misunderstand what this is doing. What does this do?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will check if the command exit properly and if it doesn't it will fallback, I have simply converted the GO code, and I assume that fallback was written to cover a user case... i.e:

https://github.com/tektoncd/pipeline/blob/4e9380fe0d0e7ce862ff23781f614ad8e6de9faf/pkg/git/git.go#L91-L92

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

I tried this out locally in a pipeline and it performed the same as the existing git-init binary (as far as I can tell...)

git/git-clone.yaml Show resolved Hide resolved
git/git-clone.yaml Outdated Show resolved Hide resolved
@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbwsg

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 Feb 19, 2020
fetchArgs="${fetchArgs} --depth=${DEPTH}"
fi
if git ${fetchArgs};then
git pull origin master
Copy link

Choose a reason for hiding this comment

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

I think it's possible that there is no "master" branch on the remote.

What is the purpose of this pull? We fetch in the previous line and then we checkout the specific revision on the next line.

Copy link
Member Author

@chmouel chmouel Feb 24, 2020

Choose a reason for hiding this comment

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

yeah i wondered it too (to be honest I merely converted the GO code without too much tweaking), i think we can just git reset --hard anyway...

@chmouel
Copy link
Member Author

chmouel commented Feb 24, 2020

Adding @sthaha for advice since he is the git guru 😀

git/git-clone.yaml Outdated Show resolved Hide resolved
git/git-clone.yaml Outdated Show resolved Hide resolved
Copy link
Member

@sthaha sthaha left a comment

Choose a reason for hiding this comment

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

Looks good to me; may want to consider addressing some of the comments.


ensureHomeEnv
fetch
echo -n "$(git rev-parse HEAD | tr -d '\n')" > "$(results.commit.path)"
Copy link
Member

Choose a reason for hiding this comment

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

echo isn't needed - right? i.e. git rev-parse HEAD | tr -d '\n' > "$( ...) should work - right?

# https://git.io/JvBCr
fetch() {
[[ ${REVISION} == "" ]] && REVISION=master
if [[ ${CHECKOUT_DIR} != "" ]];then
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 can reduced to

test -z "$CHECKOUT_DIR" || cd "$CHECKOUT_DIR"
git init .

else
git init .
fi
trimmedURL=$(echo ${URL}|sed -e 's/^[ ]*//' -e 's/[ ]*$//')
Copy link
Member

Choose a reason for hiding this comment

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

also just curious ... wouldn't trimmedURL=$(echo $URL) work :D ?

Copy link
Member Author

Choose a reason for hiding this comment

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

that doesn't trim the spaces:

image

Copy link
Member

@sthaha sthaha Mar 20, 2020

Choose a reason for hiding this comment

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

image

🤔

Copy link
Member

Choose a reason for hiding this comment

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

@chmouel are you using sh? or zsh?

Copy link
Member

Choose a reason for hiding this comment

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

@chmouel you don't have to change the implementation, I was only curious ...

@chmouel
Copy link
Member Author

chmouel commented Mar 3, 2020

/hold

will do this rewrite when i get a bit of time..

@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 Mar 3, 2020
@sthaha
Copy link
Member

sthaha commented Mar 3, 2020

/hold

will do this rewrite when i get a bit of time..

IMHO, we can merge this while you work on the improved version.

@bobcatfish
Copy link
Contributor

I'm gonna contradict tektoncd/pipeline#1961:

The disadvantage of this is that git-type PipelineResources become dependent on (presumably) Bash scripts, which can grow to unmaintainable sizes. Unit testing is hard in Bash, but git-init has no unit tests today anyway.

I'm not sure that a script is the most maintainable way forward here? As soon as we get beyond a few lines in a script, whether we're talking about python or git, and when we're talking about a piece of infra that is so core to so many Pipelines (i.e. pulling from git), I feel like we want to start having testing, linting, all that good stuff. Moving this logic into a script feels like a couple steps backward for me?

It definitely has the advantage of being able to see exactly what the script is doing, but I'd rather that we start adding tests and debug info to the git-init logic we already have - even move it into its own repo (or into this one).

/hold

@chmouel
Copy link
Member Author

chmouel commented Mar 19, 2020

@bobcatfish that's some fair points here is some of the advantages I see using a only shell git clone task :

  • It's easier for user to debug what's going on instead of having to dig deep into the code, figuring out which git command has been run.

  • It's easier for the user to modify, if they need some esoteric way of doing git-clonning they could just modify this task.

  • It's easier for distributors to maintain and having one image less.

  • There is no dependency between the go code and the task and having to make sure task version X depends on git-init version Y.

  • The current git-init image is mostly launching shell commands and not doing much more what a shell script is doing. It's arguably as difficult to read the git-init code than the shell script (or at least it was for me when translating the go code in shell).

And to add this, I am adding tests for this and we can have a job doing bash unit tests.

@vdemeester
Copy link
Member

As soon as we get beyond a few lines in a script, whether we're talking about python or git, and when we're talking about a piece of infra that is so core to so many Pipelines (i.e. pulling from git), I feel like we want to start having testing, linting, all that good stuff. Moving this logic into a script feels like a couple steps backward for me?

I am not entirely sure how "so core" it is to Pipelines. It can be considered as core if it is in tektoncd/pipeline as the git PipelineResource git. But cloning a repository in a task, is at the same level as any other task that Pipelines are supposed to support, it shouldn't be consider as core as it is just a way to populate a workspace to be consumed by later Tasks — at least this task shouldn't (but whatever is used by the git PipelineResource now or in the future, should).

I do agree (and adding 👍) with @chmouel on his points, the git-init image is more opaque than a git script, and both do the same in the end (aka executing git commands).

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 19, 2020
We are rewritting git-clone as a 'pure' bourne shell script with no dependence
on the git-init image.

I have rewritten almost word by word the go code from here https://git.io/JvBCr

Error handling are handled by shell's set -e so if any command fails it will
just exit 1,

There is some bugs in go code submodules which is done always so i have handled
this differently to properly be conditional to the parameter.

Signed-off-by: Chmouel Boudjnah <[email protected]>
@chmouel
Copy link
Member Author

chmouel commented Mar 19, 2020

I have added some tests and resynced with master...

@tekton-robot
Copy link

@chmouel: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-tekton-catalog-integration-tests 87041b8 link /test pull-tekton-catalog-integration-tests

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

nikhil-thomas pushed a commit to nikhil-thomas/catalog that referenced this pull request Apr 13, 2020
…o-release-v0.11

New merge from upstream v1beta to release v0.11
@ghost
Copy link

ghost commented Apr 17, 2020

@bobcatfish @chmouel @vdemeester can we find a venue to discuss this further and get closure for this PR? Perhaps the Pipelines WG? I think there are sound arguments on both sides of this debate and we should probably resolve them so that we can set the policy for other catalog entries going forward.

@chmouel
Copy link
Member Author

chmouel commented Apr 20, 2020

Sounds good to me, let's have this discussion on next week agenda.

@chmouel
Copy link
Member Author

chmouel commented Jun 10, 2020

/close

let's try in another way maybe complicated shell scripts is a bit too cryptic, will send a new PR trying it in Python+Tests.

@tekton-robot
Copy link

@chmouel: Closed this PR.

In response to this:

/close

let's try in another way maybe complicated shell scripts is a bit too cryptic, will send a new PR trying it in Python+Tests.

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.

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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. 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.

5 participants