Skip to content

Conversation

nirs
Copy link
Contributor

@nirs nirs commented Oct 2, 2025

Currently we use viper outside of cmd/minikube/cmd package in pkg/minikube/** and pkg/drivers/**. This introduce 2 issues:

  • Make the code hard to test by using global state. For example for testing interactive mode we must use viper.SetBool("interactive", false). This may break another test assuming interactive mode.
  • Error prone - since the flag names are private constants in the cmd/minikube/cmd package, we use strings (e.g. "interactive") in other package. A typo in the flag name will silently provide the wrong value, ignoring the user request.

This is the first part in removing viper calls outside of the cmd/minikube/cmd package.

Preparations

  • run: Introduce minikube/run.Options - add the basic infrastructure for passing options from the command down to the drivers via the registry.Configurator() interface.
  • run: Prepare for using run.Options in vment - pass options to registry.StatusChecker() interface to allow passing options from krunkit driver.
  • run: Add run.Options.NonInteractive option - pass the --interactive flag
  • run: Introduce the flags package

Removals

  • vment: Remove viper interactive check - remove viper.GetBool("interactive") check in vment.ValidateHelper()
  • firewall: Remove viper interactive check - remove viper.GetBool("interactive") check in firewall.UnblockBootpd()
  • notify: Remove viper interactive checks - remove viper.GetBool("interactive") check in notify.shouldCheckURLVersion()

Known issues

  • When starting a stopped cluster we get the default Driver.Options, but we should really use Options from the command line. I did not find yet how the Driver section from ~/.minikube/machines/NAME/config.json is parsed and converted to a concrete Driver struct.

Part-of #21670

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 2, 2025
@k8s-ci-robot k8s-ci-robot requested review from medyagh and prezha October 2, 2025 18:15
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

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

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 2, 2025
@nirs
Copy link
Contributor Author

nirs commented Oct 2, 2025

/cc @ComradeProgrammer
/cc @afbjorklund

@nirs
Copy link
Contributor Author

nirs commented Oct 2, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Oct 2, 2025
@nirs nirs force-pushed the remove-viper-checks branch from 1a26ae8 to cf26111 Compare October 2, 2025 19:25
@afbjorklund afbjorklund removed their request for review October 2, 2025 19:26
Copy link
Member

@medyagh medyagh left a comment

Choose a reason for hiding this comment

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

thank you for doing this ! this is gonna make minikube development much safer (and less suprises)

@medyagh
Copy link
Member

medyagh commented Oct 2, 2025

/ok-to-test

@minikube-pr-bot

This comment has been minimized.

@nirs

This comment was marked as outdated.

@minikube-pr-bot

This comment has been minimized.

Copy link
Member

@medyagh medyagh left a comment

Choose a reason for hiding this comment

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

we should make to document this in the contributors guide
to never make a viper call outside CMD packages

@nirs nirs changed the title Start removing viper calls in minikube Prepare for removing viper from minikube and driver packages Oct 6, 2025
@nirs nirs requested a review from medyagh October 6, 2025 20:34
@nirs
Copy link
Contributor Author

nirs commented Oct 6, 2025

@medyagh I remove all options, leaving only the infrastructure for adding options from the root command down to the driver.

The next pull commits (or pull requests) will remove one viper option per commit to keep this easy to review and less likely to break.

@nirs nirs force-pushed the remove-viper-checks branch from f46905b to d752111 Compare October 6, 2025 20:41
@nirs nirs marked this pull request as ready for review October 6, 2025 20:56
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 6, 2025
@minikube-pr-bot

This comment has been minimized.

@minikube-pr-bot

This comment has been minimized.

@nirs nirs force-pushed the remove-viper-checks branch from 5e86397 to 239003c Compare October 7, 2025 16:40
@nirs nirs changed the title Prepare for removing viper from minikube and driver packages Remove viper from minikube and driver packages - part 1 Oct 7, 2025
@nirs nirs force-pushed the remove-viper-checks branch 2 times, most recently from 16b6ee0 to 3e67c8e Compare October 7, 2025 18:46
// commandOptions creates minikube runtime options from the command line flags.
// Flags that must be handled outside of the cmd package must be added to
// run.Options.
func commandOptions() *run.Options {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is moved to cmd/flags.Options in later commit since this function does not work for sharing options in cmd/config.

@nirs nirs force-pushed the remove-viper-checks branch from 3e67c8e to c7fcd88 Compare October 7, 2025 20:29
@minikube-pr-bot

This comment has been minimized.

@minikube-pr-bot

This comment has been minimized.

@nirs nirs force-pushed the remove-viper-checks branch from c7fcd88 to 9daa62a Compare October 8, 2025 13:10
@minikube-pr-bot

This comment has been minimized.

@minikube-pr-bot

This comment has been minimized.

nirs added 7 commits October 9, 2025 21:17
Preparing for removal of viper usage outside of cmd/minikube/cmd
package, add a minikube/run.Options type for keeping command line
options from viper and passing to the library code.

We need to pass options through many layers:

    cmd -> node -> machine -> registry -> driver

The libmachine Driver API does not have a way to pass options, so we
need to keep the options in the driver struct.

drivers/common.CommonDriver keeps now Options field. This field is
initialized when a driver is configured in the registry,
registry.Configurator interface accept now *run.Options.

Configuration happens only when the cluster is created.  Driver.Options
is not persisted so on the next start options contains the zero value
with the defaults.

The driver config function is called by the machine package, which is
called by the node package, which called from the `start`, `node add`,
and `node start` command. We go back from the driver config function and
add the options argument until we reach the command code.

In the cmd package, the options are created by new commandOptions()
helper.
To remove viper.GetBool("interactive") call in vment.ValidateHelper() we
need to pass the options to the function. It is called from
minikube/registry/drvs/krunkit.status(). Update registry.StatusChecker
to accept *run.Options, and relevant code so options pass from `start`,
`node add`, and `node start` command pass options to the driver status()
function.

Unify the way we create the options in the cmd package. The options are
always created in the runCommand function, so we have one call per
command that need to pass options down to minikube.

With this change we are ready to remove the first viper call.
This option keeps the value of the --interactive flag. We keep the
negative value so the zero value of run.Options use the default value.
This expose the default options for drivers, using zero value of
drivers/common/CommandDriver.Options.

This options should be handled in several places, this change only add
the option.
We need to use pass options from cmd/config, but commandOptions() is a
private function of the cmd package. We want to have single function for
creating runtime options shared with the minikube packages, accessible
from cmd and cmd/config (and other future packages). Add a new
cmd/flags package keeping the flags names needed for creating
run.Options and move commandOptions() to flag.Options().

The `interactive` constant was moved from form start_flags.go to the new
package.

We can move later all flags to the new package, but I started with the
minimal change.
vment.ValidateHelper() accept now *run.Options and use
options.NonInteractive to check if interaction is allowed.  Update
callers to pass options from the minikube command.

Testing non-interactive mode:

    % sudo rm /etc/sudoers.d/vmnet-helper
    % sudo -k
    % out/minikube start -d krunkit --interactive=false
    😄  minikube v1.37.0 on Darwin 26.0.1 (arm64)
    ✨  Using the krunkit (experimental) driver based on user configuration

    🤷  Exiting due to PROVIDER_KRUNKIT_NOT_FOUND: The 'krunkit' provider was not found: exit status 1: sudo: a password is required
    💡  Suggestion: Install and configure vment-helper
    📘  Documentation: https://minikube.sigs.k8s.io/docs/reference/drivers/krunkit/

Testing interactive mode:

    % out/minikube start -d krunkit
    😄  minikube v1.37.0 on Darwin 26.0.1 (arm64)
    💡  Unable to run vmnet-helper without a password
        To configure vment-helper to run without a password, please check the documentation:
        https://github.com/nirs/vmnet-helper/#granting-permission-to-run-vmnet-helper
    Password:
    ✨  Using the krunkit (experimental) driver based on user configuration
    👍  Starting "minikube" primary control-plane node in "minikube" cluster
    🔥  Creating krunkit VM (CPUs=2, Memory=6144MB, Disk=20000MB) ...
    🐳  Preparing Kubernetes v1.34.1 on Docker 28.4.0 ...
    🔗  Configuring bridge CNI (Container Networking Interface) ...
    🔎  Verifying Kubernetes components...
        ▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
    🌟  Enabled addons: default-storageclass, storage-provisioner
    🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
filewall.UnblockBootpd() accepts now *run.Options and use it to check if
we can interact with the user. Update callers to pass options.

To make this work for drivers, we initialize the driver CommonDriver
with the options from the command line in the driver configure()
functions for vfkit, qemu, and krunkit. Other drivers do not need this
flag so they use the zero value with the defaults.
The notify helpers accept now *run.Options and use it to check if we can
interact with the user. Modify callers to pass options using
cmd/flags.Options().
@nirs nirs force-pushed the remove-viper-checks branch from 9daa62a to ec1ad26 Compare October 9, 2025 18:17
@k8s-ci-robot
Copy link
Contributor

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

Test name Commit Details Required Rerun command
pull-minikube-integration ec1ad26 link true /test pull-minikube-integration

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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.

@minikube-pr-bot
Copy link

kvm2 driver with docker runtime

┌───────────────────┬──────────┬────────────────────────┐
│      COMMAND      │ MINIKUBE │ MINIKUBE  ( PR 21683 ) │
├───────────────────┼──────────┼────────────────────────┤
│ minikube start    │ 45.5s    │ 44.2s                  │
│ ⚠️  enable ingress │ 16.6s    │ 27.7s ⚠️                │
└───────────────────┴──────────┴────────────────────────┘

Times for minikube start: 47.6s 45.4s 44.4s 45.0s 45.3s
Times for minikube (PR 21683) start: 44.5s 43.5s 45.3s 43.3s 44.5s

Times for minikube ingress: 16.3s 16.9s 15.8s 17.9s 15.9s
Times for minikube (PR 21683) ingress: 15.8s 15.8s 75.3s 15.9s 15.8s

docker driver with docker runtime

┌────────────────┬──────────┬────────────────────────┐
│    COMMAND     │ MINIKUBE │ MINIKUBE  ( PR 21683 ) │
├────────────────┼──────────┼────────────────────────┤
│ minikube start │ 23.3s    │ 23.8s                  │
│ enable ingress │ 11.6s    │ 11.4s                  │
└────────────────┴──────────┴────────────────────────┘

Times for minikube start: 24.7s 20.2s 25.9s 22.5s 23.1s
Times for minikube (PR 21683) start: 21.1s 25.9s 22.8s 22.8s 26.6s

Times for minikube ingress: 10.6s 10.6s 13.7s 10.6s 12.6s
Times for minikube (PR 21683) ingress: 12.6s 10.6s 10.6s 12.6s 10.6s

docker driver with containerd runtime

┌────────────────┬──────────┬────────────────────────┐
│    COMMAND     │ MINIKUBE │ MINIKUBE  ( PR 21683 ) │
├────────────────┼──────────┼────────────────────────┤
│ minikube start │ 20.8s    │ 21.3s                  │
│ enable ingress │ 26.7s    │ 26.3s                  │
└────────────────┴──────────┴────────────────────────┘

Times for minikube start: 19.7s 20.2s 23.9s 19.9s 20.5s
Times for minikube (PR 21683) start: 22.8s 19.3s 21.6s 20.9s 21.9s

Times for minikube ingress: 20.1s 20.1s 20.1s 50.1s 23.1s
Times for minikube (PR 21683) ingress: 20.1s 20.1s 21.1s 50.2s 20.1s

@minikube-pr-bot
Copy link

Here are the number of top 10 failed tests in each environments with lowest flake rate.

Environment Test Name Flake Rate
Docker_Windows (1 failed) TestErrorSpam/setup(gopogh) Unknown

Besides the following environments also have failed tests:

To see the flake rates of all tests by environment, click here.

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants