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

add support for checking out to Git refs #1026

Merged
merged 1 commit into from
Feb 16, 2023
Merged

Conversation

aryan9600
Copy link
Member

Add a new field .spec.ref.name which points to a Git reference which enables checking out to a particular commit pointed to by the specified reference.

Fixes: #1017

// Name of the reference to check out; takes precedence over Branch, Tag and SemVer.
//
// It must be a valid Git reference: https://git-scm.com/docs/git-check-ref-format#_description
// Examples: "refs/heads/main", "refs/tags/v0.1.0", "refs/pull/420/head", "refs/merge-requests/1/head"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add here a kubebuilder regex that matches refs/<any>/<any>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation is much more complex than just refs/...: https://git-scm.com/docs/git-check-ref-format#_description

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather just let the Git implementation figure out if the arbitrary reference is correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we include the ref name in the error message: https://github.com/fluxcd/pkg/blob/main/git/gogit/clone.go#L372 and we have some basic validation: https://github.com/fluxcd/pkg/blob/main/git/gogit/clone.go#L402-L404. given these, i don't think we have a pressing need to validate the ref name at the API level

@aryan9600
Copy link
Member Author

Artifact description when we specify .spec.ref.name as refs/tags/6.0.0:

Status:
  Artifact:
    Checksum:          41400196b131aa44d00a198b15d98beb692c98bda6bd00843ac52dbf9b61f926
    Digest:            sha256:41400196b131aa44d00a198b15d98beb692c98bda6bd00843ac52dbf9b61f926
    Last Update Time:  2023-02-16T08:47:09Z
    Path:              gitrepository/flux-system/podinfo/627d5c4bb67b77185f37e31d734b085019ff2951.tar.gz
    Revision:          sha1:627d5c4bb67b77185f37e31d734b085019ff2951
    Size:              76434
    URL:               http://localhost:9090/gitrepository/fluxsystem/podinfo/627d5c4bb67b77185f37e31d734b085019ff2951.tar.gz

vs when we specify .spec.ref.tag as 6.0.0:

Status:
  Artifact:
    Checksum:          41400196b131aa44d00a198b15d98beb692c98bda6bd00843ac52dbf9b61f926
    Digest:            sha256:41400196b131aa44d00a198b15d98beb692c98bda6bd00843ac52dbf9b61f926
    Last Update Time:  2023-02-16T08:51:23Z
    Path:              gitrepository/flux-system/podinfo/627d5c4bb67b77185f37e31d734b085019ff2951.tar.gz
    Revision:          6.0.0@sha1:627d5c4bb67b77185f37e31d734b085019ff2951
    Size:              76434
    URL:               http://localhost:9090/gitrepository/fluxsystem/podinfo/627d5c4bb67b77185f37e31d734b085019ff2951.tar.gz

@stefanprodan
Copy link
Member

I think we should use the ref name in the artifact.revision e.g. refs/tags/6.0.0@sha1:627d5c4bb67b77185f37e31d734b085019ff2951 cc @hiddeco

@hiddeco
Copy link
Member

hiddeco commented Feb 16, 2023

Think while we initially discussed this, we opted not to? Changing this would require changing pkg/git again...

@hiddeco hiddeco added enhancement New feature or request area/git Git related issues and pull requests labels Feb 16, 2023
Add a new field `.spec.ref.name` which points to a Git reference which
enables checking out to a particular commit pointed to by the specified
reference.

Signed-off-by: Sanskar Jaiswal <jaiswalsanskar078@gmail.com>
Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely splendid @aryan9600, minimal change that opens up the world and brings our support for (automating) things up to a next level. 🥇

Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thanks @aryan9600 🏅

@hiddeco hiddeco merged commit 9cb04d2 into fluxcd:main Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/git Git related issues and pull requests enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support reference name in GitRepositoryRef
3 participants