Skip to content

Commit

Permalink
Merge pull request #5430 from u5surf/issue-5357
Browse files Browse the repository at this point in the history
Remove single-package constants from constants package
  • Loading branch information
tstromberg authored Sep 27, 2019
2 parents 218336c + 291b60b commit cc82b4a
Show file tree
Hide file tree
Showing 36 changed files with 257 additions and 258 deletions.
12 changes: 8 additions & 4 deletions cmd/minikube/cmd/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ import (
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/machine"
)

// cacheImageConfigKey is the config field name used to store which images we have previously cached
const cacheImageConfigKey = "cache"

// cacheCmd represents the cache command
var cacheCmd = &cobra.Command{
Use: "cache",
Expand All @@ -43,7 +47,7 @@ var addCacheCmd = &cobra.Command{
exit.WithError("Failed to cache and load images", err)
}
// Add images to config file
if err := cmdConfig.AddToConfigMap(constants.Cache, args); err != nil {
if err := cmdConfig.AddToConfigMap(cacheImageConfigKey, args); err != nil {
exit.WithError("Failed to update config", err)
}
},
Expand All @@ -56,7 +60,7 @@ var deleteCacheCmd = &cobra.Command{
Long: "Delete an image from the local cache.",
Run: func(cmd *cobra.Command, args []string) {
// Delete images from config file
if err := cmdConfig.DeleteFromConfigMap(constants.Cache, args); err != nil {
if err := cmdConfig.DeleteFromConfigMap(cacheImageConfigKey, args); err != nil {
exit.WithError("Failed to delete images from config", err)
}
// Delete images from cache/images directory
Expand All @@ -67,11 +71,11 @@ var deleteCacheCmd = &cobra.Command{
}

func imagesInConfigFile() ([]string, error) {
configFile, err := config.ReadConfig(constants.ConfigFile)
configFile, err := config.ReadConfig(localpath.ConfigFile)
if err != nil {
return nil, err
}
if values, ok := configFile[constants.Cache]; ok {
if values, ok := configFile[cacheImageConfigKey]; ok {
var images []string
for key := range values.(map[string]interface{}) {
images = append(images, key)
Expand Down
7 changes: 4 additions & 3 deletions cmd/minikube/cmd/cache_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ import (

"github.com/spf13/cobra"
cmdConfig "k8s.io/minikube/cmd/minikube/cmd/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
)

const defaultCacheListFormat = "{{.CacheImage}}\n"

var cacheListFormat string

// CacheListTemplate represents the cache list template
Expand All @@ -39,7 +40,7 @@ var listCacheCmd = &cobra.Command{
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) {
images, err := cmdConfig.ListConfigMap(constants.Cache)
images, err := cmdConfig.ListConfigMap(cacheImageConfigKey)
if err != nil {
exit.WithError("Failed to get image map", err)
}
Expand All @@ -50,7 +51,7 @@ var listCacheCmd = &cobra.Command{
}

func init() {
listCacheCmd.Flags().StringVar(&cacheListFormat, "format", constants.DefaultCacheListFormat,
listCacheCmd.Flags().StringVar(&cacheListFormat, "format", defaultCacheListFormat,
`Go template format string for the cache list 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#CacheListTemplate`)
cacheCmd.AddCommand(listCacheCmd)
Expand Down
5 changes: 3 additions & 2 deletions cmd/minikube/cmd/config/addons_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import (

"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
)

const defaultAddonListFormat = "- {{.AddonName}}: {{.AddonStatus}}\n"

var addonListFormat string

// AddonListTemplate represents the addon list template
Expand All @@ -51,7 +52,7 @@ var addonsListCmd = &cobra.Command{
}

func init() {
AddonsCmd.Flags().StringVar(&addonListFormat, "format", constants.DefaultAddonListFormat,
AddonsCmd.Flags().StringVar(&addonListFormat, "format", defaultAddonListFormat,
`Go template format string for the addon list 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#AddonListTemplate`)
AddonsCmd.AddCommand(addonsListCmd)
Expand Down
12 changes: 6 additions & 6 deletions cmd/minikube/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/golang/glog"
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/localpath"
)

// Bootstrapper is the name for bootstrapper
Expand Down Expand Up @@ -300,7 +300,7 @@ func configurableFields() string {

// ListConfigMap list entries from config file
func ListConfigMap(name string) ([]string, error) {
configFile, err := config.ReadConfig(constants.ConfigFile)
configFile, err := config.ReadConfig(localpath.ConfigFile)
if err != nil {
return nil, err
}
Expand All @@ -320,7 +320,7 @@ func AddToConfigMap(name string, images []string) error {
return err
}
// Set the values
cfg, err := config.ReadConfig(constants.ConfigFile)
cfg, err := config.ReadConfig(localpath.ConfigFile)
if err != nil {
return err
}
Expand All @@ -337,7 +337,7 @@ func AddToConfigMap(name string, images []string) error {
return err
}
// Write the values
return config.WriteConfig(constants.ConfigFile, cfg)
return config.WriteConfig(localpath.ConfigFile, cfg)
}

// DeleteFromConfigMap deletes entries from a map in the config file
Expand All @@ -347,7 +347,7 @@ func DeleteFromConfigMap(name string, images []string) error {
return err
}
// Set the values
cfg, err := config.ReadConfig(constants.ConfigFile)
cfg, err := config.ReadConfig(localpath.ConfigFile)
if err != nil {
return err
}
Expand All @@ -362,5 +362,5 @@ func DeleteFromConfigMap(name string, images []string) error {
return err
}
// Write the values
return config.WriteConfig(constants.ConfigFile, cfg)
return config.WriteConfig(localpath.ConfigFile, cfg)
}
5 changes: 2 additions & 3 deletions cmd/minikube/cmd/config/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
Expand Down Expand Up @@ -103,8 +102,8 @@ You can add one by annotating a service with the label {{.labelName}}:{{.addonNa
func init() {
addonsOpenCmd.Flags().BoolVar(&addonsURLMode, "url", false, "Display the kubernetes addons URL in the CLI instead of opening it in the default browser")
addonsOpenCmd.Flags().BoolVar(&https, "https", false, "Open the addons URL with https instead of http")
addonsOpenCmd.Flags().IntVar(&wait, "wait", constants.DefaultWait, "Amount of time to wait for service in seconds")
addonsOpenCmd.Flags().IntVar(&interval, "interval", constants.DefaultInterval, "The time interval for each check that wait performs in seconds")
addonsOpenCmd.Flags().IntVar(&wait, "wait", service.DefaultWait, "Amount of time to wait for service in seconds")
addonsOpenCmd.Flags().IntVar(&interval, "interval", service.DefaultInterval, "The time interval for each check that wait performs in seconds")
addonsOpenCmd.PersistentFlags().StringVar(&addonsURLFormat, "format", defaultAddonsFormatTemplate, "Format to output addons URL in. This format will be applied to each url individually and they will be printed one at a time.")
AddonsCmd.AddCommand(addonsOpenCmd)
}
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/config/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package config
import (
"github.com/spf13/cobra"
pkgConfig "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/out"
)

Expand Down Expand Up @@ -60,7 +60,7 @@ func Set(name string, value string) error {
}

// Set the value
config, err := pkgConfig.ReadConfig(constants.ConfigFile)
config, err := pkgConfig.ReadConfig(localpath.ConfigFile)
if err != nil {
return err
}
Expand All @@ -76,5 +76,5 @@ func Set(name string, value string) error {
}

// Write the value
return pkgConfig.WriteConfig(constants.ConfigFile, config)
return pkgConfig.WriteConfig(localpath.ConfigFile, config)
}
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/config/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package config
import (
"github.com/spf13/cobra"
pkgConfig "k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
)

var configUnsetCmd = &cobra.Command{
Expand All @@ -44,10 +44,10 @@ func init() {

// Unset unsets a property
func Unset(name string) error {
m, err := pkgConfig.ReadConfig(constants.ConfigFile)
m, err := pkgConfig.ReadConfig(localpath.ConfigFile)
if err != nil {
return err
}
delete(m, name)
return pkgConfig.WriteConfig(constants.ConfigFile, m)
return pkgConfig.WriteConfig(localpath.ConfigFile, m)
}
6 changes: 4 additions & 2 deletions cmd/minikube/cmd/config/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import (
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/storageclass"
)

// defaultStorageClassProvisioner is the name of the default storage class provisioner
const defaultStorageClassProvisioner = "standard"

// Runs all the validation or callback functions and collects errors
func run(name string, value string, fns []setFn) error {
var errors []error
Expand Down Expand Up @@ -205,7 +207,7 @@ func EnableOrDisableStorageClasses(name, val string) error {
return errors.Wrap(err, "Error parsing boolean")
}

class := constants.DefaultStorageClassProvisioner
class := defaultStorageClassProvisioner
if name == "storage-provisioner-gluster" {
class = "glusterfile"
}
Expand Down
8 changes: 5 additions & 3 deletions cmd/minikube/cmd/config/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import (

"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/localpath"
)

const defaultConfigViewFormat = "- {{.ConfigKey}}: {{.ConfigValue}}\n"

var viewFormat string

// ViewTemplate represents the view template
Expand All @@ -47,15 +49,15 @@ var configViewCmd = &cobra.Command{
}

func init() {
configViewCmd.Flags().StringVar(&viewFormat, "format", constants.DefaultConfigViewFormat,
configViewCmd.Flags().StringVar(&viewFormat, "format", 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)
}

// View displays the current config
func View() error {
cfg, err := config.ReadConfig(constants.ConfigFile)
cfg, err := config.ReadConfig(localpath.ConfigFile)
if err != nil {
return err
}
Expand Down
12 changes: 8 additions & 4 deletions cmd/minikube/cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ import (
"k8s.io/minikube/third_party/go9p/ufs"
)

// nineP is the value of --type used for the 9p filesystem.
const nineP = "9p"
const (
// nineP is the value of --type used for the 9p filesystem.
nineP = "9p"
defaultMountVersion = "9p2000.L"
defaultMsize = 262144
)

// placeholders for flag values
var mountIP string
Expand Down Expand Up @@ -202,13 +206,13 @@ var mountCmd = &cobra.Command{
func init() {
mountCmd.Flags().StringVar(&mountIP, "ip", "", "Specify the ip that the mount should be setup on")
mountCmd.Flags().StringVar(&mountType, "type", nineP, "Specify the mount filesystem type (supported types: 9p)")
mountCmd.Flags().StringVar(&mountVersion, "9p-version", constants.DefaultMountVersion, "Specify the 9p version that the mount should use")
mountCmd.Flags().StringVar(&mountVersion, "9p-version", defaultMountVersion, "Specify the 9p version that the mount should use")
mountCmd.Flags().BoolVar(&isKill, "kill", false, "Kill the mount process spawned by minikube start")
mountCmd.Flags().StringVar(&uid, "uid", "docker", "Default user id used for the mount")
mountCmd.Flags().StringVar(&gid, "gid", "docker", "Default group id used for the mount")
mountCmd.Flags().UintVar(&mode, "mode", 0755, "File permissions used for the mount")
mountCmd.Flags().StringSliceVar(&options, "options", []string{}, "Additional mount options, such as cache=fscache")
mountCmd.Flags().IntVar(&mSize, "msize", constants.DefaultMsize, "The number of bytes to use for 9p packet payload")
mountCmd.Flags().IntVar(&mSize, "msize", defaultMsize, "The number of bytes to use for 9p packet payload")
}

// getPort asks the kernel for a free open port that is ready to use
Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func setFlagsUsingViper() {
func init() {
translate.DetermineLocale()
RootCmd.PersistentFlags().StringP(config.MachineProfile, "p", constants.DefaultMachineName, `The name of the minikube VM being used. This can be set to allow having multiple instances of minikube independently.`)
RootCmd.PersistentFlags().StringP(configCmd.Bootstrapper, "b", constants.DefaultClusterBootstrapper, "The name of the cluster bootstrapper that will set up the kubernetes cluster.")
RootCmd.PersistentFlags().StringP(configCmd.Bootstrapper, "b", "kubeadm", "The name of the cluster bootstrapper that will set up the kubernetes cluster.")

groups := templates.CommandGroups{
{
Expand Down Expand Up @@ -232,7 +232,7 @@ func init() {

// initConfig reads in config file and ENV variables if set.
func initConfig() {
configPath := constants.ConfigFile
configPath := localpath.ConfigFile
viper.SetConfigFile(configPath)
viper.SetConfigType("json")
err := viper.ReadInConfig()
Expand All @@ -243,7 +243,7 @@ func initConfig() {
}

func setupViper() {
viper.SetEnvPrefix(constants.MinikubeEnvPrefix)
viper.SetEnvPrefix(minikubeEnvPrefix)
// Replaces '-' in flags with '_' in env variables
// e.g. iso-url => $ENVPREFIX_ISO_URL
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
Expand Down
5 changes: 2 additions & 3 deletions cmd/minikube/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/tests"
)

Expand Down Expand Up @@ -97,7 +96,7 @@ func runCommand(f func(*cobra.Command, []string)) {
func hideEnv(t *testing.T) func(t *testing.T) {
envs := make(map[string]string)
for _, env := range os.Environ() {
if strings.HasPrefix(env, constants.MinikubeEnvPrefix) {
if strings.HasPrefix(env, minikubeEnvPrefix) {
line := strings.Split(env, "=")
key, val := line[0], line[1]
envs[key] = val
Expand Down Expand Up @@ -143,7 +142,7 @@ func TestViperConfig(t *testing.T) {
}

func getEnvVarName(name string) string {
return constants.MinikubeEnvPrefix + "_" + strings.ToUpper(name)
return minikubeEnvPrefix + "_" + strings.ToUpper(name)
}

func setValues(tt configTest) error {
Expand Down
5 changes: 2 additions & 3 deletions cmd/minikube/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/spf13/cobra"
"k8s.io/minikube/pkg/minikube/cluster"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/service"
Expand Down Expand Up @@ -78,8 +77,8 @@ func init() {
serviceCmd.Flags().StringVarP(&namespace, "namespace", "n", "default", "The service namespace")
serviceCmd.Flags().BoolVar(&serviceURLMode, "url", false, "Display the kubernetes service URL in the CLI instead of opening it in the default browser")
serviceCmd.Flags().BoolVar(&https, "https", false, "Open the service URL with https instead of http")
serviceCmd.Flags().IntVar(&wait, "wait", constants.DefaultWait, "Amount of time to wait for a service in seconds")
serviceCmd.Flags().IntVar(&interval, "interval", constants.DefaultInterval, "The initial time interval for each check that wait performs in seconds")
serviceCmd.Flags().IntVar(&wait, "wait", service.DefaultWait, "Amount of time to wait for a service in seconds")
serviceCmd.Flags().IntVar(&interval, "interval", service.DefaultInterval, "The initial time interval for each check that wait performs in seconds")

serviceCmd.PersistentFlags().StringVar(&serviceURLFormat, "format", defaultServiceFormatTemplate, "Format to output service URL in. This format will be applied to each url individually and they will be printed one at a time.")

Expand Down
Loading

0 comments on commit cc82b4a

Please sign in to comment.