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

Parameterize git clone depth and fix disabling submodules #1729

Merged
merged 3 commits into from
Dec 12, 2019
Merged

Parameterize git clone depth and fix disabling submodules #1729

merged 3 commits into from
Dec 12, 2019

Conversation

silverlyra
Copy link
Contributor

@silverlyra silverlyra commented Dec 10, 2019

Changes

Submitter Checklist

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

Release Notes

### Features

- The clone depth of `git` resources can now be set with a new `depth` parameter. Shallow clones can be disabled entirely by setting depth to `'0'`. #1450

### Fixes

- Initializing git submodules can now be turned off by setting the `submodules` param to `'false'`. #1727

@tekton-robot tekton-robot requested review from abayer and a user December 10, 2019 21:46
@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 10, 2019
@tekton-robot
Copy link
Collaborator

Hi @silverlyra. Thanks for your PR.

I'm waiting for a tektoncd 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.

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.

@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Dec 10, 2019
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.

On nit, otherwise looks good 👍

)

func init() {
Copy link
Member

Choose a reason for hiding this comment

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

nit: any reason for this to be in init() and not on top of main() ; the end result should be the same :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I find this more intuitive than sticking it in main. Most uses of the flag package I’ve seen don’t use the …Var forms and just live inside a top-level var block. Those calls run before main and stand out visually from the code in main – to me, this felt like a more consistent and minimal refactor than adding them to main.

@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 11, 2019
Copy link
Member

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this!

It could be useful to add a YAML example (which would be run in CI as a test) that demonstrates submodule fetch and custom depth. That would have helped us catch this bug originally.

@dibyom
Copy link
Member

dibyom commented Dec 11, 2019

/ok-to-test

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 11, 2019
desc string
gitResource *v1alpha1.GitResource
want corev1.Container
}{
Copy link
Member

Choose a reason for hiding this comment

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

nit: If you collapse this { and the next one, you can save a couple horizontal lines, and a vertical tabwidth:

for _, tc := range []struct {
  // struct fields
} {{
  // case 1
}, {
  // case 2
}} {
  t.Run(...)
}

Revision: "test",
GitImage: "override-with-git:latest",
Submodules: true,
Depth: 0,
Copy link
Member

Choose a reason for hiding this comment

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

What actually happens when you clone with --depth=0? Is this a case we should catch and fail in validation? Should we reject negative values?

(It's probably fine to just pass through whatever and let git fail as it wants, but it can be useful to avoid running a container that we know will fail -- this validation also doesn't have to happen in this change)

cmd/git-init/main.go Show resolved Hide resolved
if _, err := run(logger, "", "fetch", "--depth=1", "--recurse-submodules=yes", "origin", revision); err != nil {

fetchArgs := []string{"fetch", "--recurse-submodules=yes"}
if spec.Depth > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Ah I see, we just ignore any value <= 0. This seems like it could surprise users, I think we should reject it upfront instead. 🤔

Or at least log that we're ignoring it? Also probably worth logging that we couldn't parse the depth as a uint, and that we're falling back to the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should reject [depth of 0]

The original issue asking for depth control (#1450) isn't super clearly written, but my interpretation is that the author was asking for a way to turn off shallow clones entirely:

actual behavior: Git resources are always shallow cloned

git fetch --depth 0 is an error, so I’m overloading it to mean “full depth”. But I agree it’s subtle; how about I add a separate param shallow (defaulting to true) as the mechanism to opt into a full clone?

Also probably worth logging that we couldn't parse the depth as a uint, and that we're falling back to the default.

Unrecognized values for submodules are currently swallowed without logging anything – I kept this consistent with what’s already there, but I agree it’s not user-friendly. What if we have NewGitResource return an error in these cases? Would that be triggered from the validating webhook?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that should bubble up to webhook validation.

FWIW I think this change is pretty much just fine without all this extra validation, if you want to get this in and fix the obvious regression first, then add better validation later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that would be fine by me 😎

Lyra Naeseth added 2 commits December 11, 2019 10:07
Fixes #1727. In #1531, the submodules parameter was added, but it has no
influence on the generated git-init invocation.
@silverlyra
Copy link
Contributor Author

Can I get some 👀 on the CI output? I think all the failures I’m seeing are spurious.

@imjasonh
Copy link
Member

Yeah most of these are definitely unrelated. The unit test failures should be fixed by #1709 I think (though I thought #1731 would fix it...), and the link checker failure is just annoyingly flaky today.

However, there's a relevant error helpfully tucked deeeep within the integration test logs:

I1211 18:21:28.622] 2019/12/11 18:21:28 Unexpected error running "go build": exit status 2
I1211 18:21:28.623] # github.com/tektoncd/pipeline/pkg/git
I1211 18:21:28.624] pkg/git/git.go:80:33: cannot use spec.Depth (type uint) as type string in append

Which comes from here: https://github.com/tektoncd/pipeline/pull/1729/files#diff-4de8c4734d5ffab0d7fd8835bf8b3421R80

If you fix that we should be able to check that e2e tests aren't broken, then we'll just be waiting for unit tests and link-checker to start behaving.

Sorry for the noise, and thanks for sticking with it 💪

This lets users control the shallow clone depth, or disable shallow
clones entirely by setting depth to 0. Some build processes expect to be
able to access Git history. Increasing depth also helps users re-run
builds of commits that may no longer be at the head of a branch without
falling back to the full `git pull` code path.

Closes #1450.
@silverlyra
Copy link
Contributor Author

/retest

@silverlyra
Copy link
Contributor Author

/test pull-tekton-pipeline-build-tests

@silverlyra
Copy link
Contributor Author

🎉 Other than the link check failure, tests are now passing 😁

@vdemeester
Copy link
Member

/test pull-tekton-pipeline-build-tests

2 similar comments
@imjasonh
Copy link
Member

/test pull-tekton-pipeline-build-tests

@imjasonh
Copy link
Member

/test pull-tekton-pipeline-build-tests

@imjasonh
Copy link
Member

/lgtm

🎉

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 12, 2019
@tekton-robot tekton-robot merged commit 24c2131 into tektoncd:master Dec 12, 2019
@Fabian-K
Copy link
Contributor

Fabian-K commented Feb 19, 2020

Hi @silverlyra, we have a pipeline that relies on the entire repo to be cloned. With tekton 0.9 we therefore added a step git fetch --unshallow as it cloned by default with (I think) depth = 1.

After upgrading to 0.10.1 (and without specifying any value for depth) this fails now with fatal: --unshallow on a complete repository does not make sense. It looks like the default behavior is now a full clone. Is that intentional or does it make sense to change the default behavior back to 1?
Thanks, Fabian

Update: I don´t know what happened yesterday but I´m not able to reproduce it anymore. I´ll raise a issue it if i see it again. Sorry!

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

7 participants