Skip to content

CNF-11589: Embed commit SHA and version info into LCA binaries#6308

Open
sebrandon1 wants to merge 1 commit into
openshift-kni:mainfrom
sebrandon1:CNF-11589/embed-version-info
Open

CNF-11589: Embed commit SHA and version info into LCA binaries#6308
sebrandon1 wants to merge 1 commit into
openshift-kni:mainfrom
sebrandon1:CNF-11589/embed-version-info

Conversation

@sebrandon1
Copy link
Copy Markdown
Contributor

Jira: CNF-11589

Summary

  • Add version/ package with Version, GitCommit, and BuildTime variables injected via -ldflags at build time
  • Update Makefile build and cli-build targets to pass -ldflags with version info
  • Update Dockerfile and Dockerfile.multiarch to inject VERSION, GIT_COMMIT, and BUILD_TIME build args into all go build commands
  • Wire lca-cli --version to print version string (replaces unused releaseVersion variable)
  • Log version info at manager startup

Example output:

$ lca-cli --version
lca-cli version 5.0.0 (commit: d7d630512, built: 2026-04-30T20:12:56Z)

Test plan

  • make build — manager binary compiles with ldflags
  • make cli-build — lca-cli binary compiles with ldflags
  • bin/lca-cli --version — prints version, commit SHA, and build time
  • make golangci-lint — 0 issues
  • make unittest — 0 failures

@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Apr 30, 2026

@sebrandon1: This pull request references CNF-11589 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Jira: CNF-11589

Summary

  • Add version/ package with Version, GitCommit, and BuildTime variables injected via -ldflags at build time
  • Update Makefile build and cli-build targets to pass -ldflags with version info
  • Update Dockerfile and Dockerfile.multiarch to inject VERSION, GIT_COMMIT, and BUILD_TIME build args into all go build commands
  • Wire lca-cli --version to print version string (replaces unused releaseVersion variable)
  • Log version info at manager startup

Example output:

$ lca-cli --version
lca-cli version 5.0.0 (commit: d7d630512, built: 2026-04-30T20:12:56Z)

Test plan

  • make build — manager binary compiles with ldflags
  • make cli-build — lca-cli binary compiles with ldflags
  • bin/lca-cli --version — prints version, commit SHA, and build time
  • make golangci-lint — 0 issues
  • make unittest — 0 failures

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci Bot requested review from leo8a and pixelsoccupied April 30, 2026 20:32
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Apr 30, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

Details 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

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Review limit reached

@sebrandon1, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 41 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: fa6ceec4-27ad-4c8a-8e5d-393e6284747d

📥 Commits

Reviewing files that changed from the base of the PR and between 94aa19b and 1658154.

📒 Files selected for processing (5)
  • Dockerfile
  • Makefile
  • lca-cli/cmd/root.go
  • main/main.go
  • version/version.go
📝 Walkthrough

Walkthrough

This change introduces version metadata injection into Go binaries during the build process. A new version package exports configurable strings for version, git commit, and build time. Build configurations (Dockerfile, Dockerfile.multiarch, Makefile) are updated to inject these values via Go's -ldflags mechanism. Application code wires version retrieval to display at startup and in the CLI.

Changes

