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

gitVersion results in inconsistent string values #99376

Closed
imjasonh opened this issue Feb 23, 2021 · 8 comments · Fixed by #99377
Closed

gitVersion results in inconsistent string values #99376

imjasonh opened this issue Feb 23, 2021 · 8 comments · Fixed by #99377
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/release Categorizes an issue or PR as relevant to SIG Release.

Comments

@imjasonh
Copy link

Ref. ko-build/ko#315 (comment)

pkg/version/base.go includes:

// NOTE: The $Format strings are replaced during 'git archive' thanks to the
// companion .gitattributes file containing 'export-subst' in this same
// directory.  See also https://git-scm.com/docs/gitattributes
gitVersion   string = "v0.0.0-master+$Format:%h$"

This $Format:%h$ directive, activated by git archive and the .gitattributes containing the line base.go export-subst, results in file contents served by GitHub Archives that can change in unexpected ways. For example, the length of the commit SHA can expand over time as there are collisions.

This non-determinism can lead to surprises, such as ko-build/ko#315, where a client-go dependency resulted in unexpectedly different tar hashes, which was detected when a new version of the ko binary was being added to Homebrew.

tl;dr: though the client-go dependency itself didn't change for ko, later runs of git archive (via GitHub Archives) resulted in different contents for the gitVersion string to avoid a new collision for the previous prefix length, which cascaded into different content SHAs and shady-looking binary SHAs.

I'm not sure, but after reading docs I believe you could naively solve this by replacing $Format:%h$ with $Format:%H$ so the gitVersion string includes the full commit hash instead of the abbreviated one.

I have no idea if anything depends on gitVersion being a shorter string, but presumably things are fine with it having been a variable-length string so 🤷‍♂️ . Given enough time/collisions, I suppose theoretically %h will slow grow to be equal to %H, but I don't think that will happen during any of our lifetimes 👴

cc @Bo98

@liggitt liggitt transferred this issue from kubernetes/client-go Feb 23, 2021
@k8s-ci-robot k8s-ci-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Feb 23, 2021
@k8s-ci-robot
Copy link
Contributor

@imjasonh: This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Feb 23, 2021
@liggitt
Copy link
Member

liggitt commented Feb 23, 2021

Thanks for the report. Moving to kubernetes/kubernetes where this source comes from.

There's not a lot we can do for past releases, but I'd be in favor of switching to %H going forward. Reproducibility of source archives is important.

@neolit123
Copy link
Member

/sig release

@k8s-ci-robot k8s-ci-robot added sig/release Categorizes an issue or PR as relevant to SIG Release. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 25, 2021
@neolit123
Copy link
Member

/kind bug

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Feb 25, 2021
@imjasonh
Copy link
Author

Thanks for taking this on @liggitt !! 🎉

@jonyhy96
Copy link
Contributor

@liggitt @neolit123 since we don't actually use git archive to full-fill the commit info as version, should we just delete that .gitattributes file?
containerd faced a issue about checksum mismatch containerd/containerd#6387 due to this.

@afbjorklund
Copy link

containerd faced a issue about checksum mismatch containerd/containerd#6387 due to this.

and before that it was cri-o/cri-o#4820 and before that containers/podman#9355, so everywhere

@nikhita
Copy link
Member

nikhita commented Jan 17, 2022

should we just delete that .gitattributes file?

@jonyhy96 @afbjorklund I have created kubernetes/publishing-bot#285 to stop including the .gitattributes files in k8s libraries. For anyone vendoring these libraries in the future, you should no longer be affected by this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. sig/release Categorizes an issue or PR as relevant to SIG Release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants