Skip to content

Fix for Add fallback to Static Version File in Shallow Clones. #131630

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sarkar-deb
Copy link

When git describe cannot determine the version due to a shallow clone or lack of tags, the current versioning logic does not
provide a meaningful fallback. This can cause downstream tooling and image tagging logic to behave incorrectly or inconsistently.

❯ git clone git@github.com:sarkar-deb/kubernetes.git --branch fix-release-version --depth 1 .
Cloning into '.'...
remote: Enumerating objects: 26663, done.
remote: Counting objects: 100% (26663/26663), done.
remote: Compressing objects: 100% (17598/17598), done.
remote: Total 26663 (delta 7677), reused 23373 (delta 7154), pack-reused 0 (from 0)
Receiving objects: 100% (26663/26663), 40.16 MiB | 12.21 MiB/s, done.
Resolving deltas: 100% (7677/7677), done.
Updating files: 100% (26893/26893), done.

Now when we build kubelet on this a branch:

❯ make all WHAT=cmd/kubelet
go: downloading go1.24.2 (darwin/amd64)
+++ [0506 17:16:52] Building go targets for darwin/amd64
    k8s.io/kubernetes/cmd/kubelet (non-static)
❯ ./_output/local/go/bin/kubelet --version
Kubernetes v0.0.0-master+$Format:%H$

After fix

❯ make all WHAT=cmd/kubelet
+++ [0506 17:19:24] Building go targets for darwin/amd64
    k8s.io/kubernetes/cmd/kubelet (non-static)
❯ ./_output/local/go/bin/kubelet --version
Kubernetes v1.33.0+b30054dfb64e45

Note: To get version I have used data from file build/build-image/cross/VERSION

For issue:
#131629

@k8s-ci-robot
Copy link
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 6, 2025
@k8s-ci-robot
Copy link
Contributor

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-sigs/prow repository.

@k8s-ci-robot
Copy link
Contributor

Hi @sarkar-deb. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label May 6, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sarkar-deb
Once this PR has been reviewed and has the lgtm label, please assign sataqiu for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

else
KUBE_GIT_VERSION=$("${git[@]}" describe --tags --match='v*' --abbrev=14 "${KUBE_GIT_COMMIT}^{commit}" 2>/dev/null) || true
# Fallback to /build/build-image/cross/VERSION if git describe fails
version_file="${KUBE_ROOT}/build/build-image/cross/VERSION"
Copy link
Member

Choose a reason for hiding this comment

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

/hold
#131629 (comment)

This is not correct

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 6, 2025
@BenTheElder BenTheElder self-assigned this May 6, 2025
@liggitt
Copy link
Member

liggitt commented May 7, 2025

This can cause downstream tooling and image tagging logic to behave incorrectly or inconsistently.

downstream tooling is responsible to do one of these things:

  1. do a clone with enough git tag info that these build scripts work as-is
  2. set KUBE_GIT_VERSION using its own logic and use these build scripts
  3. set the version ldflags using its own logic in its own build scripts

if our scripts are allowing a build to proceed with KUBE_GIT_VERSION completely unset or invalid, erroring more visibly seems reasonable, but I don't think we need to add new ways of deriving version info in this script... the git tag or manual override of KUBE_GIT_VERSION seems reasonable to me

@sarkar-deb
Copy link
Author

@liggitt
Thanks I got your point as of different ways to get git version while building binary.
But my point was like instead of passing idflags while building kubelet why cannot we use a version data, by this we can ensure that we are using correct code base as intended else we could have a case where in we are using release of 1.32 and while building we have unknowing added version as 1.31(as shown in code block below). So, to avoid that confusion I was suggesting this PR.

KUBE_GIT_VERSION="1.31.0"
KUBE_GIT_COMMIT=$(git rev-parse HEAD)
KUBE_GIT_TREE_STATE=clean
KUBE_GIT_MAJOR=$(echo $KUBE_GIT_VERSION | sed 's/v\([0-9]*\)\..*/\1/')
KUBE_GIT_MINOR=$(echo $KUBE_GIT_VERSION | sed 's/v[0-9]*\.\([0-9]*\).*/\1/')
LDFLAGS="-X [k8s.io/component-base/version.gitVersion=$](http://k8s.io/component-base/version.gitVersion=$){KUBE_GIT_VERSION} \
         -X [k8s.io/component-base/version.gitCommit=$](http://k8s.io/component-base/version.gitCommit=$){KUBE_GIT_COMMIT} \
         -X [k8s.io/component-base/version.gitTreeState=$](http://k8s.io/component-base/version.gitTreeState=$){KUBE_GIT_TREE_STATE} \
         -X [k8s.io/component-base/version.gitMajor=$](http://k8s.io/component-base/version.gitMajor=$){KUBE_GIT_MAJOR} \
         -X [k8s.io/component-base/version.gitMinor=$](http://k8s.io/component-base/version.gitMinor=$){KUBE_GIT_MINOR}"
go build -ldflags "$LDFLAGS" ./cmd/kubelet

@BenTheElder
I am open to pick version from any other path if you guide me, as per my understanding I have used that path and have checked that we update version every release and currently master branch has version as v1.33.0-go1.24.2-bullseye.0

@liggitt
Copy link
Member

liggitt commented May 13, 2025

There are two approaches today:

  1. clone the repo normally and use the build scripts that derive versions from git tags
  2. clone the repo differently and override the version by setting KUBE_GIT_VERSION, etc

I don't think we should add a third way to derive version tags. If we want to try to improve detection of when the repo was not cloned normally build scripts are deriving unexpected git tags and error sooner, that could be ok if it is straightforward and reliable.

@sarkar-deb
Copy link
Author

If we want to try to improve detection of when the repo was not cloned normally build scripts are deriving unexpected git tags and error sooner, that could be ok if it is straightforward and reliable.

@liggitt , when git has given a way to perform shallow clone, why would we go and fail build rather we can use a way to derive versions and get it moving. Hope I got your comment correctly.

@liggitt
Copy link
Member

liggitt commented May 14, 2025

@liggitt , when git has given a way to perform shallow clone, why would we go and fail build rather we can use a way to derive versions and get it moving.

Doing a shallow clone is perfectly fine, but you are then responsible to provide the missing tag information by setting KUBE_GIT_VERSION. We don't want to add a second way to derive the version, especially since it will not be used by the official Kubernetes release, and will therefore be very likely to atrophy / stop working randomly.

@BenTheElder
Copy link
Member

BenTheElder commented May 14, 2025

@liggitt , when git has given a way to perform shallow clone, why would we go and fail build rather we can use a way to derive versions and get it moving. Hope I got your comment correctly.

you're not deriving the version in this PR, please see the comments on the issue linked above #131629 (comment)

Also, there are better alternatives to shallow clone (see the comment linked ... #131629 (comment))

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants