-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
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 Once the patch is verified, the new status will be reflected by the 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. |
There was a problem hiding this 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() { |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
.
[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 |
There was a problem hiding this 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.
/ok-to-test |
desc string | ||
gitResource *v1alpha1.GitResource | ||
want corev1.Container | ||
}{ |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)
if _, err := run(logger, "", "fetch", "--depth=1", "--recurse-submodules=yes", "origin", revision); err != nil { | ||
|
||
fetchArgs := []string{"fetch", "--recurse-submodules=yes"} | ||
if spec.Depth > 0 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😎
Can I get some 👀 on the CI output? I think all the failures I’m seeing are spurious. |
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:
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.
/retest |
/test pull-tekton-pipeline-build-tests |
🎉 Other than the link check failure, tests are now passing 😁 |
/test pull-tekton-pipeline-build-tests |
2 similar comments
/test pull-tekton-pipeline-build-tests |
/test pull-tekton-pipeline-build-tests |
/lgtm 🎉 |
Hi @silverlyra, we have a pipeline that relies on the entire repo to be cloned. With tekton 0.9 we therefore added a step After upgrading to 0.10.1 (and without specifying any value for depth) this fails now with 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! |
Changes
depth
param togit
resources to control the--depth
flag togit fetch
. When set to'0'
, shallow fetches are disabled entirely. Git Pipeline Resources should allow depth to be specified #1450submodule
param so that it can be meaningfully set tofalse
. git-init: Setting submodules to false has no effect #1727Submitter 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