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

feat: add go ldflags for version info injection #313

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

a-hilaly
Copy link
Member

Add support for injecting version information at build time via ldflags. This includes:

  • Version, git commit hash, and build date injection in .ko.yaml
  • Updated metadata labeler to use dynamic version
  • Makefile updates to support version info injection

This label is not really useful since pod IDs change in HA setups, making
the label meaningless.
Add support for injecting version information at build time via ldflags. This includes:
- Version, git commit hash, and build date injection in `.ko.yaml`
- Updated metadata labeler to use dynamic version
- Makefile updates to support version info injection
$(KO) build --bare github.com/kro-run/kro/cmd/controller \
--local\
--push=false --tags ${RELEASE_VERSION} --sbom=none

.PHONY: publish
publish-image: ko ## Publish the kro controller images to ghcr.io
$(WITH_GOFLAGS) KOCACHE=$(KOCACHE) \
$(WITH_GOFLAGS) KOCACHE=$(KOCACHE) KO_DOCKER_REPO=$(KO_DOCKER_REPO) \
Copy link
Member

Choose a reason for hiding this comment

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

Is the fact the KO_DOCKER_REPO wasn't here before a bug?

KroVersionLabel = LabelKroPrefix + "kro-version"
ControllerPodIDLabel = LabelKroPrefix + "controller-pod-id"
OwnedLabel = LabelKroPrefix + "owned"
KroVersionLabel = LabelKroPrefix + "kro-version"
Copy link
Member

Choose a reason for hiding this comment

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

I'm being a super pedant here but:
https://google.github.io/styleguide/go/decisions#initialisms

KRO vs Kro.

Copy link
Member

Choose a reason for hiding this comment

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

This applies elsewhere in this file too.

kroVersion string,
controllerPodID string,
) GenericLabeler {
func NewKroMetaLabeler() GenericLabeler {
Copy link
Member

@matthchr matthchr Feb 19, 2025

Choose a reason for hiding this comment

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

What's the experience when running tests locally (in a KIND cluster, for example).

Are the labels set correctly? I looked at the makefile and I think they will be?
What about in envtest (less sure they will be there)?

Does it make sense to have this still be settable on the labeller and then have the envtest context specifically pass "something"? Or maybe we need envtest contexts to just set pkg.Version/etc correctly?

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.

2 participants