Console output cleanup (#4825)

* Console output cleanup

* comment fix

* Fixing out.Out stutter

* Fix invalid template

* Change profile_list.go to new console functions

* more merge stuff
pull/4674/head^2
Sharif Elgamal 2019-07-19 17:00:51 -07:00 committed by GitHub
parent 784717c007
commit 6552436311
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 312 additions and 416 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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})
},
}

View File

@ -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})
},
}

View File

@ -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})
},
}

View File

@ -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
},
}

View File

@ -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})
}
}
},

View File

@ -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})
},
}

View File

@ -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))
}
},
}

View File

@ -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

View File

@ -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 {

View File

@ -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 {

View File

@ -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)
}

View File

@ -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
}

View File

@ -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})
}
}

View File

@ -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})
}
}

View File

@ -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

View File

@ -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)
},
}

View File

@ -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"

View File

@ -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 <source directory>:<target directory> (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: <source directory>:<target directory>`, console.Arg{"value": mountString})
exit.UsageT(`mount argument "{{.value}}" must be in form: <source directory>:<target directory>`, 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()
},
}

View File

@ -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]

View File

@ -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)
}

View File

@ -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"))
},
}

View File

@ -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)
}

View File

@ -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})
}
}
}

View File

@ -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()

View File

@ -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()

View File

@ -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)
},
}

View File

@ -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})
}
},

View File

@ -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)
}
},
}

View File

@ -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()
}

View File

@ -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})

View File

@ -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 <name> --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 <name> --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 <name>' to create a new cluster, or 'minikube delete' to delete this one.")
out.T(out.Tip, "Tip: Use 'minikube start -p <name>' 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})
}
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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")
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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'")
}
}

View File

@ -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

View File

@ -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...)
}

View File

@ -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=<override>
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)
}
}

View File

@ -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)

View File

@ -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

View File

@ -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)})
}
}

View File

@ -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})
}
}
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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": "",

View File

@ -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": "",