Skip to content

Move version/commitSHA vars out of internal/cli into a leaf package #4663

Description

@rh-hemartin

What happens

version and commitSHA are vars in internal/cli (root.go:9-10), set via -ldflags -X at build time. Any package that needs the version string must either import cli (which pulls in cobra, every subcommand, and all of cli's transitive dependencies) or receive it as a function parameter threaded from the call site.

Today telemetry.Setup() takes serviceVersion string as a parameter because internal/telemetry cannot import internal/cli without creating a cycle (cli already imports telemetry). The same threading happens in internal/binary/crosscompile.go, which reconstructs the ldflags path to inject the version into cross-compiled binaries.

What should happen

The two build-time vars and their accessors (Version(), CommitSHA()) should live in a dependency-free leaf package (e.g. internal/buildinfo) that any internal package can import without risk of cycles. The -ldflags -X paths in Makefile:102 and internal/binary/crosscompile.go:64 would update to point at the new package.

Callers that currently receive the version as a parameter (telemetry.Setup, and any future packages that need it) could import buildinfo directly instead of threading the value through multiple call sites.

Context

Came up during the OTel SDK migration (refactor/otel-sdk). telemetry.Setup needs the version to set service.version on the OTel resource, but can't import cli. Threading the string works, but as more packages need build metadata (the OTLP exporter, the OTel resource, user-agent headers), the parameter-passing accumulates. A leaf package removes the problem at the root.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/mediumNormal priority, plan for next cycletriagedTriaged but awaiting human prioritizationtype/choreMaintenance and housekeeping tasks

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions