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 revision show the wrong commit in Status #2403

Open
1 task done
0xavi0 opened this issue May 3, 2024 · 1 comment
Open
1 task done

Gitrepos based on revision show the wrong commit in Status #2403

0xavi0 opened this issue May 3, 2024 · 1 comment
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

I'm using the following gitrepo:

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

The git repository has 3 tags

  • v0.0.0
  • v0.0.1
  • v0.0.2

After applying the gitrepo (which references tag v0.0.0) we can see the following commit in the gitrepo

$ kubectl get gitrepo -n fleet-local sample                                                                                                      
NAME     REPO                                                 COMMIT                                     BUNDLEDEPLOYMENTS-READY   STATUS
sample   https://github.com/0xavi0/fleet-experiments-master   b91254d06622d8e0ace1f76c0926b95af2efb63a   1/1

But b91254d06622d8e0ace1f76c0926b95af2efb63a is the hash for the repository's HEAD, not the commit for tag v0.0.0

$ git ls-remote https://github.com/0xavi0/fleet-experiments-master                                                                                
b91254d06622d8e0ace1f76c0926b95af2efb63a	HEAD
b91254d06622d8e0ace1f76c0926b95af2efb63a	refs/heads/master
b8a525671bfd03f32991b4ccec56517e74b3d7b0	refs/tags/v0.0.0
8e186ca6abd9930e90a129954b4bd0c630f5a7ab	refs/tags/v0.0.0^{}
b2f7eacdeda55833e299efdd6955abb68f581547	refs/tags/v0.0.1
a08281305a4320ba4df9cc877e20a295d0c128a4	refs/tags/v0.0.1^{}
ffad72d77b26152ad74053d736cc1b96c82b7c99	refs/tags/v0.0.2
b91254d06622d8e0ace1f76c0926b95af2efb63a	refs/tags/v0.0.2^{}

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 revision no branch is provided and we obtain the Commit from master (head).

Expected Behavior

I would expect to see the commit for the tag instead to the one for HEAD

Steps To Reproduce

Apply the gitrepo referenced and observe the Commit in the gitrepo

@0xavi0 0xavi0 added the kind/bug label May 3, 2024
@0xavi0 0xavi0 self-assigned this May 3, 2024
0xavi0 added a commit to 0xavi0/fleet that referenced this issue May 6, 2024
Changing the commit retrieved when applying `gitrepo`s with revisions.
It will show the commit for that revision/tag instead to the latest commit for the default branch (`master`)

Refers to: rancher#2403

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
0xavi0 added a commit to 0xavi0/fleet that referenced this issue May 6, 2024
Changing the commit retrieved when applying `gitrepo`s with revisions.
It will show the commit for that revision/tag instead to the latest commit for the default branch (`master`)

Refers to: rancher#2403

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
0xavi0 added a commit to 0xavi0/fleet that referenced this issue May 6, 2024
Changing the commit retrieved when applying `gitrepo`s with revisions.
It will show the commit for that revision/tag instead to the latest commit for the default branch (`master`)

Refers to: rancher#2403

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
0xavi0 added a commit to 0xavi0/fleet that referenced this issue May 6, 2024
Changing the commit retrieved when applying `gitrepo`s with revisions.
It will show the commit for that revision/tag instead to the latest commit for the default branch (`master`)

Refers to: rancher#2403

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
@0xavi0 0xavi0 added this to the v2.9.0 milestone May 15, 2024
manno pushed a commit that referenced this issue May 22, 2024
* Return commit for revision instead of HEAD

Changing the commit retrieved when applying `gitrepo`s with revisions.
It will show the commit for that revision/tag instead to the latest commit for the default branch (`master`)

Refers to: #2403

* pkg/git code refactor

This is a refactoring of the code in `pkg/git` package in order to make it more testable.
It basically splits things into smaller entities and follows the interface/struct approach to
make visible (and mockable) some previously internal code.

---------

Signed-off-by: Xavi Garcia <xavi.garcia@suse.com>
@0xavi0
Copy link
Contributor Author

0xavi0 commented May 30, 2024

QA Template

Solution

Fleet now gets the commit for the tag, not for the master branch of the repository

Testing

  • Apply any gitrepo with a tag (revision).
  • Check that the commit in the gitrepo status is the commit for that tag, not the one for the master branch

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

2 participants