Cohort / File(s) Summary
Build Infrastructure
Dockerfile, Dockerfile.multiarch, Makefile
Added build arguments (GIT_COMMIT, VERSION) and dynamic -ldflags generation to inject version metadata (version.Version, version.GitCommit, version.BuildTime) into binaries during compilation. Dockerfile.multiarch introduces a new multi-stage build with parameterized builder and UBI-based runtime image.
Version Package
version/version.go
New package exposing exported string variables (Version, GitCommit, BuildTime) initialized to "unknown" and a String() function that formats version information for display.
Application Integration
main/main.go, lca-cli/cmd/root.go
Updated to retrieve and display version from the shared version package via version.String() instead of local version variables; added startup log entry in main.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: embedding version and commit information into LCA binaries, directly matching the core objective of the pull request.
Description check ✅ Passed The description covers all critical sections with a clear summary, test plan checklist, and Jira reference, though it omits some recommended template sections like Background/Context and Implementation Details.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Dockerfile`:
- Around line 11-12: Add BUILD_TIME as a build-time argument and stop generating
it inside the layer: declare ARG BUILD_TIME (alongside ARG GIT_COMMIT and ARG
VERSION) and replace any RUN-step logic that computes or writes a timestamp
during the build with usage of the BUILD_TIME arg so callers can supply a
deterministic value; also update the same pattern referenced in the later block
(the lines around the second occurrence) to use ARG BUILD_TIME instead of
generating a timestamp inside the image.

In `@Dockerfile.multiarch`:
- Around line 11-12: Add a new build arg ARG BUILD_TIME and use it where build
timestamp metadata is set so the timestamp comes from the build invocation
rather than a cacheable layer; update the ARG declarations (alongside ARG
GIT_COMMIT and ARG VERSION) and ensure any places that previously relied on a
generated timestamp (including the secondary block around the other ARGs at the
later section referenced) consume BUILD_TIME so multiarch rebuilds pick up
current build metadata.

In `@Makefile`:
- Around line 41-46: The docker-build target currently omits the version
metadata injection (VERSION, GIT_COMMIT, BUILD_TIME / LDFLAGS) so images are
built with default metadata; update the docker-build rule to forward the same
build information used by build and cli-build by adding the appropriate
--build-arg flags (VERSION, GIT_COMMIT, BUILD_TIME) or exporting LDFLAGS into
the docker build command so the Dockerfile can use them during the internal go
build; ensure the docker-build target mirrors the behavior of build and
cli-build and include the same LDFLAGS/args so binaries inside the image receive
the injected Version, GitCommit, and BuildTime values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 00add334-f7eb-480c-8436-0db97d83e991

📥 Commits

Reviewing files that changed from the base of the PR and between 8954604 and 94aa19b.

📒 Files selected for processing (6)
  • Dockerfile
  • Dockerfile.multiarch
  • Makefile
  • lca-cli/cmd/root.go
  • main/main.go
  • version/version.go

Comment thread Dockerfile
Comment thread Dockerfile.multiarch Outdated
Comment thread Makefile
@sebrandon1 sebrandon1 force-pushed the CNF-11589/embed-version-info branch 2 times, most recently from 5cf32f3 to 69b3f37 Compare April 30, 2026 21:33
@sebrandon1 sebrandon1 force-pushed the CNF-11589/embed-version-info branch from 69b3f37 to 45a639f Compare May 28, 2026 18:12
Add a version package with Version, GitCommit, and BuildTime variables
injected via -ldflags at build time. Both the manager and lca-cli
binaries now report build provenance, making it straightforward to
identify exactly which commit is running in production.

- Add version/ package with String() formatter
- Update Makefile build/cli-build targets with -ldflags
- Forward VERSION, GIT_COMMIT, BUILD_TIME as --build-arg in docker-build
- Update Dockerfile to accept and use all three build args
- Wire lca-cli --version to print version string
- Log version at manager startup
@sebrandon1 sebrandon1 force-pushed the CNF-11589/embed-version-info branch from 45a639f to 1658154 Compare May 29, 2026 16:51
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented May 29, 2026

@sebrandon1: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/ipc-e2e-flow-v4v6 1658154 link false /test ipc-e2e-flow-v4v6
ci/prow/ibu-e2e-flow-v4v6 1658154 link false /test ibu-e2e-flow-v4v6
ci/prow/ibi-e2e-flow-v6v4 1658154 link false /test ibi-e2e-flow-v6v4
ci/prow/ibu-e2e-flow-v6v4 1658154 link false /test ibu-e2e-flow-v6v4
ci/prow/ibu-e2e-flow 1658154 link false /test ibu-e2e-flow
ci/prow/ipc-e2e-flow 1658154 link true /test ipc-e2e-flow
ci/prow/ipc-e2e-flow-v6v4 1658154 link false /test ipc-e2e-flow-v6v4
ci/prow/ibi-e2e-flow 1658154 link false /test ibi-e2e-flow
ci/prow/ibi-e2e-flow-v4v6 1658154 link false /test ibi-e2e-flow-v4v6

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants