Skip to content

Conversation

@renormalize
Copy link
Member

What this PR does / why we need it:

Version information is not being logged at startup currently.

klog.V(3).Infof("Version: %+v", version.Get())

does not really print anything meaningful. Currently it prints the following:

I0416 03:47:56.984925       1 controllermanager.go:78] Version: v0.0.0-master+$Format:%H$

which is the template string present in client-go@v0.31.0/pkg/version/base.go. As described in the linked file a few lines above:

// If you are looking at these fields in the git tree, they look
// strange. They are modified on the fly by the build process. The
// in-tree values are dummy values used for "git archive", which also
// works for GitHub tar downloads.
//
// When releasing a new Kubernetes version, this file is updated by
// build/mark_new_version.sh to reflect the new version, and then a
// git annotated tag (using format vX.Y where X == Major version and Y
// == Minor version) is created to point to the commit that updates
// pkg/version/base.go

where the modification is not being done by the build process in this repository, and is unnecessarily complicated for what it does.

I've introduced a simple pkg/version/version.go where exported variables are written during linking through ldflags like other projects in @gardener.

Release note:

machine-controller-manager version, and build information are printed at startup.

@renormalize renormalize requested a review from a team as a code owner April 16, 2025 07:21
@gardener-robot gardener-robot added needs/review Needs review size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 16, 2025
@ghost ghost added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Apr 16, 2025
@gardener-robot-ci-2 gardener-robot-ci-2 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Apr 16, 2025
Signed-off-by: Saketh Kalaga <51327242+renormalize@users.noreply.github.com>
@gardener-robot-ci-1 gardener-robot-ci-1 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Apr 16, 2025
Copy link
Member

@aaronfern aaronfern left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

What is the impact when MCM runs locally as a process? I assume that Version and GitSha will not be printed. Is that correct?

@renormalize
Copy link
Member Author

renormalize commented Apr 16, 2025

Thanks for the review @aaronfern!

When MCM is run locally as a process, if the verbosity level is sufficient, then the Version and Git SHA are both printed.

❯ ./bin/machine-controller-manager --v=3
I0416 13:14:12.194054   91628 flags.go:57] FLAG: --address="0.0.0.0"
I0416 13:14:12.194453   91628 flags.go:57] FLAG: --autoscaler-scaldown-annotation-during-rollout="true"
...a bunch of flags...
I0416 13:14:12.194513   91628 flags.go:57] FLAG: --v="3"
I0416 13:14:12.194515   91628 flags.go:57] FLAG: --vmodule=""
I0416 13:14:12.194538   91628 version.go:24] machine-controller-manager Version: v0.58.0-dev
I0416 13:14:12.194543   91628 version.go:25] Git SHA: 48cab6d7e
I0416 13:14:12.194546   91628 version.go:26] Go Version: go1.24.2
I0416 13:14:12.194549   91628 version.go:27] Go OS/Arch: darwin/arm64
W0416 13:14:12.194557   91628 client_config.go:659] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
W0416 13:14:12.194562   91628 client_config.go:664] error creating inClusterConfig, falling back to default config: unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined
invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

The logs print Git SHA 48cab6d, which is the commit on this PR branch 48cab6d.

When verbosity is not sufficient:

❯ ./bin/machine-controller-manager
W0416 13:17:02.278256   92616 client_config.go:659] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
W0416 13:17:02.278834   92616 client_config.go:664] error creating inClusterConfig, falling back to default config: unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined
invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable

@ghost ghost added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Apr 16, 2025
@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Apr 16, 2025
@aaronfern
Copy link
Member

When MCM is run locally as a process, if the verbosity level is sufficient, then the Version and Git SHA are both printed.

I meant more from the pov of someone running make start or go run cmd/machine-controller-manager/controller_manager.go <flags>

@renormalize
Copy link
Member Author

The Git SHA word is left empty, and the binary proceeds running as is, no regression is observed.

