-
Notifications
You must be signed in to change notification settings - Fork 198
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
Source controller fails to clone when specifying just the revision (and default branch main
at origin)
#315
Comments
See fluxcd/source-controller#315. Signed-off-by: Michael Bridgen <mikeb@squaremobius.net>
See fluxcd/source-controller#315. Signed-off-by: Michael Bridgen <mikeb@squaremobius.net>
@squaremo interested in picking this one up |
This can be achieved in a fairly straight-forward way. A question about UX:
|
The |
How do I target a commit without knowing or caring which branch it's on? Why would I want to do this -- I'm treating
Are people parsing that field? It seems like a mistake to encourage that, since it's brittle.
Presumably if you ask for a branch, then |
@squaremo my point is that if both the branch and the commit are specified, we should set the revision as |
OK yes I see, that makes sense.
This also makes sense -- does it do this now though? I suspect not, since it clones with the branch then does a checkout of the commit. |
It does, just ran into this while working on kustomize-controller tests:
results in: While
gives back: |
I stand corrected :-) |
What we are talking about is using a detached head, maybe we could specify this using a boolean (detachedHead: true, defaults to false) and when using it we skip the branch checkout? The ref could maybe be in the format |
Whether or not you check out the branch first, once you checkout a commit it's a detached head. |
As per Slack with @squaremo (https://cloud-native.slack.com/archives/C01A402P0R2/p1617451966151300) a boolean is redundant. |
To try to condense some of the discussion, what is the work to be done here? As I understand it, most of the desired behavior is currently covered by the current source-controller application logic. What is the delta here? |
The change is to let people specify just a commit, without specifying a branch as well. When the branch is given, it should behave as it does now, including recording |
Does this not break the current default behavior? If a user specifies no branch, the expectation is that this will check out the master branch? |
@jonathan-innis The user must specify one of either branch, tag, semver, or commit according to gitrepo spec for If you specify a commit hash, Flux checks out that commit hash only if it is on the branch specified. This is also currently the behavior implemented, not changing. If the user specified only a commit hash and no branch ref, Flux will no longer fill the branch ref with a default value of apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: GitRepository
metadata:
name: foo
namespace: flux-system
spec:
gitImplementation: go-git
interval: 1m0s
ref:
branch: ''
commit: 1b0d21cc635e28d51992d53e1ecc23a3f6cf4ac5
timeout: 20s
url: https://github.com/kingdonb/hephynator If I create this source now, in 0.13.4, Flux fills out the branch ref as Yes this is a slight breaking change but I think the number of users who are specifying a commit hash in their source and want it to be rejected if the commit hash wasn't on the (implicit default) master branch, or reject the commit if the master branch didn't exist (but I also don't want to speak its name in the source YAML) ... must be miniscule. If this is your use case, you should be explicit and request a commit hash from the branch you want. This is surprising behavior and we should axe it, even if it is technically a breaking change IMHO. |
Should we even support restricting the commit to the specified branch? I view the commit as a complete override over all other values because it's the most specific. If we continue supporting this behavior, we should really make sure that the error message is way more clear, because reporting that the object isn't found is super misleading:
The error should specify that it's not part of the particular branch and also print the branch name. It might be difficult to differentiate the default branch value from one that's explicitly set if we're trying to still support this alongside "Any Commit from any branch". |
I think we need to come to a decision on how the API should react here. I agree with @stealthybox where specifying both a branch and a commit is redundant as a commit should exist outside of a branch construct. From an ease-of-use perspective, the API is much more readable and easier understood if it's an order of precedence thing,
|
We got bit by this, trying to pin a single |
This commit changes the `gogit` behavior for commit checkouts, now allowing one to reference to just a commit while omitting any branch reference. Doing this creates an Artifact with a `HEAD/<commit>` revision. If both a `branch` and `commit` are defined, the commit is expected to exist within the branch. This results in a more efficient clone of just the target branch, and also makes this change backwards compatible. Fixes #407 Fixes #315 Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit changes the `gogit` behavior for commit checkouts, now allowing one to reference to just a commit while omitting any branch reference. Doing this creates an Artifact with a `HEAD/<commit>` revision. If both a `branch` and `commit` are defined, the commit is expected to exist within the branch. This results in a more efficient clone of just the target branch, and also makes this change backwards compatible. Fixes #407 Fixes #315 Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit changes the `gogit` behavior for commit checkouts, now allowing one to reference to just a commit while omitting any branch reference. Doing this creates an Artifact with a `HEAD/<commit>` revision. If both a `branch` and `commit` are defined, the commit is expected to exist within the branch. This results in a more efficient clone of just the target branch, and also makes this change backwards compatible. Fixes #407 Fixes #315 Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit changes the `gogit` behavior for commit checkouts, now allowing one to reference to just a commit while omitting any branch reference. Doing this creates an Artifact with a `HEAD/<commit>` revision. If both a `branch` and `commit` are defined, the commit is expected to exist within the branch. This results in a more efficient clone of just the target branch, and also makes this change backwards compatible. Fixes #407 Fixes #315 Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit changes the `gogit` behavior for commit checkouts, now allowing one to reference to just a commit while omitting any branch reference. Doing this creates an Artifact with a `HEAD/<commit>` revision. If both a `branch` and `commit` are defined, the commit is expected to exist within the branch. This results in a more efficient clone of just the target branch, and also makes this change backwards compatible. Fixes #407 Fixes #315 Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit changes the `gogit` behavior for commit checkouts, now allowing one to reference to just a commit while omitting any branch reference. Doing this creates an Artifact with a `HEAD/<commit>` revision. If both a `branch` and `commit` are defined, the commit is expected to exist within the branch. This results in a more efficient clone of just the target branch, and also makes this change backwards compatible. Fixes #407 Fixes #315 Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit changes the `gogit` behavior for commit checkouts, now allowing one to reference to just a commit while omitting any branch reference. Doing this creates an Artifact with a `HEAD/<commit>` revision. If both a `branch` and `commit` are defined, the commit is expected to exist within the branch. This results in a more efficient clone of just the target branch, and also makes this change backwards compatible. Fixes #407 Fixes #315 Signed-off-by: Hidde Beydals <hello@hidde.co>
It is not redundant, as the information can be used to perform a more efficient clone, in which just the history of the targeted branch is fetched. Given this, I made changes in #462 to allow defining a commit without a branch configured, but defining a branch and a commit will fallback to the previous behavior (and in the case of |
This commit changes the `gogit` behavior for commit checkouts, now allowing one to reference to just a commit while omitting any branch reference. Doing this creates an Artifact with a `HEAD/<commit>` revision. If both a `branch` and `commit` are defined, the commit is expected to exist within the branch. This results in a more efficient clone of just the target branch, and also makes this change backwards compatible. Fixes #407 Fixes #315 Signed-off-by: Hidde Beydals <hello@hidde.co>
If I create a GitRepository with a spec like this:
then the source controller fails to clone the repo. Naively, I would expect it to do the equivalent of
Unfortunately, the
.branch
field has a default ofmaster
, and the checkout code checks out the branch first, then the commit (whether or not it's on the branch, so far as I can tell). This seems like a needless step; but it also means you can't specify just a commit, you have to name a branch that exists at the origin, otherwise it'll fail.The text was updated successfully, but these errors were encountered: