fix lint errors

pull/18142/head
Steven Powell 2024-02-12 17:32:14 -08:00
parent 58b7fcacfa
commit 4d32230e3e
63 changed files with 110 additions and 116 deletions

View File

@ -47,7 +47,7 @@ var addCacheCmd = &cobra.Command{
Use: "add",
Short: "Add an image to local cache.",
Long: "Add an image to local cache.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
out.WarningT("\"minikube cache\" will be deprecated in upcoming versions, please switch to \"minikube image load\"")
// Cache and load images into docker daemon
if err := machine.CacheAndLoadImages(args, cacheAddProfiles(), false); err != nil {
@ -85,7 +85,7 @@ var deleteCacheCmd = &cobra.Command{
Use: "delete",
Short: "Delete an image from the local cache.",
Long: "Delete an image from the local cache.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
// Delete images from config file
if err := cmdConfig.DeleteFromConfigMap(cacheImageConfigKey, args); err != nil {
exit.Error(reason.InternalDelConfig, "Failed to delete images from config", err)
@ -102,7 +102,7 @@ var reloadCacheCmd = &cobra.Command{
Use: "reload",
Short: "reload cached images.",
Long: "reloads images previously added using the 'cache add' subcommand",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
err := node.CacheAndLoadImagesInConfig(cacheAddProfiles())
if err != nil {
exit.Error(reason.GuestCacheLoad, "Failed to reload cached images", err)

View File

@ -40,7 +40,7 @@ var listCacheCmd = &cobra.Command{
Use: "list",
Short: "List all available images from the local cache.",
Long: "List all available images from the local cache.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
images, err := cmdConfig.ListConfigMap(cacheImageConfigKey)
if err != nil {
exit.Error(reason.InternalListConfig, "Failed to get image map", err)

View File

@ -81,7 +81,7 @@ var completionCmd = &cobra.Command{
Use: "completion SHELL",
Short: "Generate command completion for a shell",
Long: longDescription,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 1 {
exit.Message(reason.Usage, "Usage: minikube completion SHELL")
}
@ -95,7 +95,7 @@ var bashCmd = &cobra.Command{
Use: "bash",
Short: "bash completion.",
Long: "Generate command completion for bash.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
err := GenerateBashCompletion(os.Stdout, cmd.Root())
if err != nil {
exit.Error(reason.InternalCompletion, "bash completion failed", err)
@ -107,7 +107,7 @@ var zshCmd = &cobra.Command{
Use: "zsh",
Short: "zsh completion.",
Long: "Generate command completion for zsh.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
err := GenerateZshCompletion(os.Stdout, cmd.Root())
if err != nil {
exit.Error(reason.InternalCompletion, "zsh completion failed", err)
@ -119,7 +119,7 @@ var fishCmd = &cobra.Command{
Use: "fish",
Short: "fish completion.",
Long: "Generate command completion for fish .",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
err := GenerateFishCompletion(os.Stdout, cmd.Root())
if err != nil {
exit.Error(reason.InternalCompletion, "fish completion failed", err)
@ -131,7 +131,7 @@ var powershellCmd = &cobra.Command{
Use: "powershell",
Short: "powershell completion.",
Long: "Generate command completion for PowerShell.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
err := GeneratePowerShellCompletion(os.Stdout, cmd.Root())
if err != nil {
exit.Error(reason.InternalCompletion, "powershell completion failed", err)

View File

@ -27,7 +27,7 @@ var AddonsCmd = &cobra.Command{
Use: "addons SUBCOMMAND [flags]",
Short: "Enable or disable a minikube addon",
Long: `addons modifies minikube addons files using subcommands like "minikube addons enable dashboard"`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
if err := cmd.Help(); err != nil {
klog.Errorf("help: %v", err)
}

View File

@ -48,7 +48,7 @@ var addonsListCmd = &cobra.Command{
Use: "list",
Short: "Lists all available minikube addons as well as their current statuses (enabled/disabled)",
Long: "Lists all available minikube addons as well as their current statuses (enabled/disabled)",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 0 {
exit.Message(reason.Usage, "usage: minikube addons list")
}

View File

@ -180,7 +180,7 @@ var ConfigCmd = &cobra.Command{
Short: "Modify persistent configuration values",
Long: `config modifies minikube config files using subcommands like "minikube config set driver kvm2"
Configurable fields: ` + "\n\n" + configurableFields(),
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
if err := cmd.Help(); err != nil {
klog.ErrorS(err, "help")
}

View File

@ -40,7 +40,7 @@ var addonsConfigureCmd = &cobra.Command{
Use: "configure ADDON_NAME",
Short: "Configures the addon w/ADDON_NAME within minikube (example: minikube addons configure registry-creds). For a list of available addons use: minikube addons list",
Long: "Configures the addon w/ADDON_NAME within minikube (example: minikube addons configure registry-creds). For a list of available addons use: minikube addons list",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 1 {
exit.Message(reason.Usage, "usage: minikube addons configure ADDON_NAME")
}

View File

@ -31,7 +31,7 @@ var addonsDisableCmd = &cobra.Command{
Use: "disable ADDON_NAME",
Short: "Disables the addon w/ADDON_NAME within minikube (example: minikube addons disable dashboard). For a list of available addons use: minikube addons list ",
Long: "Disables the addon w/ADDON_NAME within minikube (example: minikube addons disable dashboard). For a list of available addons use: minikube addons list ",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 1 {
exit.Message(reason.Usage, "usage: minikube addons disable ADDON_NAME")
}

View File

@ -37,7 +37,7 @@ var addonsEnableCmd = &cobra.Command{
Short: "Enables the addon w/ADDON_NAME within minikube. For a list of available addons use: minikube addons list ",
Long: "Enables the addon w/ADDON_NAME within minikube. For a list of available addons use: minikube addons list ",
Example: "minikube addons enable dashboard",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 1 {
exit.Message(reason.Usage, "usage: minikube addons enable ADDON_NAME")
}

View File

@ -32,7 +32,7 @@ var addonsImagesCmd = &cobra.Command{
Short: "List image names the addon w/ADDON_NAME used. For a list of available addons use: minikube addons list",
Long: "List image names the addon w/ADDON_NAME used. For a list of available addons use: minikube addons list",
Example: "minikube addons images ingress",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 1 {
exit.Message(reason.Usage, "usage: minikube addons images ADDON_NAME")
}

View File

@ -46,14 +46,14 @@ var addonsOpenCmd = &cobra.Command{
Use: "open ADDON_NAME",
Short: "Opens the addon w/ADDON_NAME within minikube (example: minikube addons open dashboard). For a list of available addons use: minikube addons list ",
Long: "Opens the addon w/ADDON_NAME within minikube (example: minikube addons open dashboard). For a list of available addons use: minikube addons list ",
PreRun: func(cmd *cobra.Command, args []string) {
PreRun: func(_ *cobra.Command, _ []string) {
t, err := template.New("addonsURL").Parse(addonsURLFormat)
if err != nil {
exit.Message(reason.Usage, "The value passed to --format is invalid: {{.error}}", out.V{"error": err})
}
addonsURLTemplate = t
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 1 {
exit.Message(reason.Usage, "usage: minikube addons open ADDON_NAME")
}

View File

@ -34,7 +34,7 @@ var ProfileCmd = &cobra.Command{
Use: "profile [MINIKUBE_PROFILE_NAME]. You can return to the default minikube profile by running `minikube profile default`",
Short: "Get or list the current profiles (clusters)",
Long: "profile sets the current minikube profile, or gets the current profile if no arguments are provided. This is used to run and manage multiple minikube instance. You can return to the default minikube profile by running `minikube profile default`",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) == 0 {
profile := ClusterFlagValue()
out.Styled(style.Empty, profile)

View File

@ -49,7 +49,7 @@ var profileListCmd = &cobra.Command{
Use: "list",
Short: "Lists all minikube profiles.",
Long: "Lists all valid minikube profiles and detects all possible invalid profiles.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
output := strings.ToLower(profileOutput)
out.SetJSON(output == "json")
go notify.MaybePrintUpdateTextFromGithub()

View File

@ -31,7 +31,7 @@ var configSetCmd = &cobra.Command{
Short: "Sets an individual value in a minikube config file",
Long: `Sets the PROPERTY_NAME config value to PROPERTY_VALUE
These values can be overwritten by flags or environment variables at runtime.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) < 2 {
exit.Message(reason.Usage, "not enough arguments ({{.ArgCount}}).\nusage: minikube config set PROPERTY_NAME PROPERTY_VALUE", out.V{"ArgCount": len(args)})
}

View File

@ -28,7 +28,7 @@ var configUnsetCmd = &cobra.Command{
Use: "unset PROPERTY_NAME",
Short: "unsets an individual value in a minikube config file",
Long: "unsets PROPERTY_NAME from the minikube config file. Can be overwritten by flags or environmental variables",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 1 {
exit.Message(reason.Usage, "usage: minikube config unset PROPERTY_NAME")
}

View File

@ -41,7 +41,7 @@ var configViewCmd = &cobra.Command{
Use: "view",
Short: "Display values currently set in the minikube config file",
Long: "Display values currently set in the minikube config file.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
err := View()
if err != nil {
exit.Error(reason.InternalConfigView, "config view failed", err)

View File

@ -52,7 +52,7 @@ Default target node controlplane and If <source node name> is omitted, It will t
Example Command : "minikube cp a.txt /home/docker/b.txt" +
"minikube cp a.txt minikube-m02:/home/docker/b.txt"
"minikube cp minikube-m01:a.txt minikube-m02:/home/docker/b.txt"`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 2 {
exit.Message(reason.Usage, `Please specify the path to copy:
minikube cp <source file path> <target file absolute path> (example: "minikube cp a/b.txt /copied.txt")`)

View File

@ -57,7 +57,7 @@ var dashboardCmd = &cobra.Command{
Use: "dashboard",
Short: "Access the Kubernetes dashboard running within the minikube cluster",
Long: `Access the Kubernetes dashboard running within the minikube cluster`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
cname := ClusterFlagValue()
co := mustload.Healthy(cname)

View File

@ -145,9 +145,7 @@ func TestDeleteProfile(t *testing.T) {
}
}
var hostAndDirsDeleterMock = func(api libmachine.API, cc *config.ClusterConfig, profileName string) error {
return deleteContextTest()
}
var hostAndDirsDeleterMock = func(_ libmachine.API, _ *config.ClusterConfig, _ string) error { return deleteContextTest() }
func deleteContextTest() error {
if err := cmdcfg.Unset(config.ProfileName); err != nil {

View File

@ -270,7 +270,7 @@ For example, you can do all docker operations such as docker build, docker run,
Note: You need the docker-cli to be installed on your machine.
docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/docker_desktop_replacement/#steps`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
var err error
shl := shell.ForceShell

View File

@ -38,7 +38,7 @@ var generateDocs = &cobra.Command{
Long: "Populates the specified folder with documentation in markdown about minikube",
Example: "minikube generate-docs --path <FOLDER_PATH>",
Hidden: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
// if directory does not exist
st, err := os.Stat(docsPath)
if err != nil || !st.IsDir() {

View File

@ -80,7 +80,7 @@ var loadImageCmd = &cobra.Command{
Short: "Load an image into minikube",
Long: "Load an image into minikube",
Example: "minikube image load image\nminikube image load image.tar",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) == 0 {
exit.Message(reason.Usage, "Please provide an image in your local daemon to load into minikube via <minikube image load IMAGE_NAME>")
}
@ -171,7 +171,7 @@ var saveImageCmd = &cobra.Command{
Short: "Save a image from minikube",
Long: "Save a image from minikube",
Example: "minikube image save image\nminikube image save image image.tar",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) == 0 {
exit.Message(reason.Usage, "Please provide an image in the container runtime to save from minikube via <minikube image save IMAGE_NAME>")
}
@ -230,7 +230,7 @@ $ minikube image unload image busybox
`,
Args: cobra.MinimumNArgs(1),
Aliases: []string{"remove", "unload"},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
profile, err := config.LoadProfile(viper.GetString(config.ProfileName))
if err != nil {
exit.Error(reason.Usage, "loading profile", err)
@ -247,7 +247,7 @@ var pullImageCmd = &cobra.Command{
Example: `
$ minikube image pull busybox
`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
profile, err := config.LoadProfile(viper.GetString(config.ProfileName))
if err != nil {
exit.Error(reason.Usage, "loading profile", err)
@ -273,7 +273,7 @@ var buildImageCmd = &cobra.Command{
Short: "Build a container image in minikube",
Long: "Build a container image, using the container runtime.",
Example: `minikube image build .`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) < 1 {
exit.Message(reason.Usage, "Please provide a path or url to build")
}
@ -333,7 +333,7 @@ var listImageCmd = &cobra.Command{
$ minikube image ls
`,
Aliases: []string{"list"},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
profile, err := config.LoadProfile(viper.GetString(config.ProfileName))
if err != nil {
exit.Error(reason.Usage, "loading profile", err)
@ -352,7 +352,7 @@ var tagImageCmd = &cobra.Command{
$ minikube image tag source target
`,
Aliases: []string{"list"},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 2 {
exit.Message(reason.Usage, "Please provide source and target image")
}
@ -373,7 +373,7 @@ var pushImageCmd = &cobra.Command{
Example: `
$ minikube image push busybox
`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
profile, err := config.LoadProfile(viper.GetString(config.ProfileName))
if err != nil {
exit.Error(reason.Usage, "loading profile", err)

View File

@ -30,7 +30,7 @@ var ipCmd = &cobra.Command{
Use: "ip",
Short: "Retrieves the IP address of the specified node",
Long: `Retrieves the IP address of the specified node, and writes it to STDOUT.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
co := mustload.Running(ClusterFlagValue())
n, _, err := node.Retrieve(*co.Config, nodeName)
if err != nil {

View File

@ -53,7 +53,7 @@ but optionally you can also run it directly on the control plane over the ssh co
This can be useful if you cannot run kubectl locally for some reason, like unsupported
host. Please be aware that when using --ssh all paths will apply to the remote machine.`,
Example: "minikube kubectl -- --help\nminikube kubectl -- get pods --namespace kube-system",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
cc, err := config.Load(ClusterFlagValue())
version := constants.DefaultKubernetesVersion

View File

@ -30,7 +30,7 @@ var licenseCmd = &cobra.Command{
Use: "license",
Short: "Outputs the licenses of dependencies to a directory",
Long: "Outputs the licenses of dependencies to a directory",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
if err := download.Licenses(dir); err != nil {
exit.Error(reason.InetLicenses, "Failed to download licenses", err)
}

View File

@ -62,7 +62,7 @@ var logsCmd = &cobra.Command{
Use: "logs",
Short: "Returns logs to debug a local Kubernetes cluster",
Long: `Gets the logs of the running instance, used for debugging minikube, not user code.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
var logOutput *os.File = os.Stdout
var err error

View File

@ -91,7 +91,7 @@ var mountCmd = &cobra.Command{
Use: "mount [flags] <source directory>:<target directory>",
Short: "Mounts the specified directory into minikube",
Long: `Mounts the specified directory into minikube.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if isKill {
if err := killMountProcess(); err != nil {
exit.Error(reason.HostKillMountProc, "Error killing mount process", err)

View File

@ -27,7 +27,7 @@ var nodeCmd = &cobra.Command{
Use: "node",
Short: "Add, remove, or list additional nodes",
Long: "Operations on nodes",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
exit.Message(reason.Usage, "Usage: minikube node [add|start|stop|delete|list]")
},
}

View File

@ -40,7 +40,7 @@ var nodeAddCmd = &cobra.Command{
Use: "add",
Short: "Adds a node to the given cluster.",
Long: "Adds a node to the given cluster config, and starts it.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
co := mustload.Healthy(ClusterFlagValue())
cc := co.Config

View File

@ -36,7 +36,7 @@ var nodeDeleteCmd = &cobra.Command{
Use: "delete",
Short: "Deletes a node from a cluster.",
Long: "Deletes a node from a cluster.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) == 0 {
exit.Message(reason.Usage, "Usage: minikube node delete [name]")
}

View File

@ -32,7 +32,7 @@ var nodeListCmd = &cobra.Command{
Use: "list",
Short: "List nodes.",
Long: "List existing minikube nodes.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) != 0 {
exit.Message(reason.Usage, "Usage: minikube node list")
}

View File

@ -34,7 +34,7 @@ var nodeStopCmd = &cobra.Command{
Use: "stop",
Short: "Stops a node in a cluster.",
Long: "Stops a node in a cluster.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) == 0 {
exit.Message(reason.Usage, "Usage: minikube node stop [name]")
}

View File

@ -138,7 +138,7 @@ var podmanEnvCmd = &cobra.Command{
Use: "podman-env",
Short: "Configure environment to use minikube's Podman service",
Long: `Sets up podman env variables; similar to '$(podman-machine env)'.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
sh := shell.EnvConfig{
Shell: shell.ForceShell,
}

View File

@ -63,7 +63,7 @@ var RootCmd = &cobra.Command{
Use: "minikube",
Short: "minikube quickly sets up a local Kubernetes cluster",
Long: `minikube provisions and manages local Kubernetes clusters optimized for development workflows.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
PersistentPreRun: func(_ *cobra.Command, _ []string) {
for _, path := range dirs {
if err := os.MkdirAll(path, 0777); err != nil {
exit.Error(reason.HostHomeMkdir, "Error creating minikube directory", err)
@ -86,7 +86,7 @@ var RootCmd = &cobra.Command{
os.Setenv(constants.MinikubeRootlessEnv, "true")
}
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
PersistentPostRun: func(_ *cobra.Command, _ []string) {
if err := audit.LogCommandEnd(auditID); err != nil {
klog.Warningf("failed to log command end to audit: %v", err)
}

View File

@ -74,7 +74,7 @@ var serviceCmd = &cobra.Command{
RootCmd.PersistentPreRun(cmd, args)
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
if len(args) == 0 && !all || (len(args) > 0 && all) {
exit.Message(reason.Usage, "You must specify service name(s) or --all")
}

View File

@ -41,7 +41,7 @@ var serviceListCmd = &cobra.Command{
Use: "list [flags]",
Short: "Lists the URLs for the services in your local cluster",
Long: `Lists the URLs for the services in your local cluster`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
co := mustload.Healthy(ClusterFlagValue())
output := strings.ToLower(profileOutput)

View File

@ -44,7 +44,7 @@ var sshHostCmd = &cobra.Command{
Use: "ssh-host",
Short: "Retrieve the ssh host key of the specified node",
Long: "Retrieve the ssh host key of the specified node.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
appendKnownHelper(nodeName, appendKnown)
},
}

View File

@ -34,7 +34,7 @@ var sshKeyCmd = &cobra.Command{
Use: "ssh-key",
Short: "Retrieve the ssh identity key path of the specified node",
Long: "Retrieve the ssh identity key path of the specified node, and writes it to STDOUT.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
_, cc := mustload.Partial(ClusterFlagValue())
n, _, err := node.Retrieve(*cc, nodeName)
if err != nil {

View File

@ -38,7 +38,7 @@ var sshCmd = &cobra.Command{
Use: "ssh",
Short: "Log into the minikube environment (for debugging)",
Long: "Log into or run a command on a machine with SSH; similar to 'docker-machine ssh'.",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
cname := ClusterFlagValue()
co := mustload.Running(cname)
if co.CP.Host.DriverName == driver.None {

View File

@ -116,9 +116,7 @@ func TestGetKubernetesVersion(t *testing.T) {
}
}
var checkRepoMock = func(v semver.Version, repo string) error {
return nil
}
var checkRepoMock = func(_ semver.Version, _ string) error { return nil }
func TestMirrorCountry(t *testing.T) {
// Set default disk size value in lieu of flag init

View File

@ -213,7 +213,7 @@ var statusCmd = &cobra.Command{
Long: `Gets the status of a local Kubernetes cluster.
Exit status contains the status of minikube's VM, cluster and Kubernetes encoded on it's bits in this order from right to left.
Eg: 7 meaning: 1 (for minikube NOK) + 2 (for cluster NOK) + 4 (for Kubernetes NOK)`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
output = strings.ToLower(output)
if output != "text" && statusFormat != defaultStatusFormat {
exit.Message(reason.Usage, "Cannot use both --output and --format options")

View File

@ -56,7 +56,7 @@ var tunnelCmd = &cobra.Command{
PersistentPreRun: func(cmd *cobra.Command, args []string) {
RootCmd.PersistentPreRun(cmd, args)
},
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
manager := tunnel.NewManager()
cname := ClusterFlagValue()
co := mustload.Healthy(cname)

View File

@ -42,7 +42,7 @@ var unpauseCmd = &cobra.Command{
Use: "unpause",
Aliases: []string{"resume"},
Short: "unpause Kubernetes",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
cname := ClusterFlagValue()
register.SetEventLogPath(localpath.EventLog(cname))

View File

@ -29,7 +29,7 @@ var updateCheckCmd = &cobra.Command{
Use: "update-check",
Short: "Print current and latest version number",
Long: `Print current and latest version number`,
Run: func(command *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
url := notify.GithubMinikubeReleasesURL
r, err := notify.AllVersionsFromURL(url)
if err != nil {

View File

@ -32,7 +32,7 @@ var updateContextCmd = &cobra.Command{
Short: "Update kubeconfig in case of an IP or port change",
Long: `Retrieves the IP address of the running cluster, checks it
with IP in kubeconfig, and corrects kubeconfig if incorrect.`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
cname := ClusterFlagValue()
co := mustload.Running(cname)
// cluster extension metada for kubeconfig

View File

@ -42,7 +42,7 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version of minikube",
Long: `Print the version of minikube.`,
Run: func(command *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
minikubeVersion := version.GetVersion()
gitCommitID := version.GetGitCommitID()
data := map[string]interface{}{

View File

@ -32,10 +32,10 @@ var rootCmd = &cobra.Command{
Short: "mkcmp is used to compare performance of two minikube binaries",
SilenceUsage: true,
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
PersistentPreRunE: func(_ *cobra.Command, args []string) error {
return validateArgs(args)
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
binaries, err := retrieveBinaries(args)
if err != nil {
return err

View File

@ -135,7 +135,7 @@ func filePasses(filename string, expectedBoilerplate []byte) (bool, error) {
// filesToCheck returns the list of the filers that will be checked for the boilerplate.
func filesToCheck(rootDir string, extensions map[string][]byte) ([]string, error) {
var outFiles []string
err := filepath.Walk(rootDir, func(path string, info os.FileInfo, err error) error {
err := filepath.Walk(rootDir, func(path string, info os.FileInfo, _ error) error {
// remove current workdir from the beginning of the path in case it matches the skipped path
cwd, _ := os.Getwd()
// replace "\" with "\\" for windows style path

View File

@ -154,7 +154,7 @@ func processCommitFolder(commitSha string, logger *log.Logger, gp string) error
dbPath := fmt.Sprintf(dbPathPattern, os.Getenv("DB_PASS"))
// Iterate over the JSON files in the local directory
err = filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error {
err = filepath.Walk(dirPath, func(path string, info os.FileInfo, _ error) error {
filename := filepath.Base(path[:len(path)-len(".json")])
if !info.IsDir() && strings.HasSuffix(path, ".json") && !strings.HasSuffix(path, "summary.json") && notInDB(commitSha, filename) {
gopoghCmd := fmt.Sprintf(gopoghCommand, gp, filename, mkRepo, path, commitSha, host, dbPath, dbBackend)

View File

@ -23,7 +23,7 @@ import (
)
var dockerResponse string
var dockerInspectGetterMock = func(name string) (*RunResult, error) {
var dockerInspectGetterMock = func(_ string) (*RunResult, error) {
var responseInBytes bytes.Buffer
responseInBytes.WriteString(dockerResponse)
response := &RunResult{Stdout: responseInBytes}
@ -84,7 +84,7 @@ func TestDockerInspect(t *testing.T) {
}
var podmanResponse string
var podmanInspectGetterMock = func(name string) (*RunResult, error) {
var podmanInspectGetterMock = func(_ string) (*RunResult, error) {
var responseInBytes bytes.Buffer
responseInBytes.WriteString(podmanResponse)
response := &RunResult{Stdout: responseInBytes}

View File

@ -43,7 +43,7 @@ func TestDocs(docPath string, pathToCheck string) error {
return err
}
err = filepath.Walk(pathToCheck, func(path string, info os.FileInfo, err error) error {
err = filepath.Walk(pathToCheck, func(path string, info os.FileInfo, _ error) error {
if info.IsDir() || !strings.HasSuffix(path, ".go") {
return nil
}

View File

@ -193,7 +193,7 @@ func (f *FakeCommandRunner) GetFileToContents(filename string) (string, error) {
func (f *FakeCommandRunner) commands() []string {
cmds := []string{}
f.cmdMap.Range(func(k, v interface{}) bool {
f.cmdMap.Range(func(k, _ interface{}) bool {
cmds = append(cmds, fmt.Sprintf("%s", k))
return true
})
@ -208,7 +208,7 @@ func (f *FakeCommandRunner) DumpMaps(w io.Writer) {
return true
})
fmt.Fprintln(w, "Filenames: ")
f.fileMap.Range(func(k, v interface{}) bool {
f.fileMap.Range(func(k, _ interface{}) bool {
fmt.Fprint(w, k)
return true
})

View File

@ -52,7 +52,7 @@ func testBinaryDownloadPreventsMultipleDownload(t *testing.T) {
downloadNum := 0
DownloadMock = mockSleepDownload(&downloadNum)
checkCache = func(file string) (fs.FileInfo, error) {
checkCache = func(_ string) (fs.FileInfo, error) {
if downloadNum == 0 {
return nil, fmt.Errorf("some error")
}
@ -90,15 +90,15 @@ func testPreloadDownloadPreventsMultipleDownload(t *testing.T) {
t.Fatalf("failed to write to temp file: %v", err)
}
checkCache = func(file string) (fs.FileInfo, error) {
checkCache = func(_ string) (fs.FileInfo, error) {
if downloadNum == 0 {
return nil, fmt.Errorf("some error")
}
return os.Stat(f.Name())
}
checkPreloadExists = func(k8sVersion, containerRuntime, driverName string, forcePreload ...bool) bool { return true }
getChecksum = func(k8sVersion, containerRuntime string) ([]byte, error) { return []byte("check"), nil }
ensureChecksumValid = func(k8sVersion, containerRuntime, path string, checksum []byte) error { return nil }
checkPreloadExists = func(_, _, _ string, _ ...bool) bool { return true }
getChecksum = func(_, _ string) ([]byte, error) { return []byte("check"), nil }
ensureChecksumValid = func(_, _, _ string, _ []byte) error { return nil }
var group sync.WaitGroup
group.Add(2)
@ -123,10 +123,10 @@ func testPreloadNotExists(t *testing.T) {
downloadNum := 0
DownloadMock = mockSleepDownload(&downloadNum)
checkCache = func(file string) (fs.FileInfo, error) { return nil, fmt.Errorf("cache not found") }
checkPreloadExists = func(k8sVersion, containerRuntime, driverName string, forcePreload ...bool) bool { return false }
getChecksum = func(k8sVersion, containerRuntime string) ([]byte, error) { return []byte("check"), nil }
ensureChecksumValid = func(k8sVersion, containerRuntime, path string, checksum []byte) error { return nil }
checkCache = func(_ string) (fs.FileInfo, error) { return nil, fmt.Errorf("cache not found") }
checkPreloadExists = func(_, _, _ string, _ ...bool) bool { return false }
getChecksum = func(_, _ string) ([]byte, error) { return []byte("check"), nil }
ensureChecksumValid = func(_, _, _ string, _ []byte) error { return nil }
err := Preload(constants.DefaultKubernetesVersion, constants.Docker, "docker")
if err != nil {
@ -142,10 +142,10 @@ func testPreloadChecksumMismatch(t *testing.T) {
downloadNum := 0
DownloadMock = mockSleepDownload(&downloadNum)
checkCache = func(file string) (fs.FileInfo, error) { return nil, fmt.Errorf("cache not found") }
checkPreloadExists = func(k8sVersion, containerRuntime, driverName string, forcePreload ...bool) bool { return true }
getChecksum = func(k8sVersion, containerRuntime string) ([]byte, error) { return []byte("check"), nil }
ensureChecksumValid = func(k8sVersion, containerRuntime, path string, checksum []byte) error {
checkCache = func(_ string) (fs.FileInfo, error) { return nil, fmt.Errorf("cache not found") }
checkPreloadExists = func(_, _, _ string, _ ...bool) bool { return true }
getChecksum = func(_, _ string) ([]byte, error) { return []byte("check"), nil }
ensureChecksumValid = func(_, _, _ string, _ []byte) error {
return fmt.Errorf("checksum mismatch")
}
@ -162,7 +162,7 @@ func testImageToCache(t *testing.T) {
downloadNum := 0
DownloadMock = mockSleepDownload(&downloadNum)
checkImageExistsInCache = func(img string) bool { return downloadNum > 0 }
checkImageExistsInCache = func(_ string) bool { return downloadNum > 0 }
var group sync.WaitGroup
group.Add(2)
@ -185,12 +185,12 @@ func testImageToCache(t *testing.T) {
// Validates that preload existence checks correctly caches values retrieved by remote checks.
func testPreloadExistsCaching(t *testing.T) {
checkCache = func(file string) (fs.FileInfo, error) {
checkCache = func(_ string) (fs.FileInfo, error) {
return nil, fmt.Errorf("cache not found")
}
doesPreloadExist := false
checkCalled := false
checkRemotePreloadExists = func(k8sVersion, containerRuntime string) bool {
checkRemotePreloadExists = func(_, _ string) bool {
checkCalled = true
return doesPreloadExist
}
@ -229,10 +229,10 @@ func testPreloadWithCachedSizeZero(t *testing.T) {
t.Fatalf("failed to create temp file: %v", err)
}
checkCache = func(file string) (fs.FileInfo, error) { return os.Stat(f.Name()) }
checkPreloadExists = func(k8sVersion, containerRuntime, driverName string, forcePreload ...bool) bool { return true }
getChecksum = func(k8sVersion, containerRuntime string) ([]byte, error) { return []byte("check"), nil }
ensureChecksumValid = func(k8sVersion, containerRuntime, path string, checksum []byte) error { return nil }
checkCache = func(_ string) (fs.FileInfo, error) { return os.Stat(f.Name()) }
checkPreloadExists = func(_, _, _ string, _ ...bool) bool { return true }
getChecksum = func(_, _ string) ([]byte, error) { return []byte("check"), nil }
ensureChecksumValid = func(_, _, _ string, _ []byte) error { return nil }
if err := Preload(constants.DefaultKubernetesVersion, constants.Docker, "docker"); err != nil {
t.Errorf("Expected no error with cached preload of size zero")

View File

@ -134,7 +134,7 @@ func TranslatableStrings(paths []string, functions []string, output string) erro
f := e.fs.Pop().(funcType)
e.currentFunc = f
for _, root := range paths {
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
err := filepath.Walk(root, func(path string, _ os.FileInfo, _ error) error {
if shouldCheckFile(path) {
e.filename = path
return inspectFile(e)

View File

@ -31,7 +31,7 @@ func TestReplaceWinDriveLetterToVolumeName(t *testing.T) {
if runtime.GOOS != "windows" {
// Replace to fake func.
getWindowsVolumeName = func(d string) (string, error) {
getWindowsVolumeName = func(_ string) (string, error) {
return `/`, nil
}
// Add dummy Windows drive letter.

View File

@ -193,10 +193,11 @@ func TestExcludeIP(t *testing.T) {
func TestUpdateTransport(t *testing.T) {
t.Run("new", func(t *testing.T) {
rc := rest.Config{}
UpdateTransport(&rc)
tr := &http.Transport{}
tr.RegisterProtocol("file", http.NewFileTransport(http.Dir("/tmp")))
rcBefore := rest.Config{}
rcAfter := UpdateTransport(&rcBefore)
if rcAfter.WrapTransport == nil {
t.Errorf("UpdateTransport(%v) = %v, WrapTransport was unexpectedly nil", rcBefore, rcAfter)
}
})
t.Run("existing", func(t *testing.T) {
// rest config initialized with WrapTransport function

View File

@ -140,7 +140,7 @@ REM @FOR /f "tokens=*" %%i IN ('%s --shell cmd') DO @%%i
unsetPrefix: "",
unsetSuffix: "\n",
unsetDelimiter: "",
usageHint: func(s ...interface{}) string {
usageHint: func(_ ...interface{}) string {
return ""
},
},

View File

@ -38,7 +38,7 @@ func TestTunnelManagerEventHandling(t *testing.T) {
{
name: "tunnel quits on stopped minikube",
repeat: 1,
test: func(tunnel *tunnelStub, cancel context.CancelFunc, ready, check, done chan bool) error {
test: func(tunnel *tunnelStub, _ context.CancelFunc, ready, check, done chan bool) error {
tunnel.mockClusterInfo = &Status{
MinikubeState: Stopped,
}
@ -63,7 +63,7 @@ func TestTunnelManagerEventHandling(t *testing.T) {
{
name: "tunnel quits on ctrlc before doing a check",
repeat: 1,
test: func(tunnel *tunnelStub, cancel context.CancelFunc, ready, check, done chan bool) error {
test: func(tunnel *tunnelStub, cancel context.CancelFunc, ready, _, done chan bool) error {
tunnel.mockClusterInfo = &Status{
MinikubeState: Stopped,
}
@ -137,7 +137,7 @@ func TestTunnelManagerEventHandling(t *testing.T) {
go tunnelManager.run(ctx, tunnel, ready, check, done)
err = tc.test(tunnel, cancel, ready, check, done)
if err != nil {
klog.Errorf("error at %d", i)
t.Errorf("error at %d", i)
}
}
})

View File

@ -27,8 +27,6 @@ import (
"k8s.io/minikube/pkg/util/lock"
)
const defaultReservationPeriod = 1 * time.Minute
// Parameters contains main network parameters.
type Parameters struct {
IP string // IP address of network
@ -204,7 +202,7 @@ func FreeSubnet(startSubnet string, step, tries int) (*Parameters, error) {
return nil, err
}
if !taken {
if reservation, err := reserveSubnet(subnet, defaultReservationPeriod); err == nil {
if reservation, err := reserveSubnet(subnet); err == nil {
n.reservation = reservation
klog.Infof("using free private subnet %s: %+v", n.CIDR, n)
return n, nil
@ -241,8 +239,8 @@ func ParseAddr(addr string) (net.IP, *net.IPNet, error) {
return ip, network, err
}
// reserveSubnet returns releaser if subnet was successfully reserved for given period, creating lock for subnet to avoid race condition between multiple minikube instances (especially while testing in parallel).
var reserveSubnet = func(subnet string, period time.Duration) (mutex.Releaser, error) {
// reserveSubnet returns releaser if subnet was successfully reserved, creating lock for subnet to avoid race condition between multiple minikube instances (especially while testing in parallel).
var reserveSubnet = func(subnet string) (mutex.Releaser, error) {
spec := lock.PathMutexSpec(subnet)
spec.Timeout = 1 * time.Millisecond // practically: just check, don't wait
reservation, err := mutex.Acquire(spec)

View File

@ -19,13 +19,12 @@ package network
import (
"strings"
"testing"
"time"
"github.com/juju/mutex/v2"
)
func TestFreeSubnet(t *testing.T) {
reserveSubnet = func(subnet string, period time.Duration) (mutex.Releaser, error) { return nil, nil }
reserveSubnet = func(_ string) (mutex.Releaser, error) { return nil, nil }
t.Run("NoRetriesSuccess", func(t *testing.T) {
startingSubnet := "192.168.0.0"
@ -46,7 +45,7 @@ func TestFreeSubnet(t *testing.T) {
isSubnetTaken = originalIsSubnetTaken
}()
isSubnetTaken = func(subnet string) (bool, error) {
isSubnetTaken = func(_ string) (bool, error) {
count++
return count == 1, nil
}

View File

@ -74,7 +74,7 @@ func GetBinaryDownloadURL(version, platform, arch string) string {
// ChownR does a recursive os.Chown
func ChownR(path string, uid, gid int) error {
return filepath.Walk(path, func(name string, info os.FileInfo, err error) error {
return filepath.Walk(path, func(name string, _ os.FileInfo, err error) error {
if err == nil {
err = os.Chown(name, uid, gid)
}

View File

@ -780,8 +780,8 @@ func imageID(image string) string {
},
}
if imgIds, ok := ids[image]; ok {
if id, ok := imgIds[runtime.GOARCH]; ok {
if imgIDs, ok := ids[image]; ok {
if id, ok := imgIDs[runtime.GOARCH]; ok {
return id
}
panic(fmt.Sprintf("unexpected architecture for image %q: %v", image, runtime.GOARCH))

View File

@ -379,7 +379,7 @@ func validateAccessDNS(_ context.Context, t *testing.T, profile string) {
dnsIP := fmt.Sprintf("%s:53", ip)
// Set kube-dns dial
kubeDNSDial := func(ctx context.Context, network, address string) (net.Conn, error) {
kubeDNSDial := func(ctx context.Context, _, _ string) (net.Conn, error) {
d := net.Dialer{}
return d.DialContext(ctx, "udp", dnsIP)
}