Skip to content

Commit

Permalink
Merge pull request #3839 from afbjorklund/lint
Browse files Browse the repository at this point in the history
Lint
  • Loading branch information
tstromberg authored Mar 21, 2019
2 parents 20b9cfd + 88c45bf commit 8ba53c6
Show file tree
Hide file tree
Showing 69 changed files with 481 additions and 152 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ gendocs: out/docs/minikube.md
fmt:
@gofmt -l -s -w $(SOURCE_DIRS)

.PHONY: lint
lint:
@golint $(MINIKUBE_TEST_FILES)

.PHONY: reportcard
reportcard:
goreportcard-cli -v
Expand Down
1 change: 1 addition & 0 deletions cmd/minikube/cmd/cache_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (

var cacheListFormat string

// CacheListTemplate represents the cache list template
type CacheListTemplate struct {
CacheImage string
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/minikube/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var completionCmd = &cobra.Command{
},
}

// GenerateBashCompletion generates the completion for the bash shell
func GenerateBashCompletion(w io.Writer, cmd *cobra.Command) error {
_, err := w.Write([]byte(boilerPlate))
if err != nil {
Expand All @@ -102,8 +103,9 @@ func GenerateBashCompletion(w io.Writer, cmd *cobra.Command) error {
return nil
}

// GenerateZshCompletion generates the completion for the zsh shell
func GenerateZshCompletion(out io.Writer, cmd *cobra.Command) error {
zsh_initialization := `#compdef minikube
zshInitialization := `#compdef minikube
__minikube_bash_source() {
alias shopt=':'
Expand Down Expand Up @@ -242,7 +244,7 @@ __minikube_convert_bash_to_zsh() {
return err
}

_, err = out.Write([]byte(zsh_initialization))
_, err = out.Write([]byte(zshInitialization))
if err != nil {
return err
}
Expand All @@ -257,12 +259,12 @@ __minikube_convert_bash_to_zsh() {
return err
}

zsh_tail := `
zshTail := `
BASH_COMPLETION_EOF
}
__minikube_bash_source <(__minikube_convert_bash_to_zsh)
`
_, err = out.Write([]byte(zsh_tail))
_, err = out.Write([]byte(zshTail))
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions cmd/minikube/cmd/config/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/spf13/cobra"
)

// AddonsCmd represents the addons command
var AddonsCmd = &cobra.Command{
Use: "addons SUBCOMMAND [flags]",
Short: "Modify minikube's kubernetes addons",
Expand Down
1 change: 1 addition & 0 deletions cmd/minikube/cmd/config/addons_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

var addonListFormat string

// AddonListTemplate represents the addon list template
type AddonListTemplate struct {
AddonName string
AddonStatus string
Expand Down
3 changes: 3 additions & 0 deletions cmd/minikube/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ import (
"k8s.io/minikube/pkg/minikube/constants"
)

// Bootstrapper is the name for bootstrapper
const Bootstrapper = "bootstrapper"

type setFn func(string, string) error

// Setting represents a setting
type Setting struct {
name string
set func(config.MinikubeConfig, string, string) error
Expand Down Expand Up @@ -252,6 +254,7 @@ var settings = []Setting{
},
}

// ConfigCmd represents the config command
var ConfigCmd = &cobra.Command{
Use: "config SUBCOMMAND [flags]",
Short: "Modify minikube config",
Expand Down
9 changes: 7 additions & 2 deletions cmd/minikube/cmd/config/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"fmt"

"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/config"
pkgConfig "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/console"
)

Expand All @@ -36,7 +36,7 @@ var configGetCmd = &cobra.Command{
}

cmd.SilenceUsage = true
val, err := config.Get(args[0])
val, err := Get(args[0])
if err != nil {
return err
}
Expand All @@ -52,3 +52,8 @@ var configGetCmd = &cobra.Command{
func init() {
ConfigCmd.AddCommand(configGetCmd)
}

// Get gets a property
func Get(name string) (string, error) {
return pkgConfig.Get(name)
}
1 change: 1 addition & 0 deletions cmd/minikube/cmd/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/minikube/pkg/minikube/exit"
)

// ProfileCmd represents the profile command
var ProfileCmd = &cobra.Command{
Use: "profile MINIKUBE_PROFILE_NAME. You can return to the default minikube profile by running `minikube profile default`",
Short: "Profile sets the current minikube profile",
Expand Down
1 change: 1 addition & 0 deletions cmd/minikube/cmd/config/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func concealableAskForStaticValue(readWriter io.ReadWriter, promptString string,
}
}

// AskForPasswordValue asks for a password value, while hiding the input
func AskForPasswordValue(s string) string {

stdInFd := int(os.Stdin.Fd())
Expand Down
1 change: 1 addition & 0 deletions cmd/minikube/cmd/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func init() {
ConfigCmd.AddCommand(configSetCmd)
}

// Set sets a property to a value
func Set(name string, value string) error {
s, err := findSetting(name)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions cmd/minikube/cmd/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ func findSetting(name string) (Setting, error) {

// Set Functions

// SetString sets a string value
func SetString(m config.MinikubeConfig, name string, val string) error {
m[name] = val
return nil
}

// SetMap sets a map value
func SetMap(m config.MinikubeConfig, name string, val map[string]interface{}) error {
m[name] = val
return nil
}

// SetConfigMap sets a config map value
func SetConfigMap(m config.MinikubeConfig, name string, val string) error {
list := strings.Split(val, ",")
v := make(map[string]interface{})
Expand All @@ -76,6 +79,7 @@ func SetConfigMap(m config.MinikubeConfig, name string, val string) error {
return nil
}

// SetInt sets an int value
func SetInt(m config.MinikubeConfig, name string, val string) error {
i, err := strconv.Atoi(val)
if err != nil {
Expand All @@ -85,6 +89,7 @@ func SetInt(m config.MinikubeConfig, name string, val string) error {
return nil
}

// SetBool sets a bool value
func SetBool(m config.MinikubeConfig, name string, val string) error {
b, err := strconv.ParseBool(val)
if err != nil {
Expand Down Expand Up @@ -134,6 +139,7 @@ func EnableOrDisableAddon(name string, val string) error {
return nil
}

// EnableOrDisableStorageClasses enables or disables storage classes
func EnableOrDisableStorageClasses(name, val string) error {
enable, err := strconv.ParseBool(val)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions cmd/minikube/cmd/config/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"k8s.io/minikube/pkg/minikube/cruntime"
)

// IsValidDriver checks if a driver is supported
func IsValidDriver(string, driver string) error {
for _, d := range constants.SupportedVMDrivers {
if driver == d {
Expand All @@ -42,11 +43,13 @@ func IsValidDriver(string, driver string) error {
return fmt.Errorf("Driver %s is not supported", driver)
}

// RequiresRestartMsg returns the "requires restart" message
func RequiresRestartMsg(string, string) error {
console.OutStyle("warning", "These changes will take effect upon a minikube delete and then a minikube start")
return nil
}

// IsValidDiskSize checks if a string is a valid disk size
func IsValidDiskSize(name string, disksize string) error {
_, err := units.FromHumanSize(disksize)
if err != nil {
Expand All @@ -55,6 +58,7 @@ func IsValidDiskSize(name string, disksize string) error {
return nil
}

// IsValidURL checks if a location is a valid URL
func IsValidURL(name string, location string) error {
_, err := url.Parse(location)
if err != nil {
Expand All @@ -63,6 +67,7 @@ func IsValidURL(name string, location string) error {
return nil
}

// IsURLExists checks if a location actually exists
func IsURLExists(name string, location string) error {
parsed, err := url.Parse(location)
if err != nil {
Expand Down Expand Up @@ -96,6 +101,7 @@ func IsURLExists(name string, location string) error {
return nil
}

// IsPositive checks if an integer is positive
func IsPositive(name string, val string) error {
i, err := strconv.Atoi(val)
if err != nil {
Expand All @@ -107,6 +113,7 @@ func IsPositive(name string, val string) error {
return nil
}

// IsValidCIDR checks if a string parses as a CIDR
func IsValidCIDR(name string, cidr string) error {
_, _, err := net.ParseCIDR(cidr)
if err != nil {
Expand All @@ -115,6 +122,7 @@ func IsValidCIDR(name string, cidr string) error {
return nil
}

// IsValidPath checks if a string is a valid path
func IsValidPath(name string, path string) error {
_, err := os.Stat(path)
if err != nil {
Expand All @@ -123,6 +131,7 @@ func IsValidPath(name string, path string) error {
return nil
}

// IsValidAddon checks if a string is a valid addon
func IsValidAddon(name string, val string) error {
if _, ok := assets.Addons[name]; ok {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ import (
"k8s.io/minikube/pkg/minikube/exit"
)

var configViewFormat string
var viewFormat string

type ConfigViewTemplate struct {
// ViewTemplate represents the view template
type ViewTemplate struct {
ConfigKey string
ConfigValue interface{}
}
Expand All @@ -38,31 +39,32 @@ var configViewCmd = &cobra.Command{
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) {
err := configView()
err := View()
if err != nil {
exit.WithError("config view failed", err)
}
},
}

func init() {
configViewCmd.Flags().StringVar(&configViewFormat, "format", constants.DefaultConfigViewFormat,
configViewCmd.Flags().StringVar(&viewFormat, "format", constants.DefaultConfigViewFormat,
`Go template format string for the config view output. The format for Go templates can be found here: https://golang.org/pkg/text/template/
For the list of accessible variables for the template, see the struct values here: https://godoc.org/k8s.io/minikube/cmd/minikube/cmd/config#ConfigViewTemplate`)
ConfigCmd.AddCommand(configViewCmd)
}

func configView() error {
// View displays the current config
func View() error {
cfg, err := config.ReadConfig()
if err != nil {
return err
}
for k, v := range cfg {
tmpl, err := template.New("view").Parse(configViewFormat)
tmpl, err := template.New("view").Parse(viewFormat)
if err != nil {
exit.WithError("Error creating view template", err)
}
viewTmplt := ConfigViewTemplate{k, v}
viewTmplt := ViewTemplate{k, v}
err = tmpl.Execute(os.Stdout, viewTmplt)
if err != nil {
exit.WithError("Error executing view template", err)
Expand Down
8 changes: 8 additions & 0 deletions cmd/minikube/cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ REM @FOR /f "tokens=*" %i IN ('minikube docker-env') DO @%i
`,
}

// ShellConfig represents the shell config
type ShellConfig struct {
Prefix string
Delimiter string
Expand All @@ -125,16 +126,20 @@ var (
defaultNoProxyGetter NoProxyGetter
)

// ShellDetector detects shell
type ShellDetector interface {
GetShell(string) (string, error)
}

// LibmachineShellDetector detects shell, using libmachine
type LibmachineShellDetector struct{}

// NoProxyGetter gets the no_proxy variable
type NoProxyGetter interface {
GetNoProxyVar() (string, string)
}

// EnvNoProxyGetter gets the no_proxy variable, using environment
type EnvNoProxyGetter struct{}

func generateUsageHint(userShell string) string {
Expand Down Expand Up @@ -274,13 +279,15 @@ func executeTemplateStdout(shellCfg *ShellConfig) error {
return tmpl.Execute(os.Stdout, shellCfg)
}

// GetShell detects the shell
func (LibmachineShellDetector) GetShell(userShell string) (string, error) {
if userShell != "" {
return userShell, nil
}
return shell.Detect()
}

// GetNoProxyVar gets the no_proxy var
func (EnvNoProxyGetter) GetNoProxyVar() (string, string) {
// first check for an existing lower case no_proxy var
noProxyVar := "no_proxy"
Expand All @@ -294,6 +301,7 @@ func (EnvNoProxyGetter) GetNoProxyVar() (string, string) {
return noProxyVar, noProxyValue
}

// GetDockerActive checks if Docker is active
func GetDockerActive(host *host.Host) (bool, error) {
statusCmd := `sudo systemctl is-active docker`
status, err := host.RunSSHCommand(statusCmd)
Expand Down
Loading

0 comments on commit 8ba53c6

Please sign in to comment.