❯ make start
I0416 13:23:27.775232   95046 flags.go:57] FLAG: --address="0.0.0.0"
I0416 13:23:27.775294   95046 flags.go:57] FLAG: --autoscaler-scaldown-annotation-during-rollout="true"
...a bunch of flags...
I0416 13:23:27.775334   95046 flags.go:57] FLAG: --v="3"
I0416 13:23:27.775335   95046 flags.go:57] FLAG: --vmodule=""
I0416 13:23:27.775347   95046 version.go:24] machine-controller-manager Version:
I0416 13:23:27.775349   95046 version.go:25] Git SHA:
I0416 13:23:27.775351   95046 version.go:26] Go Version: go1.24.2
I0416 13:23:27.775353   95046 version.go:27] Go OS/Arch: darwin/arm64
W0416 13:23:27.775357   95046 client_config.go:659] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
W0416 13:23:27.775362   95046 client_config.go:664] error creating inClusterConfig, falling back to default config: unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined
invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
exit status 1

Perhaps I could enhance the start make target to include the Git SHA and Version as well. However, the user running go run cmd/machine-controller-manager/controller_manager.go <flags> will have to pass the necessary linking flags themselves to see the Version and Git SHA.

@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Apr 16, 2025
@ghost ghost removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Apr 16, 2025
@renormalize
Copy link
Member Author

The start target has been enhanced as well, in 2c39f8a.

❯ git log -1
commit 2c39f8abfe5a72f08f7fee428b64f01676b4966e (HEAD -> version, origin/version)
Author: Saketh Kalaga <51327242+renormalize@users.noreply.github.com>
Date:   Wed Apr 16 13:44:19 2025 +0530

    Add `ldflags` to the `start` make target.
[I] ~/go/src/github.com/gardener/machine-controller-manager (version)
❯ make start
I0416 13:47:47.820233    8115 flags.go:57] FLAG: --address="0.0.0.0"
I0416 13:47:47.820521    8115 flags.go:57] FLAG: --autoscaler-scaldown-annotation-during-rollout="true"
...a bunch of flags...
I0416 13:47:47.820562    8115 flags.go:57] FLAG: --v="3"
I0416 13:47:47.820564    8115 flags.go:57] FLAG: --vmodule=""
I0416 13:47:47.820608    8115 version.go:24] machine-controller-manager Version: v0.58.0-dev
I0416 13:47:47.820611    8115 version.go:25] Git SHA: 2c39f8abf
I0416 13:47:47.820613    8115 version.go:26] Go Version: go1.24.2
I0416 13:47:47.820615    8115 version.go:27] Go OS/Arch: darwin/arm64
W0416 13:47:47.820638    8115 client_config.go:659] Neither --kubeconfig nor --master was specified.  Using the inClusterConfig.  This might not work.
W0416 13:47:47.820641    8115 client_config.go:664] error creating inClusterConfig, falling back to default config: unable to load in-cluster configuration, KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT must be defined
invalid configuration: no configuration has been provided, try setting KUBERNETES_MASTER environment variable
exit status 1
make: *** [start] Error 1

@renormalize renormalize requested a review from aaronfern April 16, 2025 08:19
Copy link
Member

@aaronfern aaronfern left a comment

Choose a reason for hiding this comment

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

Thanks for the changes!
/lgtm

@gardener-robot gardener-robot added reviewed/lgtm Has approval for merging and removed needs/review Needs review labels Apr 16, 2025
@ghost ghost added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Apr 16, 2025
@aaronfern aaronfern merged commit dc78d82 into gardener:master Apr 29, 2025
8 checks passed
@gardener-robot gardener-robot added the status/closed Issue is closed (either delivered or triaged) label Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) reviewed/lgtm Has approval for merging reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) size/S Denotes a PR that changes 10-29 lines, ignoring generated files. status/closed Issue is closed (either delivered or triaged)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants