diff --git a/cmd/minikube/cmd/completion.go b/cmd/minikube/cmd/completion.go index 5d05d3faad91..edb9144d4780 100644 --- a/cmd/minikube/cmd/completion.go +++ b/cmd/minikube/cmd/completion.go @@ -23,8 +23,8 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/exit" + "k8s.io/minikube/pkg/minikube/out" ) const longDescription = ` @@ -73,7 +73,7 @@ var completionCmd = &cobra.Command{ exit.UsageT("Usage: minikube completion SHELL") } if args[0] != "bash" && args[0] != "zsh" { - exit.UsageT("Sorry, completion support is not yet implemented for {{.name}}", console.Arg{"name": args[0]}) + exit.UsageT("Sorry, completion support is not yet implemented for {{.name}}", out.V{"name": args[0]}) } else if args[0] == "bash" { err := GenerateBashCompletion(os.Stdout, cmd.Parent()) if err != nil { diff --git a/cmd/minikube/cmd/config/addons_list.go b/cmd/minikube/cmd/config/addons_list.go index 483a543c948d..bf05d976a7a7 100644 --- a/cmd/minikube/cmd/config/addons_list.go +++ b/cmd/minikube/cmd/config/addons_list.go @@ -41,7 +41,7 @@ var addonsListCmd = &cobra.Command{ Long: "Lists all available minikube addons as well as their current statuses (enabled/disabled)", Run: func(cmd *cobra.Command, args []string) { if len(args) != 0 { - exit.Usage("usage: minikube addons list") + exit.UsageT("usage: minikube addons list") } err := addonList() if err != nil { diff --git a/cmd/minikube/cmd/config/configure.go b/cmd/minikube/cmd/config/configure.go index d017a5139feb..b51d240063b1 100644 --- a/cmd/minikube/cmd/config/configure.go +++ b/cmd/minikube/cmd/config/configure.go @@ -20,8 +20,8 @@ import ( "io/ioutil" "github.com/spf13/cobra" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/exit" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/service" ) @@ -31,7 +31,7 @@ var addonsConfigureCmd = &cobra.Command{ 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) { if len(args) != 1 { - exit.Usage("usage: minikube addons configure ADDON_NAME") + exit.UsageT("usage: minikube addons configure ADDON_NAME") } addon := args[0] @@ -77,7 +77,7 @@ var addonsConfigureCmd = &cobra.Command{ dat, err := ioutil.ReadFile(gcrPath) if err != nil { - console.Failure("Error reading %s: %v", gcrPath, err) + out.FailureT("Error reading {{.path}}: {{.error}}", out.V{"path": gcrPath, "error": err}) } else { gcrApplicationDefaultCredentials = string(dat) } @@ -109,7 +109,7 @@ var addonsConfigureCmd = &cobra.Command{ }) if err != nil { - console.FailureT("ERROR creating `registry-creds-ecr` secret: {{.error}}", console.Arg{"error": err}) + out.FailureT("ERROR creating `registry-creds-ecr` secret: {{.error}}", out.V{"error": err}) } // Create GCR Secret @@ -127,7 +127,7 @@ var addonsConfigureCmd = &cobra.Command{ }) if err != nil { - console.FailureT("ERROR creating `registry-creds-gcr` secret: {{.error}}", console.Arg{"error": err}) + out.FailureT("ERROR creating `registry-creds-gcr` secret: {{.error}}", out.V{"error": err}) } // Create Docker Secret @@ -146,14 +146,14 @@ var addonsConfigureCmd = &cobra.Command{ }) if err != nil { - console.WarningT("ERROR creating `registry-creds-dpr` secret") + out.WarningT("ERROR creating `registry-creds-dpr` secret") } default: - console.FailureT("{{.name}} has no available configuration options", console.Arg{"name": addon}) + out.FailureT("{{.name}} has no available configuration options", out.V{"name": addon}) return } - console.SuccessT("{{.name}} was successfully configured", console.Arg{"name": addon}) + out.SuccessT("{{.name}} was successfully configured", out.V{"name": addon}) }, } diff --git a/cmd/minikube/cmd/config/disable.go b/cmd/minikube/cmd/config/disable.go index 34b98041ef36..6901f43bd416 100644 --- a/cmd/minikube/cmd/config/disable.go +++ b/cmd/minikube/cmd/config/disable.go @@ -18,8 +18,8 @@ package config import ( "github.com/spf13/cobra" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/exit" + "k8s.io/minikube/pkg/minikube/out" ) var addonsDisableCmd = &cobra.Command{ @@ -36,7 +36,7 @@ var addonsDisableCmd = &cobra.Command{ if err != nil { exit.WithError("disable failed", err) } - console.SuccessT(`"{{.minikube_addon}}" was successfully disabled`, console.Arg{"minikube_addon": addon}) + out.SuccessT(`"{{.minikube_addon}}" was successfully disabled`, out.V{"minikube_addon": addon}) }, } diff --git a/cmd/minikube/cmd/config/enable.go b/cmd/minikube/cmd/config/enable.go index 189682174937..20b018b135e2 100644 --- a/cmd/minikube/cmd/config/enable.go +++ b/cmd/minikube/cmd/config/enable.go @@ -18,8 +18,8 @@ package config import ( "github.com/spf13/cobra" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/exit" + "k8s.io/minikube/pkg/minikube/out" ) var addonsEnableCmd = &cobra.Command{ @@ -28,7 +28,7 @@ var addonsEnableCmd = &cobra.Command{ Long: "Enables the addon w/ADDON_NAME within minikube (example: minikube addons enable dashboard). For a list of available addons use: minikube addons list ", Run: func(cmd *cobra.Command, args []string) { if len(args) != 1 { - exit.Usage("usage: minikube addons enable ADDON_NAME") + exit.UsageT("usage: minikube addons enable ADDON_NAME") } addon := args[0] @@ -36,7 +36,7 @@ var addonsEnableCmd = &cobra.Command{ if err != nil { exit.WithError("enable failed", err) } - console.SuccessT("{{.addonName}} was successfully enabled", console.Arg{"addonName": addon}) + out.SuccessT("{{.addonName}} was successfully enabled", out.V{"addonName": addon}) }, } diff --git a/cmd/minikube/cmd/config/get.go b/cmd/minikube/cmd/config/get.go index 704a1146f3e0..fa5747d27f59 100644 --- a/cmd/minikube/cmd/config/get.go +++ b/cmd/minikube/cmd/config/get.go @@ -22,7 +22,7 @@ import ( "github.com/spf13/cobra" pkgConfig "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" + "k8s.io/minikube/pkg/minikube/out" ) var configGetCmd = &cobra.Command{ @@ -44,7 +44,7 @@ var configGetCmd = &cobra.Command{ return fmt.Errorf("no value for key '%s'", args[0]) } - console.OutLn(val) + out.Ln(val) return nil }, } diff --git a/cmd/minikube/cmd/config/open.go b/cmd/minikube/cmd/config/open.go index 18b878279f1d..53d87aa8ad1b 100644 --- a/cmd/minikube/cmd/config/open.go +++ b/cmd/minikube/cmd/config/open.go @@ -22,10 +22,10 @@ import ( "github.com/spf13/cobra" "k8s.io/minikube/pkg/minikube/assets" "k8s.io/minikube/pkg/minikube/cluster" - "k8s.io/minikube/pkg/minikube/console" "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/service" ) @@ -47,7 +47,7 @@ var addonsOpenCmd = &cobra.Command{ PreRun: func(cmd *cobra.Command, args []string) { t, err := template.New("addonsURL").Parse(addonsURLFormat) if err != nil { - exit.UsageT("The value passed to --format is invalid: {{.error}}", console.Arg{"error": err}) + exit.UsageT("The value passed to --format is invalid: {{.error}}", out.V{"error": err}) } addonsURLTemplate = t }, @@ -68,7 +68,7 @@ var addonsOpenCmd = &cobra.Command{ if !ok { exit.WithCodeT(exit.Data, `addon '{{.name}}' is not a valid addon packaged with minikube. To see the list of available addons run: -minikube addons list`, console.Arg{"name": addonName}) +minikube addons list`, out.V{"name": addonName}) } ok, err = addon.IsEnabled() if err != nil { @@ -77,7 +77,7 @@ minikube addons list`, console.Arg{"name": addonName}) if !ok { exit.WithCodeT(exit.Unavailable, `addon '{{.name}}' is currently not enabled. To enable this addon run: -minikube addons enable {{.name}}`, console.Arg{"name": addonName}) +minikube addons enable {{.name}}`, out.V{"name": addonName}) } namespace := "kube-system" @@ -85,16 +85,16 @@ minikube addons enable {{.name}}`, console.Arg{"name": addonName}) serviceList, err := service.GetServiceListByLabel(namespace, key, addonName) if err != nil { - exit.WithCodeT(exit.Unavailable, "Error getting service with namespace: {{.namespace}} and labels {{.labelName}}:{{.addonName}}: {{.error}}", console.Arg{"namespace": namespace, "labelName": key, "addonName": addonName, "error": err}) + exit.WithCodeT(exit.Unavailable, "Error getting service with namespace: {{.namespace}} and labels {{.labelName}}:{{.addonName}}: {{.error}}", out.V{"namespace": namespace, "labelName": key, "addonName": addonName, "error": err}) } if len(serviceList.Items) == 0 { exit.WithCodeT(exit.Config, `This addon does not have an endpoint defined for the 'addons open' command. -You can add one by annotating a service with the label {{.labelName}}:{{.addonName}}`, console.Arg{"labelName": key, "addonName": addonName}) +You can add one by annotating a service with the label {{.labelName}}:{{.addonName}}`, out.V{"labelName": key, "addonName": addonName}) } for i := range serviceList.Items { svc := serviceList.Items[i].ObjectMeta.Name if err := service.WaitAndMaybeOpenService(api, namespace, svc, addonsURLTemplate, addonsURLMode, https, wait, interval); err != nil { - exit.WithCodeT(exit.Unavailable, "Wait failed: {{.error}}", console.Arg{"error": err}) + exit.WithCodeT(exit.Unavailable, "Wait failed: {{.error}}", out.V{"error": err}) } } }, diff --git a/cmd/minikube/cmd/config/profile.go b/cmd/minikube/cmd/config/profile.go index bb0113870fed..c15be55847ab 100644 --- a/cmd/minikube/cmd/config/profile.go +++ b/cmd/minikube/cmd/config/profile.go @@ -22,9 +22,9 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" pkgConfig "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/exit" + "k8s.io/minikube/pkg/minikube/out" pkgutil "k8s.io/minikube/pkg/util" ) @@ -36,7 +36,7 @@ var ProfileCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { profile := viper.GetString(pkgConfig.MachineProfile) - console.OutT(console.Empty, profile) + out.T(out.Empty, profile) os.Exit(0) } @@ -55,19 +55,19 @@ var ProfileCmd = &cobra.Command{ cc, err := pkgConfig.Load() // might err when loading older version of cfg file that doesn't have KeepContext field if err != nil && !os.IsNotExist(err) { - console.ErrT(console.Sad, `Error loading profile config: {{.error}}`, console.Arg{"error": err}) + out.ErrT(out.Sad, `Error loading profile config: {{.error}}`, out.V{"error": err}) } if err == nil { if cc.MachineConfig.KeepContext { - console.SuccessT("Skipped switching kubectl context for {{.profile_name}} , because --keep-context", console.Arg{"profile_name": profile}) - console.SuccessT("To connect to this cluster, use: kubectl --context={{.profile_name}}", console.Arg{"profile_name": profile}) + out.SuccessT("Skipped switching kubectl context for {{.profile_name}} , because --keep-context", out.V{"profile_name": profile}) + out.SuccessT("To connect to this cluster, use: kubectl --context={{.profile_name}}", out.V{"profile_name": profile}) } else { err := pkgutil.SetCurrentContext(constants.KubeconfigPath, profile) if err != nil { - console.ErrT(console.Sad, `Error while setting kubectl current context : {{.error}}`, console.Arg{"error": err}) + out.ErrT(out.Sad, `Error while setting kubectl current context : {{.error}}`, out.V{"error": err}) } } } - console.SuccessT("minikube profile was successfully set to {{.profile_name}}", console.Arg{"profile_name": profile}) + out.SuccessT("minikube profile was successfully set to {{.profile_name}}", out.V{"profile_name": profile}) }, } diff --git a/cmd/minikube/cmd/config/profile_list.go b/cmd/minikube/cmd/config/profile_list.go index c1287c00f7ed..4498e6d33c9e 100644 --- a/cmd/minikube/cmd/config/profile_list.go +++ b/cmd/minikube/cmd/config/profile_list.go @@ -22,8 +22,8 @@ import ( "strconv" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/exit" + "k8s.io/minikube/pkg/minikube/out" "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" @@ -55,18 +55,18 @@ var profileListCmd = &cobra.Command{ table.Render() if invalidProfiles != nil { - console.OutT(console.WarningType, "Found {{.number}} invalid profile(s) ! ", console.Arg{"number": len(invalidProfiles)}) + out.T(out.WarningType, "Found {{.number}} invalid profile(s) ! ", out.V{"number": len(invalidProfiles)}) for _, p := range invalidProfiles { - console.OutT(console.Empty, "\t "+p.Name) + out.T(out.Empty, "\t "+p.Name) } - console.OutT(console.Tip, "You can delete them using the following command(s): ") + out.T(out.Tip, "You can delete them using the following command(s): ") for _, p := range invalidProfiles { - console.Out(fmt.Sprintf("\t $ minikube delete -p %s \n", p.Name)) + out.String(fmt.Sprintf("\t $ minikube delete -p %s \n", p.Name)) } } if err != nil { - exit.WithCode(exit.Config, fmt.Sprintf("error loading profiles: %v", err)) + exit.WithCodeT(exit.Config, fmt.Sprintf("error loading profiles: %v", err)) } }, } diff --git a/cmd/minikube/cmd/config/prompt.go b/cmd/minikube/cmd/config/prompt.go index bbfbf19c52a7..91cbae6b7731 100644 --- a/cmd/minikube/cmd/config/prompt.go +++ b/cmd/minikube/cmd/config/prompt.go @@ -25,7 +25,7 @@ import ( "github.com/golang/glog" "golang.org/x/crypto/ssh/terminal" - "k8s.io/minikube/pkg/minikube/console" + "k8s.io/minikube/pkg/minikube/out" ) // AskForYesNoConfirmation asks the user for confirmation. A user must type in "yes" or "no" and @@ -36,7 +36,7 @@ func AskForYesNoConfirmation(s string, posResponses, negResponses []string) bool reader := bufio.NewReader(os.Stdin) for { - console.Out("%s [y/n]: ", s) + out.String("%s [y/n]: ", s) response, err := reader.ReadString('\n') if err != nil { @@ -49,7 +49,7 @@ func AskForYesNoConfirmation(s string, posResponses, negResponses []string) bool case containsString(negResponses, r): return false default: - console.Err("Please type yes or no:") + out.Err("Please type yes or no:") } } } @@ -63,7 +63,7 @@ func AskForStaticValue(s string) string { // Can't have zero length if len(response) == 0 { - console.Err("--Error, please enter a value:") + out.Err("--Error, please enter a value:") continue } return response @@ -78,7 +78,7 @@ func AskForStaticValueOptional(s string) string { } func getStaticValue(reader *bufio.Reader, s string) string { - console.Out("%s", s) + out.String("%s", s) response, err := reader.ReadString('\n') if err != nil { @@ -110,7 +110,7 @@ func concealableAskForStaticValue(readWriter io.ReadWriter, promptString string, } response = strings.TrimSpace(response) if len(response) == 0 { - console.Warning("Please enter a value:") + out.WarningT("Please enter a value:") continue } return response, nil diff --git a/cmd/minikube/cmd/config/set.go b/cmd/minikube/cmd/config/set.go index 3982a8e32103..096473a1512d 100644 --- a/cmd/minikube/cmd/config/set.go +++ b/cmd/minikube/cmd/config/set.go @@ -29,7 +29,7 @@ var configSetCmd = &cobra.Command{ These values can be overwritten by flags or environment variables at runtime.`, Run: func(cmd *cobra.Command, args []string) { if len(args) != 2 { - exit.Usage("usage: minikube config set PROPERTY_NAME PROPERTY_VALUE") + exit.UsageT("usage: minikube config set PROPERTY_NAME PROPERTY_VALUE") } err := Set(args[0], args[1]) if err != nil { diff --git a/cmd/minikube/cmd/config/unset.go b/cmd/minikube/cmd/config/unset.go index 1ea0723405aa..61fa7c7cbb23 100644 --- a/cmd/minikube/cmd/config/unset.go +++ b/cmd/minikube/cmd/config/unset.go @@ -28,7 +28,7 @@ var configUnsetCmd = &cobra.Command{ Long: "unsets PROPERTY_NAME from the minikube config file. Can be overwritten by flags or environmental variables", Run: func(cmd *cobra.Command, args []string) { if len(args) != 1 { - exit.Usage("usage: minikube config unset PROPERTY_NAME") + exit.UsageT("usage: minikube config unset PROPERTY_NAME") } err := unset(args[0]) if err != nil { diff --git a/cmd/minikube/cmd/config/util.go b/cmd/minikube/cmd/config/util.go index 2aa15c7ff346..18c0b5cd8ff7 100644 --- a/cmd/minikube/cmd/config/util.go +++ b/cmd/minikube/cmd/config/util.go @@ -27,10 +27,10 @@ import ( "k8s.io/minikube/pkg/minikube/cluster" "k8s.io/minikube/pkg/minikube/command" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "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" ) @@ -130,7 +130,7 @@ func EnableOrDisableAddon(name string, val string) error { cfg, err := config.Load() if err != nil && !os.IsNotExist(err) { - exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", console.Arg{"error": err}) + exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", out.V{"error": err}) } data := assets.GenerateTemplateData(cfg.KubernetesConfig) @@ -158,7 +158,7 @@ func enableOrDisableAddonInternal(addon *assets.Addon, cmd command.Runner, data var err error // check addon status before enabling/disabling it if err := isAddonAlreadySet(addon, enable); err != nil { - console.ErrT(console.Conflict, "{{.error}}", console.Arg{"error": err}) + out.ErrT(out.Conflict, "{{.error}}", out.V{"error": err}) os.Exit(0) } diff --git a/cmd/minikube/cmd/config/validations.go b/cmd/minikube/cmd/config/validations.go index dedd468b16f6..aa6ca13ae5bc 100644 --- a/cmd/minikube/cmd/config/validations.go +++ b/cmd/minikube/cmd/config/validations.go @@ -28,9 +28,9 @@ import ( "github.com/pkg/errors" "k8s.io/minikube/pkg/minikube/assets" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/cruntime" + "k8s.io/minikube/pkg/minikube/out" ) // containerdOnlyMsg is the message shown when a containerd-only addon is enabled @@ -55,7 +55,7 @@ func IsValidDriver(string, driver string) error { // RequiresRestartMsg returns the "requires restart" message func RequiresRestartMsg(string, string) error { - console.OutStyle(console.WarningType, "These changes will take effect upon a minikube delete and then a minikube start") + out.T(out.WarningType, "These changes will take effect upon a minikube delete and then a minikube start") return nil } diff --git a/cmd/minikube/cmd/dashboard.go b/cmd/minikube/cmd/dashboard.go index 2a04d8201c3c..b47f6870d648 100644 --- a/cmd/minikube/cmd/dashboard.go +++ b/cmd/minikube/cmd/dashboard.go @@ -35,9 +35,9 @@ import ( "k8s.io/minikube/pkg/minikube/assets" "k8s.io/minikube/pkg/minikube/cluster" pkg_config "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/machine" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/proxy" "k8s.io/minikube/pkg/minikube/service" "k8s.io/minikube/pkg/util" @@ -76,7 +76,7 @@ var dashboardCmd = &cobra.Command{ if _, err = api.Load(pkg_config.GetMachineName()); err != nil { switch err := errors.Cause(err).(type) { case mcnerror.ErrHostDoesNotExist: - exit.WithCodeT(exit.Unavailable, "{{.name}} cluster does not exist", console.Arg{"name": pkg_config.GetMachineName()}) + exit.WithCodeT(exit.Unavailable, "{{.name}} cluster does not exist", out.V{"name": pkg_config.GetMachineName()}) default: exit.WithError("Error getting cluster", err) } @@ -89,7 +89,7 @@ var dashboardCmd = &cobra.Command{ kubectl, err := exec.LookPath("kubectl") if err != nil { - exit.WithCode(exit.NoInput, "kubectl not found in PATH, but is required for the dashboard. Installation guide: https://kubernetes.io/docs/tasks/tools/install-kubectl/") + exit.WithCodeT(exit.NoInput, "kubectl not found in PATH, but is required for the dashboard. Installation guide: https://kubernetes.io/docs/tasks/tools/install-kubectl/") } cluster.EnsureMinikubeRunningOrExit(api, 1) @@ -99,7 +99,7 @@ var dashboardCmd = &cobra.Command{ dashboardStatus, _ := dashboardAddon.IsEnabled() if !dashboardStatus { // Send status messages to stderr for folks re-using this output. - console.ErrT(console.Enabling, "Enabling dashboard ...") + out.ErrT(out.Enabling, "Enabling dashboard ...") // Enable the dashboard add-on err = configcmd.Set("dashboard", "true") if err != nil { @@ -109,29 +109,29 @@ var dashboardCmd = &cobra.Command{ ns := "kube-system" svc := "kubernetes-dashboard" - console.ErrT(console.Verifying, "Verifying dashboard health ...") + out.ErrT(out.Verifying, "Verifying dashboard health ...") if err = util.RetryAfter(180, func() error { return service.CheckService(ns, svc) }, 1*time.Second); err != nil { - exit.WithCodeT(exit.Unavailable, "dashboard service is not running: {{.error}}", console.Arg{"error": err}) + exit.WithCodeT(exit.Unavailable, "dashboard service is not running: {{.error}}", out.V{"error": err}) } - console.ErrT(console.Launch, "Launching proxy ...") + out.ErrT(out.Launch, "Launching proxy ...") p, hostPort, err := kubectlProxy(kubectl) if err != nil { exit.WithError("kubectl proxy", err) } url := dashboardURL(hostPort, ns, svc) - console.ErrT(console.Verifying, "Verifying proxy health ...") + out.ErrT(out.Verifying, "Verifying proxy health ...") if err = util.RetryAfter(60, func() error { return checkURL(url) }, 1*time.Second); err != nil { - exit.WithCodeT(exit.Unavailable, "{{.url}} is not accessible: {{.error}}", console.Arg{"url": url, "error": err}) + exit.WithCodeT(exit.Unavailable, "{{.url}} is not accessible: {{.error}}", out.V{"url": url, "error": err}) } if dashboardURLMode { - console.OutLn(url) + out.Ln(url) } else { - console.ErrT(console.Celebrate, "Opening %s in your default browser...", console.Arg{"url": url}) + out.ErrT(out.Celebrate, "Opening %s in your default browser...", out.V{"url": url}) if err = browser.OpenURL(url); err != nil { - exit.WithCodeT(exit.Software, "failed to open browser: {{.error}}", console.Arg{"error": err}) + exit.WithCodeT(exit.Software, "failed to open browser: {{.error}}", out.V{"error": err}) } } diff --git a/cmd/minikube/cmd/delete.go b/cmd/minikube/cmd/delete.go index d4720164024e..960bd4c37427 100644 --- a/cmd/minikube/cmd/delete.go +++ b/cmd/minikube/cmd/delete.go @@ -28,10 +28,10 @@ import ( cmdUtil "k8s.io/minikube/cmd/util" "k8s.io/minikube/pkg/minikube/cluster" pkg_config "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/machine" + "k8s.io/minikube/pkg/minikube/out" pkgutil "k8s.io/minikube/pkg/util" ) @@ -58,7 +58,7 @@ func runDelete(cmd *cobra.Command, args []string) { cc, err := pkg_config.Load() if err != nil && !os.IsNotExist(err) { - console.ErrT(console.Sad, "Error loading profile config: {{.error}}", console.Arg{"name": profile}) + out.ErrT(out.Sad, "Error loading profile config: {{.error}}", out.V{"name": profile}) } // In the case of "none", we want to uninstall Kubernetes as there is no VM to delete @@ -69,24 +69,24 @@ func runDelete(cmd *cobra.Command, args []string) { if err = cluster.DeleteHost(api); err != nil { switch err := errors.Cause(err).(type) { case mcnerror.ErrHostDoesNotExist: - console.OutT(console.Meh, `"{{.name}}" cluster does not exist`, console.Arg{"name": profile}) + out.T(out.Meh, `"{{.name}}" cluster does not exist`, out.V{"name": profile}) default: exit.WithError("Failed to delete cluster", err) } } if err := cmdUtil.KillMountProcess(); err != nil { - console.FatalT("Failed to kill mount process: {{.error}}", console.Arg{"error": err}) + out.FatalT("Failed to kill mount process: {{.error}}", out.V{"error": err}) } if err := os.RemoveAll(constants.GetProfilePath(viper.GetString(pkg_config.MachineProfile))); err != nil { if os.IsNotExist(err) { - console.OutT(console.Meh, `"{{.profile_name}}" profile does not exist`, console.Arg{"profile_name": profile}) + out.T(out.Meh, `"{{.profile_name}}" profile does not exist`, out.V{"profile_name": profile}) os.Exit(0) } exit.WithError("Failed to remove profile", err) } - console.OutT(console.Crushed, `The "{{.cluster_name}}" cluster has been deleted.`, console.Arg{"cluster_name": profile}) + out.T(out.Crushed, `The "{{.cluster_name}}" cluster has been deleted.`, out.V{"cluster_name": profile}) machineName := pkg_config.GetMachineName() if err := pkgutil.DeleteKubeConfigContext(constants.KubeconfigPath, machineName); err != nil { @@ -95,12 +95,12 @@ func runDelete(cmd *cobra.Command, args []string) { } func uninstallKubernetes(api libmachine.API, kc pkg_config.KubernetesConfig, bsName string) { - console.OutT(console.Resetting, "Uninstalling Kubernetes {{.kubernetes_version}} using {{.bootstrapper_name}} ...", console.Arg{"kubernetes_version": kc.KubernetesVersion, "bootstrapper_name": bsName}) + out.T(out.Resetting, "Uninstalling Kubernetes {{.kubernetes_version}} using {{.bootstrapper_name}} ...", out.V{"kubernetes_version": kc.KubernetesVersion, "bootstrapper_name": bsName}) clusterBootstrapper, err := getClusterBootstrapper(api, bsName) if err != nil { - console.ErrT(console.Empty, "Unable to get bootstrapper: {{.error}}", console.Arg{"error": err}) + out.ErrT(out.Empty, "Unable to get bootstrapper: {{.error}}", out.V{"error": err}) } else if err = clusterBootstrapper.DeleteCluster(kc); err != nil { - console.ErrT(console.Empty, "Failed to delete cluster: {{.error}}", console.Arg{"error": err}) + out.ErrT(out.Empty, "Failed to delete cluster: {{.error}}", out.V{"error": err}) } } diff --git a/cmd/minikube/cmd/env.go b/cmd/minikube/cmd/env.go index cf4d669178a2..5b6ea1c0329e 100644 --- a/cmd/minikube/cmd/env.go +++ b/cmd/minikube/cmd/env.go @@ -344,21 +344,21 @@ var dockerEnvCmd = &cobra.Command{ exit.WithError("Error getting host", err) } if host.Driver.DriverName() == constants.DriverNone { - exit.Usage(`'none' driver does not support 'minikube docker-env' command`) + exit.UsageT(`'none' driver does not support 'minikube docker-env' command`) } hostSt, err := cluster.GetHostStatus(api) if err != nil { exit.WithError("Error getting host status", err) } if hostSt != state.Running.String() { - exit.WithCode(exit.Unavailable, `The docker host is currently not running`) + exit.WithCodeT(exit.Unavailable, `The docker host is currently not running`) } docker, err := GetDockerActive(host) if err != nil { exit.WithError("Error getting service status", err) } if !docker { - exit.WithCode(exit.Unavailable, `The docker service is currently not active`) + exit.WithCodeT(exit.Unavailable, `The docker service is currently not active`) } var shellCfg *ShellConfig diff --git a/cmd/minikube/cmd/ip.go b/cmd/minikube/cmd/ip.go index b2c078fe53ad..270e33261525 100644 --- a/cmd/minikube/cmd/ip.go +++ b/cmd/minikube/cmd/ip.go @@ -21,9 +21,9 @@ import ( "github.com/pkg/errors" "github.com/spf13/cobra" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/machine" + "k8s.io/minikube/pkg/minikube/out" ) // ipCmd represents the ip command @@ -42,7 +42,7 @@ var ipCmd = &cobra.Command{ if err != nil { switch err := errors.Cause(err).(type) { case mcnerror.ErrHostDoesNotExist: - exit.WithCodeT(exit.NoInput, `"{{.profile_name}}" host does not exist, unable to show an IP`, console.Arg{"profile_name": config.GetMachineName()}) + exit.WithCodeT(exit.NoInput, `"{{.profile_name}}" host does not exist, unable to show an IP`, out.V{"profile_name": config.GetMachineName()}) default: exit.WithError("Error getting host", err) } @@ -51,7 +51,7 @@ var ipCmd = &cobra.Command{ if err != nil { exit.WithError("Error getting IP", err) } - console.Out(ip) + out.Ln(ip) }, } diff --git a/cmd/minikube/cmd/kubectl.go b/cmd/minikube/cmd/kubectl.go index 5cf1424879a3..3761f41160d1 100644 --- a/cmd/minikube/cmd/kubectl.go +++ b/cmd/minikube/cmd/kubectl.go @@ -26,10 +26,10 @@ import ( "github.com/golang/glog" "github.com/spf13/cobra" pkg_config "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/machine" + "k8s.io/minikube/pkg/minikube/out" ) // kubectlCmd represents the kubectl command @@ -50,7 +50,7 @@ kubectl get pods --namespace kube-system`, cc, err := pkg_config.Load() if err != nil && !os.IsNotExist(err) { - console.ErrLn("Error loading profile config: %v", err) + out.ErrLn("Error loading profile config: %v", err) } binary := "kubectl" diff --git a/cmd/minikube/cmd/mount.go b/cmd/minikube/cmd/mount.go index 6135e0ccc4e4..4c05674bb933 100644 --- a/cmd/minikube/cmd/mount.go +++ b/cmd/minikube/cmd/mount.go @@ -31,10 +31,10 @@ import ( cmdUtil "k8s.io/minikube/cmd/util" "k8s.io/minikube/pkg/minikube/cluster" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "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/third_party/go9p/ufs" ) @@ -69,25 +69,25 @@ var mountCmd = &cobra.Command{ } if len(args) != 1 { - exit.Usage(`Please specify the directory to be mounted: + exit.UsageT(`Please specify the directory to be mounted: minikube mount : (example: "/host-home:/vm-home")`) } mountString := args[0] idx := strings.LastIndex(mountString, ":") if idx == -1 { // no ":" was present - exit.UsageT(`mount argument "{{.value}}" must be in form: :`, console.Arg{"value": mountString}) + exit.UsageT(`mount argument "{{.value}}" must be in form: :`, out.V{"value": mountString}) } hostPath := mountString[:idx] vmPath := mountString[idx+1:] if _, err := os.Stat(hostPath); err != nil { if os.IsNotExist(err) { - exit.WithCodeT(exit.NoInput, "Cannot find directory {{.path}} for mount", console.Arg{"path": hostPath}) + exit.WithCodeT(exit.NoInput, "Cannot find directory {{.path}} for mount", out.V{"path": hostPath}) } else { exit.WithError("stat failed", err) } } if len(vmPath) == 0 || !strings.HasPrefix(vmPath, "/") { - exit.UsageT("Target directory {{.path}} must be an absolute path", console.Arg{"path": vmPath}) + exit.UsageT("Target directory {{.path}} must be an absolute path", out.V{"path": vmPath}) } var debugVal int if glog.V(1) { @@ -104,7 +104,7 @@ var mountCmd = &cobra.Command{ exit.WithError("Error loading api", err) } if host.Driver.DriverName() == constants.DriverNone { - exit.Usage(`'none' driver does not support 'minikube mount' command`) + exit.UsageT(`'none' driver does not support 'minikube mount' command`) } var ip net.IP if mountIP == "" { @@ -115,7 +115,7 @@ var mountCmd = &cobra.Command{ } else { ip = net.ParseIP(mountIP) if ip == nil { - exit.WithCode(exit.Data, "error parsing the input ip address for mount") + exit.WithCodeT(exit.Data, "error parsing the input ip address for mount") } } port, err := cmdUtil.GetPort() @@ -143,27 +143,27 @@ var mountCmd = &cobra.Command{ cfg.Options[parts[0]] = parts[1] } - console.OutT(console.Mounting, "Mounting host path {{.sourcePath}} into VM as {{.destinationPath}} ...", console.Arg{"sourcePath": hostPath, "destinationPath": vmPath}) - console.OutT(console.Option, "Mount type: {{.name}}", console.Arg{"type": cfg.Type}) - console.OutT(console.Option, "User ID: {{.userID}}", console.Arg{"userID": cfg.UID}) - console.OutT(console.Option, "Group ID: {{.groupID}}", console.Arg{"groupID": cfg.GID}) - console.OutT(console.Option, "Version: {{.version}}", console.Arg{"version": cfg.Version}) - console.OutT(console.Option, "Message Size: {{.size}}", console.Arg{"size": cfg.MSize}) - console.OutT(console.Option, "Permissions: {{.octalMode}} ({{.writtenMode}})", console.Arg{"octalMode": fmt.Sprintf("%o", cfg.Mode), "writtenMode": cfg.Mode}) - console.OutT(console.Option, "Options: {{.options}}", console.Arg{"options": cfg.Options}) + out.T(out.Mounting, "Mounting host path {{.sourcePath}} into VM as {{.destinationPath}} ...", out.V{"sourcePath": hostPath, "destinationPath": vmPath}) + out.T(out.Option, "Mount type: {{.name}}", out.V{"type": cfg.Type}) + out.T(out.Option, "User ID: {{.userID}}", out.V{"userID": cfg.UID}) + out.T(out.Option, "Group ID: {{.groupID}}", out.V{"groupID": cfg.GID}) + out.T(out.Option, "Version: {{.version}}", out.V{"version": cfg.Version}) + out.T(out.Option, "Message Size: {{.size}}", out.V{"size": cfg.MSize}) + out.T(out.Option, "Permissions: {{.octalMode}} ({{.writtenMode}})", out.V{"octalMode": fmt.Sprintf("%o", cfg.Mode), "writtenMode": cfg.Mode}) + out.T(out.Option, "Options: {{.options}}", out.V{"options": cfg.Options}) // An escape valve to allow future hackers to try NFS, VirtFS, or other FS types. if !supportedFilesystems[cfg.Type] { - console.OutT(console.WarningType, "{{.type}} is not yet a supported filesystem. We will try anyways!", console.Arg{"type": cfg.Type}) + out.T(out.WarningType, "{{.type}} is not yet a supported filesystem. We will try anyways!", out.V{"type": cfg.Type}) } var wg sync.WaitGroup if cfg.Type == nineP { wg.Add(1) go func() { - console.OutT(console.Fileserver, "Userspace file server: ") + out.T(out.Fileserver, "Userspace file server: ") ufs.StartServer(net.JoinHostPort(ip.String(), strconv.Itoa(port)), debugVal, hostPath) - console.OutT(console.Stopped, "Userspace file server is shutdown") + out.T(out.Stopped, "Userspace file server is shutdown") wg.Done() }() } @@ -179,12 +179,12 @@ var mountCmd = &cobra.Command{ signal.Notify(c, os.Interrupt, syscall.SIGTERM) go func() { for sig := range c { - console.OutT(console.Unmount, "Unmounting {{.path}} ...", console.Arg{"path": vmPath}) + out.T(out.Unmount, "Unmounting {{.path}} ...", out.V{"path": vmPath}) err := cluster.Unmount(runner, vmPath) if err != nil { - console.ErrT(console.FailureType, "Failed unmount: {{.error}}", console.Arg{"error": err}) + out.ErrT(out.FailureType, "Failed unmount: {{.error}}", out.V{"error": err}) } - exit.WithCodeT(exit.Interrupted, "Received {{.name}} signal", console.Arg{"name": sig}) + exit.WithCodeT(exit.Interrupted, "Received {{.name}} signal", out.V{"name": sig}) } }() @@ -192,9 +192,9 @@ var mountCmd = &cobra.Command{ if err != nil { exit.WithError("mount failed", err) } - console.OutT(console.SuccessType, "Successfully mounted {{.sourcePath}} to {{.destinationPath}}", console.Arg{"sourcePath": hostPath, "destinationPath": vmPath}) - console.OutLn("") - console.OutT(console.Notice, "NOTE: This process must stay alive for the mount to be accessible ...") + out.T(out.SuccessType, "Successfully mounted {{.sourcePath}} to {{.destinationPath}}", out.V{"sourcePath": hostPath, "destinationPath": vmPath}) + out.Ln("") + out.T(out.Notice, "NOTE: This process must stay alive for the mount to be accessible ...") wg.Wait() }, } diff --git a/cmd/minikube/cmd/service.go b/cmd/minikube/cmd/service.go index 84e8db0ae604..94c3c8ad9e99 100644 --- a/cmd/minikube/cmd/service.go +++ b/cmd/minikube/cmd/service.go @@ -55,7 +55,7 @@ var serviceCmd = &cobra.Command{ }, Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 || len(args) > 1 { - exit.Usage("You must specify a service name") + exit.UsageT("You must specify a service name") } svc := args[0] diff --git a/cmd/minikube/cmd/service_list.go b/cmd/minikube/cmd/service_list.go index e1e6a4ed7ef5..ad1903a4b892 100644 --- a/cmd/minikube/cmd/service_list.go +++ b/cmd/minikube/cmd/service_list.go @@ -22,9 +22,9 @@ import ( "github.com/spf13/cobra" core "k8s.io/api/core/v1" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/machine" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/service" ) @@ -43,8 +43,8 @@ var serviceListCmd = &cobra.Command{ defer api.Close() serviceURLs, err := service.GetServiceURLs(api, serviceListNamespace, serviceURLTemplate) if err != nil { - console.FatalT("Failed to get service URL: {{.error}}", console.Arg{"error": err}) - console.ErrT(console.Notice, "Check that minikube is running and that you have specified the correct namespace (-n flag) if required.") + out.FatalT("Failed to get service URL: {{.error}}", out.V{"error": err}) + out.ErrT(out.Notice, "Check that minikube is running and that you have specified the correct namespace (-n flag) if required.") os.Exit(exit.Unavailable) } diff --git a/cmd/minikube/cmd/ssh-key.go b/cmd/minikube/cmd/ssh-key.go index b1fb4e2717be..f549ea413144 100644 --- a/cmd/minikube/cmd/ssh-key.go +++ b/cmd/minikube/cmd/ssh-key.go @@ -21,8 +21,8 @@ import ( "github.com/spf13/cobra" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/out" ) // sshKeyCmd represents the sshKey command @@ -31,7 +31,7 @@ var sshKeyCmd = &cobra.Command{ Short: "Retrieve the ssh identity key path of the specified cluster", Long: "Retrieve the ssh identity key path of the specified cluster.", Run: func(cmd *cobra.Command, args []string) { - console.OutLn(filepath.Join(constants.GetMinipath(), "machines", config.GetMachineName(), "id_rsa")) + out.Ln(filepath.Join(constants.GetMinipath(), "machines", config.GetMachineName(), "id_rsa")) }, } diff --git a/cmd/minikube/cmd/ssh.go b/cmd/minikube/cmd/ssh.go index e791f6933095..e0a0fc91d273 100644 --- a/cmd/minikube/cmd/ssh.go +++ b/cmd/minikube/cmd/ssh.go @@ -22,10 +22,10 @@ import ( "github.com/spf13/cobra" "k8s.io/minikube/pkg/minikube/cluster" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/machine" + "k8s.io/minikube/pkg/minikube/out" ) // sshCmd represents the docker-ssh command @@ -44,12 +44,12 @@ var sshCmd = &cobra.Command{ exit.WithError("Error getting host", err) } if host.Driver.DriverName() == constants.DriverNone { - exit.Usage("'none' driver does not support 'minikube ssh' command") + exit.UsageT("'none' driver does not support 'minikube ssh' command") } err = cluster.CreateSSHShell(api, args) if err != nil { // This is typically due to a non-zero exit code, so no need for flourish. - console.ErrLn("ssh: %v", err) + out.ErrLn("ssh: %v", err) // It'd be nice if we could pass up the correct error code here :( os.Exit(exit.Failure) } diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index a6ca6c66e902..847dbc637450 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -51,12 +51,12 @@ import ( "k8s.io/minikube/pkg/minikube/cluster" "k8s.io/minikube/pkg/minikube/command" cfg "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/cruntime" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/logs" "k8s.io/minikube/pkg/minikube/machine" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/proxy" pkgutil "k8s.io/minikube/pkg/util" "k8s.io/minikube/pkg/version" @@ -209,7 +209,7 @@ var startCmd = &cobra.Command{ // runStart handles the executes the flow of "minikube start" func runStart(cmd *cobra.Command, args []string) { - console.OutT(console.Happy, "minikube {{.version}} on {{.os}} ({{.arch}})", console.Arg{"version": version.GetVersion(), "os": runtime.GOOS, "arch": runtime.GOARCH}) + out.T(out.Happy, "minikube {{.version}} on {{.os}} ({{.arch}})", out.V{"version": version.GetVersion(), "os": runtime.GOOS, "arch": runtime.GOARCH}) validateConfig() validateUser() @@ -253,7 +253,7 @@ func runStart(cmd *cobra.Command, args []string) { bootstrapCluster(bs, cr, mRunner, config.KubernetesConfig, preExists, isUpgrade) configureMounts() if err = loadCachedImagesInConfigFile(); err != nil { - console.OutT(console.FailureType, "Unable to load cached images from config file.") + out.T(out.FailureType, "Unable to load cached images from config file.") } // special ops for none driver, like change minikube directory. prepareNone(viper.GetString(vmDriver)) @@ -278,7 +278,7 @@ func handleDownloadOnly(cacheGroup *errgroup.Group, k8sVersion string) { if err := CacheImagesInConfigFile(); err != nil { exit.WithError("Failed to cache images", err) } - console.OutT(console.Check, "Download complete!") + out.T(out.Check, "Download complete!") os.Exit(0) } @@ -294,7 +294,7 @@ func startMachine(config *cfg.Config) (runner command.Runner, preExists bool, ma // Bypass proxy for minikube's vm host ip err = proxy.ExcludeIP(ip) if err != nil { - console.ErrT(console.FailureType, "Failed to set NO_PROXY Env. Please use `export NO_PROXY=$NO_PROXY,{{.ip}}`.", console.Arg{"ip": ip}) + out.ErrT(out.FailureType, "Failed to set NO_PROXY Env. Please use `export NO_PROXY=$NO_PROXY,{{.ip}}`.", out.V{"ip": ip}) } // Save IP to configuration file for subsequent use config.KubernetesConfig.NodeIP = ip @@ -312,7 +312,7 @@ func startMachine(config *cfg.Config) (runner command.Runner, preExists bool, ma func getKubernetesVersion() (k8sVersion string, isUpgrade bool) { oldConfig, err := cfg.Load() if err != nil && !os.IsNotExist(err) { - exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", console.Arg{"error": err}) + exit.WithCodeT(exit.Data, "Unable to load config: {{.error}}", out.V{"error": err}) } return validateKubernetesVersions(oldConfig) } @@ -334,28 +334,28 @@ func skipCache(config *cfg.Config) { func showVersionInfo(k8sVersion string, cr cruntime.Manager) { version, _ := cr.Version() - console.OutT(cr.Style(), "Configuring environment for Kubernetes {{.k8sVersion}} on {{.runtime}} {{.runtimeVersion}}", console.Arg{"k8sVersion": k8sVersion, "runtime": cr.Name(), "runtimeVersion": version}) + out.T(cr.Style(), "Configuring environment for Kubernetes {{.k8sVersion}} on {{.runtime}} {{.runtimeVersion}}", out.V{"k8sVersion": k8sVersion, "runtime": cr.Name(), "runtimeVersion": version}) for _, v := range dockerOpt { - console.OutT(console.Option, "opt {{.docker_option}}", console.Arg{"docker_option": v}) + out.T(out.Option, "opt {{.docker_option}}", out.V{"docker_option": v}) } for _, v := range dockerEnv { - console.OutT(console.Option, "env {{.docker_env}}", console.Arg{"docker_env": v}) + out.T(out.Option, "env {{.docker_env}}", out.V{"docker_env": v}) } } func showKubectlConnectInfo(kubeconfig *pkgutil.KubeConfigSetup) { if kubeconfig.KeepContext { - console.OutT(console.Kubectl, "To connect to this cluster, use: kubectl --context={{.name}}", console.Arg{"name": kubeconfig.ClusterName}) + out.T(out.Kubectl, "To connect to this cluster, use: kubectl --context={{.name}}", out.V{"name": kubeconfig.ClusterName}) } else { if !viper.GetBool(waitUntilHealthy) { - console.OutT(console.Ready, "kubectl has been configured configured to use {{.name}}", console.Arg{"name": cfg.GetMachineName()}) + out.T(out.Ready, "kubectl has been configured configured to use {{.name}}", out.V{"name": cfg.GetMachineName()}) } else { - console.OutT(console.Ready, "Done! kubectl is now configured to use {{.name}}", console.Arg{"name": cfg.GetMachineName()}) + out.T(out.Ready, "Done! kubectl is now configured to use {{.name}}", out.V{"name": cfg.GetMachineName()}) } } _, err := exec.LookPath("kubectl") if err != nil { - console.OutT(console.Tip, "For best results, install kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/") + out.T(out.Tip, "For best results, install kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/") } } @@ -418,9 +418,9 @@ func validateUser() { // Check if minikube needs to run with sudo or not. if err == nil { if d == constants.DriverNone && u.Name != "root" { - exit.UsageT(`Please run with sudo. the vm-driver "{{.driver_name}}" requires sudo.`, console.Arg{"driver_name": constants.DriverNone}) + exit.UsageT(`Please run with sudo. the vm-driver "{{.driver_name}}" requires sudo.`, out.V{"driver_name": constants.DriverNone}) } else if u.Name == "root" && !(d == constants.DriverHyperv || d == constants.DriverNone) { - console.OutT(console.WarningType, "Please don't run minikube as root or with 'sudo' privileges. It isn't necessary with {{.driver}} driver.", console.Arg{"driver": d}) + out.T(out.WarningType, "Please don't run minikube as root or with 'sudo' privileges. It isn't necessary with {{.driver}} driver.", out.V{"driver": d}) } } else { @@ -433,7 +433,7 @@ func validateUser() { func validateConfig() { diskSizeMB := pkgutil.CalculateSizeInMB(viper.GetString(humanReadableDiskSize)) if diskSizeMB < pkgutil.CalculateSizeInMB(constants.MinimumDiskSize) { - exit.WithCodeT(exit.Config, "Requested disk size {{.size_in_mb}} is less than minimum of {{.size_in_mb2}}", console.Arg{"size_in_mb": diskSizeMB, "size_in_mb2": pkgutil.CalculateSizeInMB(constants.MinimumDiskSize)}) + exit.WithCodeT(exit.Config, "Requested disk size {{.size_in_mb}} is less than minimum of {{.size_in_mb2}}", out.V{"size_in_mb": diskSizeMB, "size_in_mb2": pkgutil.CalculateSizeInMB(constants.MinimumDiskSize)}) } err := autoSetOptions(viper.GetString(vmDriver)) @@ -443,18 +443,18 @@ func validateConfig() { memorySizeMB := pkgutil.CalculateSizeInMB(viper.GetString(memory)) if memorySizeMB < pkgutil.CalculateSizeInMB(constants.MinimumMemorySize) { - exit.UsageT("Requested memory allocation {{.size_in_mb}} is less than the minimum allowed of {{.size_in_mb2}}", console.Arg{"size_in_mb": memorySizeMB, "size_in_mb2": pkgutil.CalculateSizeInMB(constants.MinimumMemorySize)}) + exit.UsageT("Requested memory allocation {{.size_in_mb}} is less than the minimum allowed of {{.size_in_mb2}}", out.V{"size_in_mb": memorySizeMB, "size_in_mb2": pkgutil.CalculateSizeInMB(constants.MinimumMemorySize)}) } if memorySizeMB < pkgutil.CalculateSizeInMB(constants.DefaultMemorySize) { - console.OutT(console.Notice, "Requested memory allocation ({{.memory}}MB) is less than the default memory allocation of {{.default_memorysize}}MB. Beware that minikube might not work correctly or crash unexpectedly.", - console.Arg{"memory": memorySizeMB, "default_memorysize": pkgutil.CalculateSizeInMB(constants.DefaultMemorySize)}) + out.T(out.Notice, "Requested memory allocation ({{.memory}}MB) is less than the default memory allocation of {{.default_memorysize}}MB. Beware that minikube might not work correctly or crash unexpectedly.", + out.V{"memory": memorySizeMB, "default_memorysize": pkgutil.CalculateSizeInMB(constants.DefaultMemorySize)}) } // check that kubeadm extra args contain only whitelisted parameters for param := range extraOptions.AsMap().Get(kubeadm.Kubeadm) { if !pkgutil.ContainsString(kubeadm.KubeadmExtraArgsWhitelist[kubeadm.KubeadmCmdParam], param) && !pkgutil.ContainsString(kubeadm.KubeadmExtraArgsWhitelist[kubeadm.KubeadmConfigParam], param) { - exit.UsageT("Sorry, the kubeadm.{{.parameter_name}} parameter is currently not supported by --extra-config", console.Arg{"parameter_name": param}) + exit.UsageT("Sorry, the kubeadm.{{.parameter_name}} parameter is currently not supported by --extra-config", out.V{"parameter_name": param}) } } @@ -472,7 +472,7 @@ func validateRegistryMirror() { glog.Errorln("Error Parsing URL: ", err) } if (URL.Scheme != "http" && URL.Scheme != "https") || URL.Path != "" { - exit.UsageT("Sorry, url provided with --registry-mirror flag is invalid {{.url}}", console.Arg{"url": loc}) + exit.UsageT("Sorry, url provided with --registry-mirror flag is invalid {{.url}}", out.V{"url": loc}) } } @@ -546,9 +546,9 @@ func generateConfig(cmd *cobra.Command, k8sVersion string) (cfg.Config, error) { if !found { if autoSelectedRepository == "" { - exit.WithCode(exit.Failure, "None of known repositories is accessible. Consider specifying an alternative image repository with --image-repository flag") + exit.WithCodeT(exit.Failure, "None of known repositories is accessible. Consider specifying an alternative image repository with --image-repository flag") } else { - console.WarningT("None of known repositories in your location is accessible. Use {{.image_repository_name}} as fallback.", console.Arg{"image_repository_name": autoSelectedRepository}) + out.WarningT("None of known repositories in your location is accessible. Use {{.image_repository_name}} as fallback.", out.V{"image_repository_name": autoSelectedRepository}) } } @@ -556,7 +556,7 @@ func generateConfig(cmd *cobra.Command, k8sVersion string) (cfg.Config, error) { } if repository != "" { - console.OutT(console.SuccessType, "Using image repository {{.name}}", console.Arg{"name": repository}) + out.T(out.SuccessType, "Using image repository {{.name}}", out.V{"name": repository}) } cfg := cfg.Config{ @@ -627,31 +627,31 @@ func prepareNone(vmDriver string) { if vmDriver != constants.DriverNone { return } - console.OutT(console.StartingNone, "Configuring local host environment ...") + out.T(out.StartingNone, "Configuring local host environment ...") if viper.GetBool(cfg.WantNoneDriverWarning) { - console.OutT(console.Empty, "") - console.WarningT("The 'none' driver provides limited isolation and may reduce system security and reliability.") - console.WarningT("For more information, see:") - console.OutT(console.URL, "https://github.com/kubernetes/minikube/blob/master/docs/vmdriver-none.md") - console.OutT(console.Empty, "") + out.T(out.Empty, "") + out.WarningT("The 'none' driver provides limited isolation and may reduce system security and reliability.") + out.WarningT("For more information, see:") + out.T(out.URL, "https://github.com/kubernetes/minikube/blob/master/docs/vmdriver-none.md") + out.T(out.Empty, "") } if os.Getenv("CHANGE_MINIKUBE_NONE_USER") == "" { home := os.Getenv("HOME") - console.WarningT("kubectl and minikube configuration will be stored in {{.home_folder}}", console.Arg{"home_folder": home}) - console.WarningT("To use kubectl or minikube commands as your own user, you may") - console.WarningT("need to relocate them. For example, to overwrite your own settings:") + out.WarningT("kubectl and minikube configuration will be stored in {{.home_folder}}", out.V{"home_folder": home}) + out.WarningT("To use kubectl or minikube commands as your own user, you may") + out.WarningT("need to relocate them. For example, to overwrite your own settings:") - console.OutT(console.Empty, "") - console.OutT(console.Command, "sudo mv {{.home_folder}}/.kube {{.home_folder}}/.minikube $HOME", console.Arg{"home_folder": home}) - console.OutT(console.Command, "sudo chown -R $USER $HOME/.kube $HOME/.minikube") - console.OutT(console.Empty, "") + out.T(out.Empty, "") + out.T(out.Command, "sudo mv {{.home_folder}}/.kube {{.home_folder}}/.minikube $HOME", out.V{"home_folder": home}) + out.T(out.Command, "sudo chown -R $USER $HOME/.kube $HOME/.minikube") + out.T(out.Empty, "") - console.OutT(console.Tip, "This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true") + out.T(out.Tip, "This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true") } if err := pkgutil.MaybeChownDirRecursiveToMinikubeUser(constants.GetMinipath()); err != nil { - exit.WithCodeT(exit.Permissions, "Failed to chown {{.minikube_dir_path}}: {{.error}}", console.Arg{"minikube_dir_path": constants.GetMinipath(), "error": err}) + exit.WithCodeT(exit.Permissions, "Failed to chown {{.minikube_dir_path}}: {{.error}}", out.V{"minikube_dir_path": constants.GetMinipath(), "error": err}) } } @@ -688,14 +688,14 @@ func validateNetwork(h *host.Host) string { for _, k := range proxy.EnvVars { if v := os.Getenv(k); v != "" { if !optSeen { - console.OutT(console.Internet, "Found network options:") + out.T(out.Internet, "Found network options:") optSeen = true } - console.OutT(console.Option, "{{.key}}={{.value}}", console.Arg{"key": k, "value": v}) + out.T(out.Option, "{{.key}}={{.value}}", out.V{"key": k, "value": v}) ipExcluded := proxy.IsIPExcluded(ip) // Skip warning if minikube ip is already in NO_PROXY k = strings.ToUpper(k) // for http_proxy & https_proxy if (k == "HTTP_PROXY" || k == "HTTPS_PROXY") && !ipExcluded && !warnedOnce { - console.WarningT("You appear to be using a proxy, but your NO_PROXY environment does not include the minikube IP ({{.ip_address}}). Please see https://github.com/kubernetes/minikube/blob/master/docs/http_proxy.md for more details", console.Arg{"ip_address": ip}) + out.WarningT("You appear to be using a proxy, but your NO_PROXY environment does not include the minikube IP ({{.ip_address}}). Please see https://github.com/kubernetes/minikube/blob/master/docs/http_proxy.md for more details", out.V{"ip_address": ip}) warnedOnce = true } } @@ -715,7 +715,7 @@ func validateKubernetesVersions(old *cfg.Config) (string, bool) { nvs, err := semver.Make(strings.TrimPrefix(rawVersion, version.VersionPrefix)) if err != nil { - exit.WithCodeT(exit.Data, `Unable to parse "{{.kubenretes_version}}": {{.error}}`, console.Arg{"kubenretes_version": rawVersion, "error": err}) + exit.WithCodeT(exit.Data, `Unable to parse "{{.kubenretes_version}}": {{.error}}`, out.V{"kubenretes_version": rawVersion, "error": err}) } nv := version.VersionPrefix + nvs.String() @@ -730,11 +730,11 @@ func validateKubernetesVersions(old *cfg.Config) (string, bool) { if nvs.LT(ovs) { nv = version.VersionPrefix + ovs.String() - console.ErrT(console.Conflict, "Kubernetes downgrade is not supported, will continue to use {{.version}}", console.Arg{"version": nv}) + out.ErrT(out.Conflict, "Kubernetes downgrade is not supported, will continue to use {{.version}}", out.V{"version": nv}) return nv, isUpgrade } if nvs.GT(ovs) { - console.OutT(console.ThumbsUp, "minikube will upgrade the local cluster from Kubernetes {{.old}} to {{.new}}", console.Arg{"old": ovs, "new": nvs}) + out.T(out.ThumbsUp, "minikube will upgrade the local cluster from Kubernetes {{.old}} to {{.new}}", out.V{"old": ovs, "new": nvs}) isUpgrade = true } return nv, isUpgrade @@ -747,7 +747,7 @@ func setupKubeAdm(mAPI libmachine.API, kc cfg.KubernetesConfig) bootstrapper.Boo exit.WithError("Failed to get bootstrapper", err) } for _, eo := range extraOptions { - console.OutT(console.Option, "{{.extra_option_component_name}}.{{.key}}={{.value}}", console.Arg{"extra_option_component_name": eo.Component, "key": eo.Key, "value": eo.Value}) + out.T(out.Option, "{{.extra_option_component_name}}.{{.key}}={{.value}}", out.V{"extra_option_component_name": eo.Component, "key": eo.Key, "value": eo.Value}) } // Loads cached images, generates config files, download binaries if err := bs.UpdateCluster(kc); err != nil { @@ -813,21 +813,21 @@ func bootstrapCluster(bs bootstrapper.Bootstrapper, r cruntime.Manager, runner c bsName := viper.GetString(cmdcfg.Bootstrapper) if isUpgrade || !preexisting { - console.OutT(console.Pulling, "Pulling images ...") + out.T(out.Pulling, "Pulling images ...") if err := bs.PullImages(kc); err != nil { - console.OutT(console.FailureType, "Unable to pull images, which may be OK: {{.error}}", console.Arg{"error": err}) + out.T(out.FailureType, "Unable to pull images, which may be OK: {{.error}}", out.V{"error": err}) } } if preexisting { - console.OutT(console.Restarting, "Relaunching Kubernetes {{.version}} using {{.bootstrapper}} ... ", console.Arg{"version": kc.KubernetesVersion, "bootstrapper": bsName}) + out.T(out.Restarting, "Relaunching Kubernetes {{.version}} using {{.bootstrapper}} ... ", out.V{"version": kc.KubernetesVersion, "bootstrapper": bsName}) if err := bs.RestartCluster(kc); err != nil { exit.WithLogEntries("Error restarting cluster", err, logs.FindProblems(r, bs, runner)) } return } - console.OutT(console.Launch, "Launching Kubernetes ... ") + out.T(out.Launch, "Launching Kubernetes ... ") if err := bs.StartCluster(kc); err != nil { exit.WithLogEntries("Error starting cluster", err, logs.FindProblems(r, bs, runner)) } @@ -839,7 +839,7 @@ func configureMounts() { return } - console.OutT(console.Mounting, "Creating mount {{.name}} ...", console.Arg{"name": viper.GetString(mountString)}) + out.T(out.Mounting, "Creating mount {{.name}} ...", out.V{"name": viper.GetString(mountString)}) path := os.Args[0] mountDebugVal := 0 if glog.V(8) { @@ -911,7 +911,7 @@ func validateDriverVersion(vmDriver string) { // we don't want to fail if an error was returned, // libmachine has a nice message for the user if the driver isn't present if err != nil { - console.WarningT("Error checking driver version: {{.error}}", console.Arg{"error": err}) + out.WarningT("Error checking driver version: {{.error}}", out.V{"error": err}) return } @@ -919,23 +919,23 @@ func validateDriverVersion(vmDriver string) { // if the driver doesn't have return any version, it is really old, we force a upgrade. if len(v) == 0 { - exit.WithCodeT(exit.Failure, "Please upgrade the 'docker-machine-driver-kvm2'. {{.documentation_url}}", console.Arg{"documentation_url": constants.KVMDocumentation}) + exit.WithCodeT(exit.Failure, "Please upgrade the 'docker-machine-driver-kvm2'. {{.documentation_url}}", out.V{"documentation_url": constants.KVMDocumentation}) } vmDriverVersion, err := semver.Make(v) if err != nil { - console.WarningT("Error parsing vmDriver version: {{.error}}", console.Arg{"error": err}) + out.WarningT("Error parsing vmDriver version: {{.error}}", out.V{"error": err}) return } minikubeVersion, err := version.GetSemverVersion() if err != nil { - console.WarningT("Error parsing minukube version: {{.error}}", console.Arg{"error": err}) + out.WarningT("Error parsing minukube version: {{.error}}", out.V{"error": err}) return } if vmDriverVersion.LT(minikubeVersion) { - console.WarningT("The 'docker-machine-driver-kvm2' version is old. Please consider upgrading. {{.documentation_url}}", console.Arg{"documentation_url": constants.KVMDocumentation}) + out.WarningT("The 'docker-machine-driver-kvm2' version is old. Please consider upgrading. {{.documentation_url}}", out.V{"documentation_url": constants.KVMDocumentation}) } } } diff --git a/cmd/minikube/cmd/status.go b/cmd/minikube/cmd/status.go index 98109af221cb..10764c96cf21 100644 --- a/cmd/minikube/cmd/status.go +++ b/cmd/minikube/cmd/status.go @@ -28,10 +28,10 @@ import ( "k8s.io/minikube/cmd/util" "k8s.io/minikube/pkg/minikube/cluster" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/machine" + "k8s.io/minikube/pkg/minikube/out" pkgutil "k8s.io/minikube/pkg/util" ) @@ -62,7 +62,7 @@ var statusCmd = &cobra.Command{ var returnCode = 0 api, err := machine.NewAPIClient() if err != nil { - exit.WithCodeT(exit.Unavailable, "Error getting client: {{.error}}", console.Arg{"error": err}) + exit.WithCodeT(exit.Unavailable, "Error getting client: {{.error}}", out.V{"error": err}) } defer api.Close() diff --git a/cmd/minikube/cmd/stop.go b/cmd/minikube/cmd/stop.go index 74755465136b..8dcd5f58ee36 100644 --- a/cmd/minikube/cmd/stop.go +++ b/cmd/minikube/cmd/stop.go @@ -26,10 +26,10 @@ import ( cmdUtil "k8s.io/minikube/cmd/util" "k8s.io/minikube/pkg/minikube/cluster" pkg_config "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/machine" + "k8s.io/minikube/pkg/minikube/out" pkgutil "k8s.io/minikube/pkg/util" ) @@ -57,7 +57,7 @@ func runStop(cmd *cobra.Command, args []string) { err = cluster.StopHost(api) switch err := errors.Cause(err).(type) { case mcnerror.ErrHostDoesNotExist: - console.OutT(console.Meh, `"{{.profile_name}}" VM does not exist, nothing to stop`, console.Arg{"profile_name": profile}) + out.T(out.Meh, `"{{.profile_name}}" VM does not exist, nothing to stop`, out.V{"profile_name": profile}) nonexistent = true return nil default: @@ -68,11 +68,11 @@ func runStop(cmd *cobra.Command, args []string) { exit.WithError("Unable to stop VM", err) } if !nonexistent { - console.OutT(console.Stopped, `"{{.profile_name}}" stopped.`, console.Arg{"profile_name": profile}) + out.T(out.Stopped, `"{{.profile_name}}" stopped.`, out.V{"profile_name": profile}) } if err := cmdUtil.KillMountProcess(); err != nil { - console.OutT(console.WarningType, "Unable to kill mount process: {{.error}}", console.Arg{"error": err}) + out.T(out.WarningType, "Unable to kill mount process: {{.error}}", out.V{"error": err}) } machineName := pkg_config.GetMachineName() diff --git a/cmd/minikube/cmd/update-check.go b/cmd/minikube/cmd/update-check.go index fe61530768fb..deaf6cc6ff31 100644 --- a/cmd/minikube/cmd/update-check.go +++ b/cmd/minikube/cmd/update-check.go @@ -18,10 +18,10 @@ package cmd import ( "github.com/spf13/cobra" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/notify" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/version" ) @@ -41,11 +41,11 @@ var updateCheckCmd = &cobra.Command{ } if len(r) < 1 { - exit.WithCode(exit.Data, "Update server returned an empty list") + exit.WithCodeT(exit.Data, "Update server returned an empty list") } - console.OutLn("CurrentVersion: %s", version.GetVersion()) - console.OutLn("LatestVersion: %s", r[0].Name) + out.Ln("CurrentVersion: %s", version.GetVersion()) + out.Ln("LatestVersion: %s", r[0].Name) }, } diff --git a/cmd/minikube/cmd/update-context.go b/cmd/minikube/cmd/update-context.go index d25d8add5d3e..0c71e98412ee 100644 --- a/cmd/minikube/cmd/update-context.go +++ b/cmd/minikube/cmd/update-context.go @@ -20,10 +20,10 @@ import ( "github.com/spf13/cobra" "k8s.io/minikube/pkg/minikube/cluster" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "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/util" ) @@ -49,9 +49,9 @@ var updateContextCmd = &cobra.Command{ exit.WithError("update config", err) } if updated { - console.OutT(console.Celebrate, "{{.machine}} IP has been updated to point at {{.ip}}", console.Arg{"machine": machineName, "ip": ip}) + out.T(out.Celebrate, "{{.machine}} IP has been updated to point at {{.ip}}", out.V{"machine": machineName, "ip": ip}) } else { - console.OutT(console.Meh, "{{.machine}} IP was already correctly configured for {{.ip}}", console.Arg{"machine": machineName, "ip": ip}) + out.T(out.Meh, "{{.machine}} IP was already correctly configured for {{.ip}}", out.V{"machine": machineName, "ip": ip}) } }, diff --git a/cmd/minikube/cmd/version.go b/cmd/minikube/cmd/version.go index 073f95b879dc..9044d183a063 100644 --- a/cmd/minikube/cmd/version.go +++ b/cmd/minikube/cmd/version.go @@ -18,7 +18,7 @@ package cmd import ( "github.com/spf13/cobra" - "k8s.io/minikube/pkg/minikube/console" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/version" ) @@ -31,10 +31,10 @@ var versionCmd = &cobra.Command{ enableUpdateNotification = false }, Run: func(command *cobra.Command, args []string) { - console.OutLn("minikube version: %v", version.GetVersion()) + out.Ln("minikube version: %v", version.GetVersion()) gitCommitID := version.GetGitCommitID() if gitCommitID != "" { - console.OutLn("commit: %v", gitCommitID) + out.Ln("commit: %v", gitCommitID) } }, } diff --git a/cmd/minikube/main.go b/cmd/minikube/main.go index fdc47903b511..28ffb500526e 100644 --- a/cmd/minikube/main.go +++ b/cmd/minikube/main.go @@ -26,9 +26,9 @@ import ( "github.com/golang/glog" "github.com/pkg/profile" "k8s.io/minikube/cmd/minikube/cmd" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/machine" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/translate" _ "k8s.io/minikube/pkg/provision" ) @@ -45,8 +45,8 @@ func main() { if os.Getenv(constants.IsMinikubeChildProcess) == "" { machine.StartDriver() } - console.SetOutFile(os.Stdout) - console.SetErrFile(os.Stderr) + out.SetOutFile(os.Stdout) + out.SetErrFile(os.Stderr) translate.DetermineLocale() cmd.Execute() } diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index d804c0f03503..5bbde1a7a421 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -38,10 +38,10 @@ import ( "k8s.io/minikube/pkg/minikube/bootstrapper" "k8s.io/minikube/pkg/minikube/command" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/cruntime" "k8s.io/minikube/pkg/minikube/machine" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/util" ) @@ -305,7 +305,7 @@ func (k *Bootstrapper) WaitCluster(k8s config.KubernetesConfig) error { // by a CNI plugin which is usually started after minikube has been brought // up. Otherwise, minikube won't start, as "k8s-app" pods are not ready. componentsOnly := k8s.NetworkPlugin == "cni" - console.OutT(console.WaitingPods, "Verifying:") + out.T(out.WaitingPods, "Verifying:") client, err := util.GetClient() if err != nil { return errors.Wrap(err, "k8s client") @@ -313,7 +313,7 @@ func (k *Bootstrapper) WaitCluster(k8s config.KubernetesConfig) error { // Wait until the apiserver can answer queries properly. We don't care if the apiserver // pod shows up as registered, but need the webserver for all subsequent queries. - console.Out(" apiserver") + out.String(" apiserver") if err := k.waitForAPIServer(k8s); err != nil { return errors.Wrap(err, "waiting for apiserver") } @@ -323,13 +323,13 @@ func (k *Bootstrapper) WaitCluster(k8s config.KubernetesConfig) error { continue } - console.Out(" %s", p.name) + out.String(" %s", p.name) selector := labels.SelectorFromSet(labels.Set(map[string]string{p.key: p.value})) if err := util.WaitForPodsWithLabelRunning(client, "kube-system", selector); err != nil { return errors.Wrap(err, fmt.Sprintf("waiting for %s=%s", p.key, p.value)) } } - console.OutLn("") + out.Ln("") return nil } @@ -483,7 +483,7 @@ func (k *Bootstrapper) UpdateCluster(cfg config.KubernetesConfig) error { _, images := constants.GetKubeadmCachedImages(cfg.ImageRepository, cfg.KubernetesVersion) if cfg.ShouldLoadCachedImages { if err := machine.LoadImages(k.c, images, constants.ImageCacheDir); err != nil { - console.FailureT("Unable to load cached images: {{.error}}", console.Arg{"error": err}) + out.FailureT("Unable to load cached images: {{.error}}", out.V{"error": err}) } } r, err := cruntime.New(cruntime.Config{Type: cfg.ContainerRuntime, Socket: cfg.CRISocket}) diff --git a/pkg/minikube/cluster/cluster.go b/pkg/minikube/cluster/cluster.go index d215ff64e119..cdf1b02edc4a 100644 --- a/pkg/minikube/cluster/cluster.go +++ b/pkg/minikube/cluster/cluster.go @@ -42,9 +42,9 @@ import ( "github.com/shirou/gopsutil/mem" "github.com/spf13/viper" cfg "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/exit" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/registry" "k8s.io/minikube/pkg/util" pkgutil "k8s.io/minikube/pkg/util" @@ -101,14 +101,14 @@ func StartHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error) } if h.Driver.DriverName() != config.VMDriver { - console.OutT(console.Empty, "\n") - console.WarningT(`Ignoring --vm-driver={{.driver_name}}, as the existing "{{.profile_name}}" VM was created using the {{.driver_name2}} driver.`, - console.Arg{"driver_name": config.VMDriver, "profile_name": cfg.GetMachineName(), "driver_name2": h.Driver.DriverName()}) - console.WarningT("To switch drivers, you may create a new VM using `minikube start -p --vm-driver={{.driver_name}}`", console.Arg{"driver_name": config.VMDriver}) - console.WarningT("Alternatively, you may delete the existing VM using `minikube delete -p {{.profile_name}}`", console.Arg{"profile_name": cfg.GetMachineName()}) - console.OutT(console.Empty, "\n") + out.T(out.Empty, "\n") + out.WarningT(`Ignoring --vm-driver={{.driver_name}}, as the existing "{{.profile_name}}" VM was created using the {{.driver_name2}} driver.`, + out.V{"driver_name": config.VMDriver, "profile_name": cfg.GetMachineName(), "driver_name2": h.Driver.DriverName()}) + out.WarningT("To switch drivers, you may create a new VM using `minikube start -p --vm-driver={{.driver_name}}`", out.V{"driver_name": config.VMDriver}) + out.WarningT("Alternatively, you may delete the existing VM using `minikube delete -p {{.profile_name}}`", out.V{"profile_name": cfg.GetMachineName()}) + out.T(out.Empty, "\n") } else if exists && cfg.GetMachineName() == constants.DefaultMachineName { - console.OutT(console.Tip, "Tip: Use 'minikube start -p ' to create a new cluster, or 'minikube delete' to delete this one.") + out.T(out.Tip, "Tip: Use 'minikube start -p ' to create a new cluster, or 'minikube delete' to delete this one.") } s, err := h.Driver.GetState() @@ -118,9 +118,9 @@ func StartHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error) } if s == state.Running { - console.OutT(console.Running, `Re-using the currently running {{.driver_name}} VM for "{{.profile_name}}" ...`, console.Arg{"driver_name": h.Driver.DriverName(), "profile_name": cfg.GetMachineName()}) + out.T(out.Running, `Re-using the currently running {{.driver_name}} VM for "{{.profile_name}}" ...`, out.V{"driver_name": h.Driver.DriverName(), "profile_name": cfg.GetMachineName()}) } else { - console.OutT(console.Restarting, `Restarting existing {{.driver_name}} VM for "{{.profile_name}}" ...`, console.Arg{"driver_name": h.Driver.DriverName(), "profile_name": cfg.GetMachineName()}) + out.T(out.Restarting, `Restarting existing {{.driver_name}} VM for "{{.profile_name}}" ...`, out.V{"driver_name": h.Driver.DriverName(), "profile_name": cfg.GetMachineName()}) if err := h.Driver.Start(); err != nil { return nil, errors.Wrap(err, "start") } @@ -151,7 +151,7 @@ func localDriver(name string) bool { func configureHost(h *host.Host, e *engine.Options) error { glog.Infof("configureHost: %T %+v", h, h) // Slightly counter-intuitive, but this is what DetectProvisioner & ConfigureAuth block on. - console.OutT(console.Waiting, "Waiting for SSH access ...", console.Arg{}) + out.T(out.Waiting, "Waiting for SSH access ...", out.V{}) if len(e.Env) > 0 { h.HostOptions.EngineOptions.Env = e.Env @@ -237,7 +237,7 @@ func trySSHPowerOff(h *host.Host) { return } - console.OutT(console.Shutdown, `Powering off "{{.profile_name}}" via SSH ...`, console.Arg{"profile_name": cfg.GetMachineName()}) + out.T(out.Shutdown, `Powering off "{{.profile_name}}" via SSH ...`, out.V{"profile_name": cfg.GetMachineName()}) out, err := h.RunSSHCommand("sudo poweroff") // poweroff always results in an error, since the host disconnects. glog.Infof("poweroff result: out=%s, err=%v", out, err) @@ -249,7 +249,7 @@ func StopHost(api libmachine.API) error { if err != nil { return errors.Wrapf(err, "load") } - console.OutT(console.Stopping, `Stopping "{{.profile_name}}" in {{.driver_name}} ...`, console.Arg{"profile_name": cfg.GetMachineName(), "driver_name": host.DriverName}) + out.T(out.Stopping, `Stopping "{{.profile_name}}" in {{.driver_name}} ...`, out.V{"profile_name": cfg.GetMachineName(), "driver_name": host.DriverName}) if err := host.Stop(); err != nil { alreadyInStateError, ok := err.(mcnerror.ErrHostAlreadyInState) if ok && alreadyInStateError.State == state.Stopped { @@ -271,7 +271,7 @@ func DeleteHost(api libmachine.API) error { trySSHPowerOff(host) } - console.OutT(console.DeletingHost, `Deleting "{{.profile_name}}" in {{.driver_name}} ...`, console.Arg{"profile_name": cfg.GetMachineName(), "driver_name": host.DriverName}) + out.T(out.DeletingHost, `Deleting "{{.profile_name}}" in {{.driver_name}} ...`, out.V{"profile_name": cfg.GetMachineName(), "driver_name": host.DriverName}) if err := host.Driver.Remove(); err != nil { return errors.Wrap(err, "host remove") } @@ -367,17 +367,17 @@ func getHostInfo() (*hostInfo, error) { func createHost(api libmachine.API, config cfg.MachineConfig) (*host.Host, error) { if config.VMDriver == constants.DriverVmwareFusion && viper.GetBool(cfg.ShowDriverDeprecationNotification) { - console.WarningT(`The vmwarefusion driver is deprecated and support for it will be removed in a future release. + out.WarningT(`The vmwarefusion driver is deprecated and support for it will be removed in a future release. Please consider switching to the new vmware unified driver, which is intended to replace the vmwarefusion driver. See https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#vmware-unified-driver for more information. To disable this message, run [minikube config set ShowDriverDeprecationNotification false]`) } if !localDriver(config.VMDriver) { - console.OutT(console.StartingVM, "Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}MB, Disk={{.disk_size}}MB) ...", console.Arg{"driver_name": config.VMDriver, "number_of_cpus": config.CPUs, "memory_size": config.Memory, "disk_size": config.DiskSize}) + out.T(out.StartingVM, "Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"driver_name": config.VMDriver, "number_of_cpus": config.CPUs, "memory_size": config.Memory, "disk_size": config.DiskSize}) } else { info, err := getHostInfo() if err == nil { - console.OutT(console.StartingNone, "Running on localhost (CPUs={{.number_of_cpus}}, Memory={{.memory_size}MB, Disk={{.disk_size}}MB) ...", console.Arg{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize}) + out.T(out.StartingNone, "Running on localhost (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize}) } } diff --git a/pkg/minikube/cruntime/containerd.go b/pkg/minikube/cruntime/containerd.go index 20ec4e27da55..0d88ef1c2863 100644 --- a/pkg/minikube/cruntime/containerd.go +++ b/pkg/minikube/cruntime/containerd.go @@ -21,7 +21,7 @@ import ( "strings" "github.com/golang/glog" - "k8s.io/minikube/pkg/minikube/console" + "k8s.io/minikube/pkg/minikube/out" ) // Containerd contains containerd runtime state @@ -36,8 +36,8 @@ func (r *Containerd) Name() string { } // Style is the console style for containerd -func (r *Containerd) Style() console.StyleEnum { - return console.Containerd +func (r *Containerd) Style() out.StyleEnum { + return out.Containerd } // Version retrieves the current version of this runtime diff --git a/pkg/minikube/cruntime/crio.go b/pkg/minikube/cruntime/crio.go index 67b86fac182d..03711280a817 100644 --- a/pkg/minikube/cruntime/crio.go +++ b/pkg/minikube/cruntime/crio.go @@ -21,7 +21,7 @@ import ( "strings" "github.com/golang/glog" - "k8s.io/minikube/pkg/minikube/console" + "k8s.io/minikube/pkg/minikube/out" ) // CRIO contains CRIO runtime state @@ -36,8 +36,8 @@ func (r *CRIO) Name() string { } // Style is the console style for CRIO -func (r *CRIO) Style() console.StyleEnum { - return console.CRIO +func (r *CRIO) Style() out.StyleEnum { + return out.CRIO } // Version retrieves the current version of this runtime diff --git a/pkg/minikube/cruntime/cruntime.go b/pkg/minikube/cruntime/cruntime.go index 2cb93105325b..645c15c0b4f2 100644 --- a/pkg/minikube/cruntime/cruntime.go +++ b/pkg/minikube/cruntime/cruntime.go @@ -22,7 +22,7 @@ import ( "github.com/golang/glog" "github.com/pkg/errors" - "k8s.io/minikube/pkg/minikube/console" + "k8s.io/minikube/pkg/minikube/out" ) // CommandRunner is the subset of command.Runner this package consumes @@ -46,7 +46,7 @@ type Manager interface { // Available returns an error if it is not possible to use this runtime on a host Available() error // Style is an associated StyleEnum for Name() - Style() console.StyleEnum + Style() out.StyleEnum // KubeletOptions returns kubelet options for a runtime. KubeletOptions() map[string]string diff --git a/pkg/minikube/cruntime/docker.go b/pkg/minikube/cruntime/docker.go index c97368ac034b..709d8e67b5f5 100644 --- a/pkg/minikube/cruntime/docker.go +++ b/pkg/minikube/cruntime/docker.go @@ -22,7 +22,7 @@ import ( "strings" "github.com/golang/glog" - "k8s.io/minikube/pkg/minikube/console" + "k8s.io/minikube/pkg/minikube/out" ) // KubernetesContainerPrefix is the prefix of each kubernetes container @@ -40,8 +40,8 @@ func (r *Docker) Name() string { } // Style is the console style for Docker -func (r *Docker) Style() console.StyleEnum { - return console.Docker +func (r *Docker) Style() out.StyleEnum { + return out.Docker } // Version retrieves the current version of this runtime diff --git a/pkg/minikube/exit/exit.go b/pkg/minikube/exit/exit.go index cac359cb97c5..efe606ddd899 100644 --- a/pkg/minikube/exit/exit.go +++ b/pkg/minikube/exit/exit.go @@ -23,7 +23,7 @@ import ( "runtime" "github.com/golang/glog" - "k8s.io/minikube/pkg/minikube/console" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/problem" "k8s.io/minikube/pkg/minikube/translate" ) @@ -45,29 +45,15 @@ const ( MaxLogEntries = 3 ) -// Usage outputs a usage error and exits with error code 64 -func Usage(format string, a ...interface{}) { - console.ErrStyle(console.Usage, format, a...) - os.Exit(BadUsage) -} - // UsageT outputs a templated usage error and exits with error code 64 -func UsageT(format string, a ...console.Arg) { - console.ErrT(console.Usage, format, a...) +func UsageT(format string, a ...out.V) { + out.ErrT(out.Usage, format, a...) os.Exit(BadUsage) } -// WithCode outputs a fatal error message and exits with a supplied error code. -func WithCode(code int, format string, a ...interface{}) { - // use Warning because Error will display a duplicate message to stderr - glog.Warningf(format, a...) - console.Fatal(format, a...) - os.Exit(code) -} - // WithCodeT outputs a templated fatal error message and exits with the supplied error code. -func WithCodeT(code int, format string, a ...console.Arg) { - console.FatalT(format, a...) +func WithCodeT(code int, format string, a ...out.V) { + out.FatalT(format, a...) os.Exit(code) } @@ -83,12 +69,12 @@ func WithError(msg string, err error) { // WithProblem outputs info related to a known problem and exits. func WithProblem(msg string, p *problem.Problem) { - console.ErrT(console.Empty, "") - console.FatalT(msg) + out.ErrT(out.Empty, "") + out.FatalT(msg) p.Display() - console.ErrT(console.Empty, "") - console.ErrT(console.Sad, "If the above advice does not help, please let us know: ") - console.ErrT(console.URL, "https://github.com/kubernetes/minikube/issues/new/choose") + out.ErrT(out.Empty, "") + out.ErrT(out.Sad, "If the above advice does not help, please let us know: ") + out.ErrT(out.URL, "https://github.com/kubernetes/minikube/issues/new/choose") os.Exit(Config) } @@ -97,12 +83,12 @@ func WithLogEntries(msg string, err error, entries map[string][]string) { displayError(msg, err) for name, lines := range entries { - console.OutT(console.FailureType, "Problems detected in {{.entry}}:", console.Arg{"entry": name}) + out.T(out.FailureType, "Problems detected in {{.entry}}:", out.V{"entry": name}) if len(lines) > MaxLogEntries { lines = lines[:MaxLogEntries] } for _, l := range lines { - console.OutT(console.LogEntry, l) + out.T(out.LogEntry, l) } } os.Exit(Software) @@ -111,9 +97,9 @@ func WithLogEntries(msg string, err error, entries map[string][]string) { func displayError(msg string, err error) { // use Warning because Error will display a duplicate message to stderr glog.Warningf(fmt.Sprintf("%s: %v", msg, err)) - console.ErrT(console.Empty, "") - console.FatalT("{{.msg}}: {{.err}}", console.Arg{"msg": translate.T(msg), "err": err}) - console.ErrT(console.Empty, "") - console.ErrT(console.Sad, "Sorry that minikube crashed. If this was unexpected, we would love to hear from you:") - console.ErrT(console.URL, "https://github.com/kubernetes/minikube/issues/new/choose") + out.ErrT(out.Empty, "") + out.FatalT("{{.msg}}: {{.err}}", out.V{"msg": translate.T(msg), "err": err}) + out.ErrT(out.Empty, "") + out.ErrT(out.Sad, "Sorry that minikube crashed. If this was unexpected, we would love to hear from you:") + out.ErrT(out.URL, "https://github.com/kubernetes/minikube/issues/new/choose") } diff --git a/pkg/minikube/logs/logs.go b/pkg/minikube/logs/logs.go index 2ff70a4c8315..0e382eb87fe6 100644 --- a/pkg/minikube/logs/logs.go +++ b/pkg/minikube/logs/logs.go @@ -29,8 +29,8 @@ import ( "github.com/golang/glog" "k8s.io/minikube/pkg/minikube/bootstrapper" "k8s.io/minikube/pkg/minikube/command" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/cruntime" + "k8s.io/minikube/pkg/minikube/out" ) // rootCauseRe is a regular expression that matches known failure root causes @@ -100,12 +100,12 @@ func FindProblems(r cruntime.Manager, bs bootstrapper.Bootstrapper, runner comma // OutputProblems outputs discovered problems. func OutputProblems(problems map[string][]string, maxLines int) { for name, lines := range problems { - console.OutT(console.FailureType, "Problems detected in {{.name}}:", console.Arg{"name": name}) + out.T(out.FailureType, "Problems detected in {{.name}}:", out.V{"name": name}) if len(lines) > maxLines { lines = lines[len(lines)-maxLines:] } for _, l := range lines { - console.OutT(console.LogEntry, l) + out.T(out.LogEntry, l) } } } @@ -126,9 +126,9 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, runner command.Run failed := []string{} for i, name := range names { if i > 0 { - console.OutT(console.Empty, "") + out.T(out.Empty, "") } - console.OutT(console.Empty, "==> {{.name}} <==", console.Arg{"name": name}) + out.T(out.Empty, "==> {{.name}} <==", out.V{"name": name}) var b bytes.Buffer err := runner.CombinedOutputTo(cmds[name], &b) if err != nil { @@ -138,7 +138,7 @@ func Output(r cruntime.Manager, bs bootstrapper.Bootstrapper, runner command.Run } scanner := bufio.NewScanner(&b) for scanner.Scan() { - console.OutT(console.Empty, scanner.Text()) + out.T(out.Empty, scanner.Text()) } } if len(failed) > 0 { diff --git a/pkg/minikube/machine/cache_binaries.go b/pkg/minikube/machine/cache_binaries.go index d802c162e698..f5f28a26cfe4 100644 --- a/pkg/minikube/machine/cache_binaries.go +++ b/pkg/minikube/machine/cache_binaries.go @@ -29,8 +29,8 @@ import ( "k8s.io/minikube/pkg/minikube/assets" "k8s.io/minikube/pkg/minikube/bootstrapper" "k8s.io/minikube/pkg/minikube/command" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/out" ) // CacheBinariesForBootstrapper will cache binaries for a bootstrapper @@ -78,7 +78,7 @@ func CacheBinary(binary, version, osName, archName string) (string, error) { options.Checksum = constants.GetKubernetesReleaseURLSHA1(binary, version, osName, archName) options.ChecksumHash = crypto.SHA1 - console.OutT(console.FileDownload, "Downloading {{.name}} {{.version}}", console.Arg{"name": binary, "version": version}) + out.T(out.FileDownload, "Downloading {{.name}} {{.version}}", out.V{"name": binary, "version": version}) if err := download.ToFile(url, targetFilepath, options); err != nil { return "", errors.Wrapf(err, "Error downloading %s %s", binary, version) } diff --git a/pkg/minikube/machine/client.go b/pkg/minikube/machine/client.go index 096809962fb0..458dbf9edb6b 100644 --- a/pkg/minikube/machine/client.go +++ b/pkg/minikube/machine/client.go @@ -41,9 +41,9 @@ import ( "github.com/docker/machine/libmachine/version" "github.com/pkg/errors" "k8s.io/minikube/pkg/minikube/command" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/exit" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/registry" "k8s.io/minikube/pkg/minikube/sshutil" "k8s.io/minikube/pkg/provision" @@ -273,7 +273,7 @@ func registerDriver(driverName string) { def, err := registry.Driver(driverName) if err != nil { if err == registry.ErrDriverNotFound { - exit.UsageT("unsupported driver: {{.name}}", console.Arg{"name": driverName}) + exit.UsageT("unsupported driver: {{.name}}", out.V{"name": driverName}) } exit.WithError("error getting driver", err) } diff --git a/pkg/minikube/notify/notify.go b/pkg/minikube/notify/notify.go index bd2006f6edc9..557c364301a9 100644 --- a/pkg/minikube/notify/notify.go +++ b/pkg/minikube/notify/notify.go @@ -30,8 +30,8 @@ import ( "github.com/pkg/errors" "github.com/spf13/viper" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/version" ) @@ -67,8 +67,8 @@ func MaybePrintUpdateText(url string, lastUpdatePath string) { glog.Errorf("write time failed: %v", err) } url := fmt.Sprintf("%s/%s", updateLinkPrefix, latestVersion) - console.ErrT(console.WarningType, `minikube {{.version}} is available! Download it: {{.url}}`, console.Arg{"version": latestVersion, "url": url}) - console.OutT(console.Tip, "To disable this notice, run: 'minikube config set WantUpdateNotification false'") + out.ErrT(out.WarningType, `minikube {{.version}} is available! Download it: {{.url}}`, out.V{"version": latestVersion, "url": url}) + out.T(out.Tip, "To disable this notice, run: 'minikube config set WantUpdateNotification false'") } } diff --git a/pkg/minikube/notify/notify_test.go b/pkg/minikube/notify/notify_test.go index e78f6bf7b30a..c87c2de37208 100644 --- a/pkg/minikube/notify/notify_test.go +++ b/pkg/minikube/notify/notify_test.go @@ -29,7 +29,7 @@ import ( "github.com/blang/semver" "github.com/spf13/viper" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/tests" "k8s.io/minikube/pkg/version" ) @@ -151,7 +151,7 @@ func TestMaybePrintUpdateText(t *testing.T) { viper.Set(config.ReminderWaitPeriodInHours, 24) outputBuffer := tests.NewFakeFile() - console.SetErrFile(outputBuffer) + out.SetErrFile(outputBuffer) lastUpdateCheckFilePath := filepath.Join(tempDir, "last_update_check") // test that no update text is printed if the latest version is lower/equal to the current version diff --git a/pkg/minikube/console/console.go b/pkg/minikube/out/out.go similarity index 66% rename from pkg/minikube/console/console.go rename to pkg/minikube/out/out.go index f753afbdff0e..d053a803df07 100644 --- a/pkg/minikube/console/console.go +++ b/pkg/minikube/out/out.go @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package console provides a mechanism for sending localized, stylized output to the console. -package console +// Package out provides a mechanism for sending localized, stylized output to the console. +package out import ( "fmt" @@ -31,12 +31,12 @@ import ( // By design, this package uses global references to language and output objects, in preference // to passing a console object throughout the code base. Typical usage is: // -// console.SetOutFile(os.Stdout) -// console.Out("Starting up!") -// console.OutStyle(console.StatusChange, "Configuring things") +// out.SetOutFile(os.Stdout) +// out.String("Starting up!") +// out.T(out.StatusChange, "Configuring things") -// console.SetErrFile(os.Stderr) -// console.Fatal("Oh no, everything failed.") +// out.SetErrFile(os.Stderr) +// out.Fatal("Oh no, everything failed.") // NOTE: If you do not want colorized output, set MINIKUBE_IN_STYLE=false in your environment. @@ -57,23 +57,17 @@ type fdWriter interface { Fd() uintptr } -// Arg is a convenience wrapper for templating -type Arg map[string]interface{} +// V is a convenience wrapper for templating, it represents the variable key/value pair. +type V map[string]interface{} -// OutStyle writes a stylized and formatted message to stdout -func OutStyle(style StyleEnum, format string, a ...interface{}) { - outStyled := applyStyle(style, useColor, format) - Out(outStyled, a...) -} - -// OutT writes a stylized and templated message to stdout -func OutT(style StyleEnum, format string, a ...Arg) { +// T writes a stylized and templated message to stdout +func T(style StyleEnum, format string, a ...V) { outStyled := applyTemplateFormatting(style, useColor, format, a...) - Out(outStyled) + String(outStyled) } -// Out writes a basic formatted string to stdout -func Out(format string, a ...interface{}) { +// String writes a basic formatted string to stdout +func String(format string, a ...interface{}) { if outFile == nil { glog.Warningf("[unset outFile]: %s", fmt.Sprintf(format, a...)) return @@ -84,19 +78,13 @@ func Out(format string, a ...interface{}) { } } -// OutLn writes a basic formatted string with a newline to stdout -func OutLn(format string, a ...interface{}) { - Out(format+"\n", a...) -} - -// ErrStyle writes a stylized and formatted error message to stderr -func ErrStyle(style StyleEnum, format string, a ...interface{}) { - errStyled := applyStyle(style, useColor, format) - Err(errStyled, a...) +// Ln writes a basic formatted string with a newline to stdout +func Ln(format string, a ...interface{}) { + String(format+"\n", a...) } // ErrT writes a stylized and templated error message to stderr -func ErrT(style StyleEnum, format string, a ...Arg) { +func ErrT(style StyleEnum, format string, a ...V) { errStyled := applyTemplateFormatting(style, useColor, format, a...) Err(errStyled) } @@ -118,43 +106,23 @@ func ErrLn(format string, a ...interface{}) { Err(format+"\n", a...) } -// Success is a shortcut for writing a styled success message to stdout -func Success(format string, a ...interface{}) { - OutStyle(SuccessType, format, a...) -} - -// Fatal is a shortcut for writing a styled fatal message to stderr -func Fatal(format string, a ...interface{}) { - ErrStyle(FatalType, format, a...) -} - -// Warning is a shortcut for writing a styled warning message to stderr -func Warning(format string, a ...interface{}) { - ErrStyle(WarningType, format, a...) -} - -// Failure is a shortcut for writing a styled failure message to stderr -func Failure(format string, a ...interface{}) { - ErrStyle(FailureType, format, a...) -} - // SuccessT is a shortcut for writing a templated success message to stdout -func SuccessT(format string, a ...Arg) { - OutT(SuccessType, format, a...) +func SuccessT(format string, a ...V) { + T(SuccessType, format, a...) } // FatalT is a shortcut for writing a templated fatal message to stderr -func FatalT(format string, a ...Arg) { +func FatalT(format string, a ...V) { ErrT(FatalType, format, a...) } // WarningT is a shortcut for writing a templated warning message to stderr -func WarningT(format string, a ...Arg) { +func WarningT(format string, a ...V) { ErrT(WarningType, format, a...) } // FailureT is a shortcut for writing a templated failure message to stderr -func FailureT(format string, a ...Arg) { +func FailureT(format string, a ...V) { ErrT(FailureType, format, a...) } diff --git a/pkg/minikube/console/console_test.go b/pkg/minikube/out/out_test.go similarity index 51% rename from pkg/minikube/console/console_test.go rename to pkg/minikube/out/out_test.go index 7eb1759bda10..79646c5de489 100644 --- a/pkg/minikube/console/console_test.go +++ b/pkg/minikube/out/out_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package console +package out import ( "fmt" @@ -26,52 +26,6 @@ import ( "k8s.io/minikube/pkg/minikube/translate" ) -func TestOutStyle(t *testing.T) { - // Set the system locale to Arabic and define a dummy translation file. - if err := translate.SetPreferredLanguage("ar"); err != nil { - t.Fatalf("SetPreferredLanguage: %v", err) - } - translate.Translations = map[string]interface{}{ - "Installing Kubernetes version %s ...": "... %s تثبيت Kubernetes الإصدار", - } - - var testCases = []struct { - style StyleEnum - message string - params []interface{} - want string - wantASCII string - }{ - {Happy, "Happy", nil, "😄 Happy\n", "* Happy\n"}, - {Option, "Option", nil, " ▪ Option\n", " - Option\n"}, - {WarningType, "Warning", nil, "⚠️ Warning\n", "! Warning\n"}, - {FatalType, "Fatal: %v", []interface{}{"ugh"}, "💣 Fatal: ugh\n", "X Fatal: ugh\n"}, - {WaitingPods, "wait", nil, "⌛ wait", "* wait"}, - {Issue, "http://i/%d", []interface{}{10000}, " ▪ http://i/10000\n", " - http://i/10000\n"}, - {Usage, "raw: %s %s", []interface{}{"'%'", "%d"}, "💡 raw: '%' %d\n", "* raw: '%' %d\n"}, - {Running, "Installing Kubernetes version %s ...", []interface{}{"v1.13"}, "🏃 ... v1.13 تثبيت Kubernetes الإصدار\n", "* ... v1.13 تثبيت Kubernetes الإصدار\n"}, - } - for _, tc := range testCases { - for _, override := range []bool{true, false} { - t.Run(fmt.Sprintf("%s-override-%v", tc.message, override), func(t *testing.T) { - // Set MINIKUBE_IN_STYLE= - os.Setenv(OverrideEnv, strconv.FormatBool(override)) - f := tests.NewFakeFile() - SetOutFile(f) - OutStyle(tc.style, tc.message, tc.params...) - got := f.String() - want := tc.wantASCII - if override { - want = tc.want - } - if got != want { - t.Errorf("OutStyle() = %q (%d runes), want %q (%d runes)", got, len(got), want, len(want)) - } - }) - } - } -} - func TestOutT(t *testing.T) { // Set the system locale to Arabic and define a dummy translation file. if err := translate.SetPreferredLanguage("ar"); err != nil { @@ -84,18 +38,18 @@ func TestOutT(t *testing.T) { var testCases = []struct { style StyleEnum message string - params Arg + params V want string wantASCII string }{ {Happy, "Happy", nil, "😄 Happy\n", "* Happy\n"}, {Option, "Option", nil, " ▪ Option\n", " - Option\n"}, {WarningType, "Warning", nil, "⚠️ Warning\n", "! Warning\n"}, - {FatalType, "Fatal: {{.error}}", Arg{"error": "ugh"}, "💣 Fatal: ugh\n", "X Fatal: ugh\n"}, + {FatalType, "Fatal: {{.error}}", V{"error": "ugh"}, "💣 Fatal: ugh\n", "X Fatal: ugh\n"}, {WaitingPods, "wait", nil, "⌛ wait", "* wait"}, - {Issue, "http://i/{{.number}}", Arg{"number": 10000}, " ▪ http://i/10000\n", " - http://i/10000\n"}, - {Usage, "raw: {{.one}} {{.two}}", Arg{"one": "'%'", "two": "%d"}, "💡 raw: '%' %d\n", "* raw: '%' %d\n"}, - {Running, "Installing Kubernetes version {{.version}} ...", Arg{"version": "v1.13"}, "🏃 ... v1.13 تثبيت Kubernetes الإصدار\n", "* ... v1.13 تثبيت Kubernetes الإصدار\n"}, + {Issue, "http://i/{{.number}}", V{"number": 10000}, " ▪ http://i/10000\n", " - http://i/10000\n"}, + {Usage, "raw: {{.one}} {{.two}}", V{"one": "'%'", "two": "%d"}, "💡 raw: '%' %d\n", "* raw: '%' %d\n"}, + {Running, "Installing Kubernetes version {{.version}} ...", V{"version": "v1.13"}, "🏃 ... v1.13 تثبيت Kubernetes الإصدار\n", "* ... v1.13 تثبيت Kubernetes الإصدار\n"}, } for _, tc := range testCases { for _, override := range []bool{true, false} { @@ -104,7 +58,7 @@ func TestOutT(t *testing.T) { os.Setenv(OverrideEnv, strconv.FormatBool(override)) f := tests.NewFakeFile() SetOutFile(f) - OutT(tc.style, tc.message, tc.params) + T(tc.style, tc.message, tc.params) got := f.String() want := tc.wantASCII if override { @@ -136,9 +90,9 @@ func TestOut(t *testing.T) { SetOutFile(f) ErrLn("unrelated message") if tc.arg == nil { - Out(tc.format) + String(tc.format) } else { - Out(tc.format, tc.arg) + String(tc.format, tc.arg) } got := f.String() if got != tc.want { @@ -153,7 +107,7 @@ func TestErr(t *testing.T) { f := tests.NewFakeFile() SetErrFile(f) Err("xyz123 %s\n", "%s%%%d") - OutLn("unrelated message") + Ln("unrelated message") got := f.String() want := "xyz123 %s%%%d\n" @@ -161,15 +115,3 @@ func TestErr(t *testing.T) { t.Errorf("Err() = %q, want %q", got, want) } } - -func TestErrStyle(t *testing.T) { - os.Setenv(OverrideEnv, "1") - f := tests.NewFakeFile() - SetErrFile(f) - ErrStyle(FatalType, "error: %s", "%s%%%d") - got := f.String() - want := "💣 error: %s%%%d\n" - if got != want { - t.Errorf("ErrStyle() = %q, want %q", got, want) - } -} diff --git a/pkg/minikube/console/style.go b/pkg/minikube/out/style.go similarity index 98% rename from pkg/minikube/console/style.go rename to pkg/minikube/out/style.go index a596240d2b42..6b64f3dcc364 100644 --- a/pkg/minikube/console/style.go +++ b/pkg/minikube/out/style.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package console +package out import ( "bytes" @@ -153,9 +153,9 @@ func applyStyle(style StyleEnum, useColor bool, format string) string { return applyPrefix(s.Prefix, format) } -func applyTemplateFormatting(style StyleEnum, useColor bool, format string, a ...Arg) string { +func applyTemplateFormatting(style StyleEnum, useColor bool, format string, a ...V) string { if a == nil { - a = []Arg{Arg{}} + a = []V{V{}} } format = applyStyle(style, useColor, format) diff --git a/pkg/minikube/console/style_enum.go b/pkg/minikube/out/style_enum.go similarity index 98% rename from pkg/minikube/console/style_enum.go rename to pkg/minikube/out/style_enum.go index b1b6b16a3990..aee851fda082 100644 --- a/pkg/minikube/console/style_enum.go +++ b/pkg/minikube/out/style_enum.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package console +package out // StyleEnum is an enumeration of Style type StyleEnum int diff --git a/pkg/minikube/problem/problem.go b/pkg/minikube/problem/problem.go index 3f0db8d93391..c4e2660f1147 100644 --- a/pkg/minikube/problem/problem.go +++ b/pkg/minikube/problem/problem.go @@ -21,7 +21,7 @@ import ( "fmt" "regexp" - "k8s.io/minikube/pkg/minikube/console" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/translate" ) @@ -53,21 +53,21 @@ type match struct { // Display problem metadata to the console func (p *Problem) Display() { - console.ErrT(console.FailureType, "Error: [{{.id}}] {{.error}}", console.Arg{"id": p.ID, "error": p.Err}) - console.ErrT(console.Tip, "Suggestion: {{.advice}}", console.Arg{"advice": translate.T(p.Advice)}) + out.ErrT(out.FailureType, "Error: [{{.id}}] {{.error}}", out.V{"id": p.ID, "error": p.Err}) + out.ErrT(out.Tip, "Suggestion: {{.advice}}", out.V{"advice": translate.T(p.Advice)}) if p.URL != "" { - console.ErrT(console.Documentation, "Documentation: {{.url}}", console.Arg{"url": p.URL}) + out.ErrT(out.Documentation, "Documentation: {{.url}}", out.V{"url": p.URL}) } if len(p.Issues) == 0 { return } - console.ErrT(console.Issues, "Related issues:") + out.ErrT(out.Issues, "Related issues:") issues := p.Issues if len(issues) > 3 { issues = issues[0:3] } for _, i := range issues { - console.ErrT(console.Issue, "{{.url}}", console.Arg{"url": fmt.Sprintf("%s/%d", issueBase, i)}) + out.ErrT(out.Issue, "{{.url}}", out.V{"url": fmt.Sprintf("%s/%d", issueBase, i)}) } } diff --git a/pkg/minikube/service/service.go b/pkg/minikube/service/service.go index 196b08374d1f..4a22e8c293ef 100644 --- a/pkg/minikube/service/service.go +++ b/pkg/minikube/service/service.go @@ -41,8 +41,8 @@ import ( clientcmdapi "k8s.io/client-go/tools/clientcmd/api" "k8s.io/minikube/pkg/minikube/cluster" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/out" "k8s.io/minikube/pkg/minikube/proxy" "k8s.io/minikube/pkg/util" ) @@ -284,7 +284,7 @@ func WaitAndMaybeOpenService(api libmachine.API, namespace string, service strin } if len(urls) == 0 { - console.OutT(console.Sad, "service {{.namespace_name}}/{{.service_name}} has no node port", console.Arg{"namespace_name": namespace, "service_name": service}) + out.T(out.Sad, "service {{.namespace_name}}/{{.service_name}} has no node port", out.V{"namespace_name": namespace, "service_name": service}) return nil } @@ -292,11 +292,11 @@ func WaitAndMaybeOpenService(api libmachine.API, namespace string, service strin urlString, isHTTPSchemedURL := OptionallyHTTPSFormattedURLString(bareURLString, https) if urlMode || !isHTTPSchemedURL { - console.OutT(console.Empty, urlString) + out.T(out.Empty, urlString) } else { - console.OutT(console.Celebrate, "Opening kubernetes service {{.namespace_name}}/{{.service_name}} in default browser...", console.Arg{"namespace_name": namespace, "service_name": service}) + out.T(out.Celebrate, "Opening kubernetes service {{.namespace_name}}/{{.service_name}} in default browser...", out.V{"namespace_name": namespace, "service_name": service}) if err := browser.OpenURL(urlString); err != nil { - console.ErrT(console.Empty, "browser failed to open url: {{.error}}", console.Arg{"error": err}) + out.ErrT(out.Empty, "browser failed to open url: {{.error}}", out.V{"error": err}) } } } diff --git a/pkg/util/downloader.go b/pkg/util/downloader.go index da84a03424b8..03b130a56db6 100644 --- a/pkg/util/downloader.go +++ b/pkg/util/downloader.go @@ -25,8 +25,8 @@ import ( "github.com/golang/glog" download "github.com/jimmidyson/go-download" "github.com/pkg/errors" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/out" ) const fileScheme = "file" @@ -76,7 +76,7 @@ func (f DefaultDownloader) CacheMinikubeISOFromURL(isoURL string) error { options.ChecksumHash = crypto.SHA256 } - console.OutStyle(console.ISODownload, "Downloading Minikube ISO ...") + out.T(out.ISODownload, "Downloading Minikube ISO ...") if err := download.ToFile(isoURL, f.GetISOCacheFilepath(isoURL), options); err != nil { return errors.Wrap(err, isoURL) } diff --git a/pkg/util/utils.go b/pkg/util/utils.go index c7fa0e7c5282..7fdb2bf217dd 100644 --- a/pkg/util/utils.go +++ b/pkg/util/utils.go @@ -31,8 +31,8 @@ import ( units "github.com/docker/go-units" "github.com/golang/glog" "github.com/pkg/errors" - "k8s.io/minikube/pkg/minikube/console" "k8s.io/minikube/pkg/minikube/exit" + "k8s.io/minikube/pkg/minikube/out" ) // ErrPrefix notes an error @@ -60,7 +60,7 @@ func CalculateSizeInMB(humanReadableSize string) int { } size, err := units.FromHumanSize(humanReadableSize) if err != nil { - exit.WithCodeT(exit.Config, "Invalid size passed in argument: {{.error}}", console.Arg{"error": err}) + exit.WithCodeT(exit.Config, "Invalid size passed in argument: {{.error}}", out.V{"error": err}) } return int(size / units.MB) diff --git a/translations/fr-FR.json b/translations/fr-FR.json index 999a0221e429..aac753e008e4 100644 --- a/translations/fr-FR.json +++ b/translations/fr-FR.json @@ -21,7 +21,7 @@ "Configuring local host environment ...": "", "Creating %s VM (CPUs=%d, Memory=%dMB, Disk=%dMB) ...": "Créant un VM %s (CPUs=%d, Mémoire=%dMB, Disque=%dMB)", "Creating mount {{.name}} ...": "", - "Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}MB, Disk={{.disk_size}}MB) ...": "", + "Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...": "", "Deleting \"{{.profile_name}}\" in {{.driver_name}} ...": "", "Disable Hyper-V when you want to run VirtualBox to boot the VM": "", "Disable dynamic memory in your VM manager, or pass in a larger --memory value": "", @@ -68,7 +68,7 @@ "Error opening service": "", "Error parsing minukube version: {{.error}}": "", "Error parsing vmDriver version: {{.error}}": "", - "Error reading %s: %v": "", + "Error reading {{.path}}: {{.error}}": "", "Error restarting cluster": "", "Error setting shell variables": "", "Error starting cluster": "", @@ -165,7 +165,7 @@ "Run 'minikube delete'. If the problem persists, check your proxy or firewall configuration": "", "Run 'sudo modprobe vboxdrv' and reinstall VirtualBox if it fails.": "", "Run minikube from the C: drive.": "", - "Running on localhost (CPUs={{.number_of_cpus}}, Memory={{.memory_size}MB, Disk={{.disk_size}}MB) ...": "", + "Running on localhost (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...": "", "Set failed": "", "Setting profile failed": "", "Skipped switching kubectl context for {{.profile_name}} , because --keep-context": "", diff --git a/translations/zh-CN.json b/translations/zh-CN.json index 35c6a4ea21ff..b9a194609b04 100644 --- a/translations/zh-CN.json +++ b/translations/zh-CN.json @@ -21,7 +21,7 @@ "Configuring local host environment ...": "", "Creating %s VM (CPUs=%d, Memory=%dMB, Disk=%dMB) ...": "正在创建%s虚拟机(CPU=%d,内存=%dMB,磁盘=%dMB)...", "Creating mount {{.name}} ...": "", - "Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}MB, Disk={{.disk_size}}MB) ...": "", + "Creating {{.driver_name}} VM (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...": "", "Deleting \"{{.profile_name}}\" in {{.driver_name}} ...": "", "Disable Hyper-V when you want to run VirtualBox to boot the VM": "", "Disable dynamic memory in your VM manager, or pass in a larger --memory value": "", @@ -68,7 +68,7 @@ "Error opening service": "", "Error parsing minukube version: {{.error}}": "", "Error parsing vmDriver version: {{.error}}": "", - "Error reading %s: %v": "", + "Error reading {{.path}}: {{.error}}": "", "Error restarting cluster": "", "Error setting shell variables": "", "Error starting cluster": "", @@ -165,7 +165,7 @@ "Run 'minikube delete'. If the problem persists, check your proxy or firewall configuration": "", "Run 'sudo modprobe vboxdrv' and reinstall VirtualBox if it fails.": "", "Run minikube from the C: drive.": "", - "Running on localhost (CPUs={{.number_of_cpus}}, Memory={{.memory_size}MB, Disk={{.disk_size}}MB) ...": "", + "Running on localhost (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...": "", "Set failed": "", "Setting profile failed": "", "Skipped switching kubectl context for {{.profile_name}} , because --keep-context": "",