fleet icon indicating copy to clipboard operation
fleet copied to clipboard

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

Open 0xavi0 opened this issue 3 months ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

This issue is related to https://github.com/rancher/fleet/issues/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 https://github.com/rancher/fleet/issues/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 avatar May 03 '24 08:05 0xavi0