Skip to content

minikube cache add --all and minikube node start --delete-on-failure flags silently ignored #23347

Description

@nirs

What Happened?

Two commands register local flags with cobra but read them via viper.GetBool() without
binding the flag to viper. Since viper doesn't know about the flag, it always returns the
default value (false), and the flag is silently ignored.

Affected commands

minikube cache add --all

The --all flag is registered on addCacheCmd (cache.go:66) but read via
viper.GetBool("all") (cache.go:70). There is no viper.BindPFlags call for
addCacheCmd, so viper never sees the flag value.

Result: --all is silently ignored. Images are always loaded to the current profile
only, never to all profiles.

// cache.go:66 - flag registered on cobra
addCacheCmd.Flags().Bool(allFlag, false, "Add image to cache for all running minikube clusters")

// cache.go:70 - read via viper (never bound)
if viper.GetBool(allFlag) {

minikube node start --delete-on-failure

The --delete-on-failure flag is registered on nodeStartCmd (node_start.go:89) but
read via viper.GetBool(deleteOnFailure) (node_start.go:63). There is no
viper.BindPFlags call for nodeStartCmd.

Result: --delete-on-failure is silently ignored. The cluster is never deleted and
retried on failure.

// node_start.go:89 - flag registered on cobra
nodeStartCmd.Flags().Bool(deleteOnFailure, false, "If set, delete the current cluster if start fails and try again. Defaults to false.")

// node_start.go:63 - read via viper (never bound)
r, p, m, h, err := node.Provision(cc, n, viper.GetBool(deleteOnFailure), options)

Root cause

Viper has a single global namespace. Cobra has per-command flag sets. When a flag is
registered on a subcommand, it must be explicitly bound to viper via viper.BindPFlags()
for viper.Get*() to see it.

Only 3 commands bind their flags:

  • root.goRootCmd.PersistentFlags() (global flags like --profile)
  • start.gostartCmd.Flags()
  • delete.godeleteCmd.Flags()

All other commands that read local flags via viper.Get*() are broken.

Why BindPFlags can't simply be added

Multiple commands use the same flag names (e.g. --all on cache add, delete, and
stop). Since all init() functions run at startup regardless of which command is
invoked, binding the same name from multiple commands causes collisions — the last
binding wins.

Fix

  • minikube cache is deprecated — remove it instead of fixing.
  • minikube node start --delete-on-failure never worked — remove the flag. Nobody
    has complained about it, confirming it is not needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions