Skip to content

hack/update: allow tests for any package that imports k8s.io/minikube/hack/update - #24092

Open
rawmeat21 wants to merge 2 commits into
kubernetes:masterfrom
rawmeat21:issue-24034
Open

rawmeat21 wants to merge 2 commits into
kubernetes:masterfrom
rawmeat21:issue-24034

Conversation

@rawmeat21

@rawmeat21 rawmeat21 commented Nov 20, 2026 •

Copy link
Copy Markdown

Fixes #24034

hack/update/update.go called flag.Parse() from init(), which ran before the generated test's main() called testing.Init() to register the -test.* flags. So, flag.Parse() would fail as it would see flags which weren't registered yet.

Changed hack/update/update.go's init() with an Init() with the same body:

  • At import, the same init() function is not present, so it won't run when k8s.io/minikube/hack/update is imported.
  • For testing, the generated main() function would not call update.Init(), so tests can be added now.

For every package that imports k8s.io/minikube/hack/update, I added an update.Init() line at the top of their main() function. So, the previous init()'s code still runs, and the functionality is preserved.

To test this, I created a docker_version_test.go (this file is not included in the fix) in hack/update/docker_version and ran the following commands:

❯ go test -v ./update/docker_version/
=== RUN   TestImportDoesNotRegisterFlags
--- PASS: TestImportDoesNotRegisterFlags (0.00s)
PASS
ok      k8s.io/minikube/hack/update/docker_version      0.005s

Before, this command would fail in the previous version:

❯ go test -v ./update/docker_version/
flag provided but not defined: -test.testlogfile
...
FAIL    k8s.io/minikube/hack/update/docker_version      0.005s
FAIL

The make update-* targets should also behave the same, for example, I ran the following command on my machine:

❯ make update-golint-version
cd hack && go run update/golint_version/golint_version.go
I1120 13:34:15.057748  351581 golint_version.go:60] Golint stable version: v2.15.0
I1120 13:34:15.058534  351581 update.go:90] The Plan:
{
  "Makefile": {
    "Content": null,
    "Replace": {
      "GOLINT_VERSION \\?= v2.*": "GOLINT_VERSION ?= v2.15.0"
    }
  }
}
I1120 13:34:15.058630  351581 update.go:97] Local repo update skipped: nothing changed

This gave the same output before and after the changes were made.

  • kubernetes-version flag also works as before.
  • go fmt and go vet are all clean.
  • go build ./update/... succeeds without errors.

I would also add that this fix requires every package which imports k8s.io/minikube/hack/update to add a update.Init() line at the top of their main function to initialise k8s.io/minikube/hack/update from now on. I hope that's okay, I'm open to making any improvements on this approach.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: rawmeat21 / name: Romit (9fc3375)

@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 20, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @rawmeat21!

It looks like this is your first PR to kubernetes/minikube 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/minikube has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @rawmeat21. 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.

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.

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Nov 20, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rawmeat21
Once this PR has been reviewed and has the lgtm label, please assign medyagh 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

@minikube-bot

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Nov 20, 2026
Comment thread hack/update/update.go
}

// used in update_kubeadm_constants.go
flag.String("kubernetes-version", "latest", "kubernetes-version")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This flag is used in update_kubeadm_constants.go - why is it defined here? Move it to the program that uses it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi, I'm haven't looked much into why it's defined there, this line was already present in the previous init() (which I renamed to Init()) function so I didn't give it much thought. Also, I tried finding an update_kubeadm_constants.go file but didn't really find one with that name. There is a kubeadm_constants.go file in hack/update/kubeadm_constants though. Are these supposed to be the same file?

Comment thread hack/update/update.go
}
if err := flag.Set("alsologtostderr", "true"); err != nil {
klog.Warningf("Unable to set flag value for alsologtostderr: %v", err)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need klog.InitFlags? Do we use klog in the update programs? We should switch to more ergonomic logger lize zap.

But before we switch, we need to understand if this is needed for all update programs, or only for some. If this is common, it makes sense to keep InitFlags() helper that all programs will use. If only some programs need this, we should drop this and initialize what we need in each program.

@rawmeat21 rawmeat21 Nov 25, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi, new to contributing here. klog.InitFlags was actually part of the existing code before I made the change. I did check though, seems like only a few files in hack/update don't use klogs, these files are: update_all/update_all.go, dockerhub.go, get_version/get_version.go, image.go and github.go. Rest of the files seem to use klogs.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok, so this is common setup that will be good to do in the update library. Just ned to make the function more clear (e.g. InitFlags() or AddCommonFlags())

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Alright, renamed update.Init() to update.InitFlags()

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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hack/update: tests can't run because update.go's init() parses flags at import time

3 participants