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

Gitrepos based on repositories with default branch different to master fail to apply when revision is used #2404

Open
1 task done
0xavi0 opened this issue May 3, 2024 · 3 comments
Assignees
Labels
Milestone

Comments

@0xavi0
Copy link
Contributor

0xavi0 commented May 3, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

This issue is related to #2403

Apply the followin gitrepo (The important bit is that we're using a revision and that the git repo's default branch is main)

apiVersion: fleet.cattle.io/v1alpha1
kind: GitRepo
metadata:
  name: sample
  namespace: fleet-local
spec:
  repo: "https://github.com/0xavi0/fleet-experiments"
  revision: v0.0.0
  paths:
  - helm-test-tags

The gitrepo won't deploy successfully and we can observe the following error in gitjob:

2024-05-03T08:07:33Z	ERROR	git-latest-commit-poll-watch	error fetching commit	{"gitrepo": {"kind":"GitRepo","apiVersion":"fleet.cattle.io/v1alpha1","metadata":{"name":"sample","namespace":"fleet-local","uid":"49063f58-1f8c-4f1a-983a-9ef55e24fa9c","resourceVersion":"9037","generation":1,"creationTimestamp":"2024-05-03T08:07:32Z","annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"fleet.cattle.io/v1alpha1\",\"kind\":\"GitRepo\",\"metadata\":{\"annotations\":{},\"name\":\"sample\",\"namespace\":\"fleet-local\"},\"spec\":{\"paths\":[\"helm-test-tags\"],\"repo\":\"https://github.com/0xavi0/fleet-experiments\",\"revision\":\"v0.0.0\"}}\n"},"managedFields":[{"manager":"kubectl-client-side-apply","operation":"Update","apiVersion":"fleet.cattle.io/v1alpha1","time":"2024-05-03T08:07:32Z","fieldsType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{".":{},"f:kubectl.kubernetes.io/last-applied-configuration":{}}},"f:spec":{".":{},"f:paths":{},"f:repo":{},"f:revision":{}}}}]},"spec":{"repo":"https://github.com/0xavi0/fleet-experiments","revision":"v0.0.0","paths":["helm-test-tags"],"imageScanCommit":{"authorName":"","authorEmail":""}},"status":{"observedGeneration":0,"readyClusters":0,"desiredReadyClusters":0,"summary":{"ready":0,"desiredReady":0},"display":{},"resourceCounts":{"ready":0,"desiredReady":0,"waitApplied":0,"modified":0,"orphaned":0,"missing":0,"unknown":0,"notReady":0},"lastSyncedImageScanTime":null}}, "error": "commit not found"}

As stated in #2403 , the issue is happening because the LatestCommit function in the fetch.go file is using the provided branch to get the last commit or master if none is provided.
As this example is using a git repo with main as its default branch, and we're using a revision, fleet tries to find the last commit formaster. But master is not found and we get the error.

Expected Behavior

The default branch for git repositories should be configurable or, at least, fallback to main if master is not found (or we get an error)

At least the error message should mention what's the branch used so users (and fleet team) have pointers about what's going on.
"commit not found for branch master" would give more information, pointing out that fleet is trying to access the master branch.
The actual error message is just "commit not found"

@0xavi0 0xavi0 added the kind/bug label May 3, 2024
@p-se p-se added this to the v2.9.0 milestone May 3, 2024
@manno
Copy link
Member

manno commented May 15, 2024

Let's make the error message more verbose. We use branch to specify the reference.

@0xavi0
Copy link
Contributor Author

0xavi0 commented May 16, 2024

#2410 implements a change in the error message shown to include the branch or revision used.
This way the user will be able to see, for example, that Fleet uses master as its default branch when not defining a branch explicitly in the gitrepo resource and having main as the default.

@0xavi0
Copy link
Contributor Author

0xavi0 commented May 30, 2024

QA Template

Solution

Add the name of the branch being used by fleet to give more information

Testing

  • Apply a gitrepo referencing a repository that has main as the default branch, but don't specify any branch.
    Example:
apiVersion: fleet.cattle.io/v1alpha1
kind: GitRepo
metadata:
  name: sample-oci
  namespace: fleet-local
spec:
  repo: "https://github.com/0xavi0/fleet-experiments"
  paths:
  - helm-test-tags
  • Check the gitjob logs and you should see and error with the message: "commit not found for branch: master"

Additional notes

  • This can't be tested with rancher anymore, because it was raising when using a tag, but now Fleet is getting the commit for that tag instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Needs QA review
Development

No branches or pull requests

4 participants