未验证 提交 61f14767 编写于 作者: T Thomas Strömberg 提交者: GitHub

Merge pull request #4800 from sharifelgamal/TEMPLATES

Templatizing more calls to console
......@@ -109,7 +109,7 @@ var addonsConfigureCmd = &cobra.Command{
})
if err != nil {
console.Failure("ERROR creating `registry-creds-ecr` secret: %v", err)
console.FailureT("ERROR creating `registry-creds-ecr` secret: {{.error}}", console.Arg{"error": err})
}
// Create GCR Secret
......@@ -127,7 +127,7 @@ var addonsConfigureCmd = &cobra.Command{
})
if err != nil {
console.Failure("ERROR creating `registry-creds-gcr` secret: %v", err)
console.FailureT("ERROR creating `registry-creds-gcr` secret: {{.error}}", console.Arg{"error": err})
}
// Create Docker Secret
......@@ -146,14 +146,14 @@ var addonsConfigureCmd = &cobra.Command{
})
if err != nil {
console.Warning("ERROR creating `registry-creds-dpr` secret")
console.WarningT("ERROR creating `registry-creds-dpr` secret")
}
default:
console.Failure("%s has no available configuration options", addon)
console.FailureT("{{.name}} has no available configuration options", console.Arg{"name": addon})
return
}
console.Success("%s was successfully configured", addon)
console.SuccessT("{{.name}} was successfully configured", console.Arg{"name": addon})
},
}
......
......@@ -17,7 +17,6 @@ limitations under the License.
package config
import (
"os"
"text/template"
"github.com/spf13/cobra"
......@@ -48,13 +47,13 @@ var addonsOpenCmd = &cobra.Command{
PreRun: func(cmd *cobra.Command, args []string) {
t, err := template.New("addonsURL").Parse(addonsURLFormat)
if err != nil {
exit.Usage("The value passed to --format is invalid: %s", err)
exit.UsageT("The value passed to --format is invalid: {{.error}}", console.Arg{"error": err})
}
addonsURLTemplate = t
},
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
exit.Usage("usage: minikube addons open ADDON_NAME")
exit.UsageT("usage: minikube addons open ADDON_NAME")
}
addonName := args[0]
// TODO(r2d4): config should not reference API, pull this out
......@@ -67,19 +66,18 @@ var addonsOpenCmd = &cobra.Command{
cluster.EnsureMinikubeRunningOrExit(api, 1)
addon, ok := assets.Addons[addonName] // validate addon input
if !ok {
exit.WithCode(exit.Data, `addon '%s' is not a valid addon packaged with minikube.
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`, addonName)
minikube addons list`, console.Arg{"name": addonName})
}
ok, err = addon.IsEnabled()
if err != nil {
exit.WithError("IsEnabled failed", err)
}
if !ok {
console.ErrStyle(console.Conflict, `addon '%s' is currently not enabled.
exit.WithCodeT(exit.Unavailable, `addon '{{.name}}' is currently not enabled.
To enable this addon run:
minikube addons enable %s`, addonName, addonName)
os.Exit(exit.Unavailable)
minikube addons enable {{.name}}`, console.Arg{"name": addonName})
}
namespace := "kube-system"
......@@ -87,16 +85,16 @@ minikube addons enable %s`, addonName, addonName)
serviceList, err := service.GetServiceListByLabel(namespace, key, addonName)
if err != nil {
exit.WithCode(exit.Unavailable, "Error getting service with namespace: %s and labels %s:%s: %v", namespace, key, addonName, err)
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})
}
if len(serviceList.Items) == 0 {
exit.WithCode(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 %s:%s`, key, addonName)
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})
}
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.WithCode(exit.Unavailable, "Wait failed: %v", err)
exit.WithCodeT(exit.Unavailable, "Wait failed: {{.error}}", console.Arg{"error": err})
}
}
},
......
......@@ -28,6 +28,7 @@ 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"
......@@ -61,7 +62,7 @@ var statusCmd = &cobra.Command{
var returnCode = 0
api, err := machine.NewAPIClient()
if err != nil {
exit.WithCode(exit.Unavailable, "Error getting client: %v", err)
exit.WithCodeT(exit.Unavailable, "Error getting client: {{.error}}", console.Arg{"error": err})
}
defer api.Close()
......
......@@ -49,9 +49,9 @@ var updateContextCmd = &cobra.Command{
exit.WithError("update config", err)
}
if updated {
console.OutStyle(console.Celebrate, "%s IP has been updated to point at %s", machineName, ip)
console.OutT(console.Celebrate, "{{.machine}} IP has been updated to point at {{.ip}}", console.Arg{"machine": machineName, "ip": ip})
} else {
console.OutStyle(console.Meh, "%s IP was already correctly configured for %s", machineName, ip)
console.OutT(console.Meh, "{{.machine}} IP was already correctly configured for {{.ip}}", console.Arg{"machine": machineName, "ip": ip})
}
},
......
......@@ -79,6 +79,7 @@ var styles = map[StyleEnum]style{
Issue: {Prefix: " ▪ ", LowPrefix: lowIndent}, // Indented bullet
Check: {Prefix: "✔️ "},
Celebration: {Prefix: "🎉 "},
Empty: {Prefix: ""},
// Specialized purpose styles
ISODownload: {Prefix: "💿 "},
......
......@@ -80,4 +80,5 @@ const (
Unmount
MountOptions
Fileserver
Empty
)
......@@ -83,10 +83,10 @@ func WithError(msg string, err error) {
// WithProblem outputs info related to a known problem and exits.
func WithProblem(msg string, p *problem.Problem) {
console.Err("\n")
console.ErrT(console.Empty, "")
console.FatalT(msg)
p.Display()
console.Err("\n")
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")
os.Exit(Config)
......@@ -111,9 +111,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.Err("\n")
console.ErrT(console.Empty, "")
console.FatalT("{{.msg}}: {{.err}}", console.Arg{"msg": translate.T(msg), "err": err})
console.Err("\n")
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")
}
......@@ -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.OutStyle(console.FailureType, "Problems detected in %q:", name)
console.OutT(console.FailureType, "Problems detected in {{.name}}:", console.Arg{"name": name})
if len(lines) > maxLines {
lines = lines[len(lines)-maxLines:]
}
for _, l := range lines {
console.OutStyle(console.LogEntry, l)
console.OutT(console.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.OutLn("")
console.OutT(console.Empty, "")
}
console.OutLn("==> %s <==", name)
console.OutT(console.Empty, "==> {{.name}} <==", console.Arg{"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.OutLn(scanner.Text())
console.OutT(console.Empty, scanner.Text())
}
}
if len(failed) > 0 {
......
......@@ -34,6 +34,7 @@ import (
"github.com/golang/glog"
retryablehttp "github.com/hashicorp/go-retryablehttp"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/console"
"k8s.io/minikube/pkg/minikube/exit"
)
......@@ -62,7 +63,7 @@ func CalculateSizeInMB(humanReadableSize string) int {
}
size, err := units.FromHumanSize(humanReadableSize)
if err != nil {
exit.WithCode(exit.Config, "Invalid size passed in argument: %v", err)
exit.WithCodeT(exit.Config, "Invalid size passed in argument: {{.error}}", console.Arg{"error": err})
}
return int(size / units.MB)
......
......@@ -4,14 +4,11 @@
"%q host does not exist, unable to show an IP": "",
"%q profile does not exist": "",
"%q stopped.": "",
"%s IP has been updated to point at %s": "",
"%s IP was already correctly configured for %s": "",
"%s has no available configuration options": "",
"%s was successfully configured": "",
"%s was successfully disabled": "",
"'none' driver does not support 'minikube docker-env' command": "",
"'none' driver does not support 'minikube mount' command": "",
"'none' driver does not support 'minikube ssh' command": "",
"==\u003e {{.name}} \u003c==": "",
"A firewall is blocking Docker within the minikube VM from reaching the internet. You may need to configure it to use a proxy.": "",
"A firewall is interfering with minikube's ability to make outgoing HTTPS requests. You may need to change the value of the HTTPS_PROXY environment variable.": "",
"A firewall is likely blocking minikube from reaching the internet. You may need to configure minikube to use a proxy.": "",
......@@ -35,8 +32,8 @@
"Downloading Minikube ISO ...": "",
"Downloading {{.name}} {{.version}}": "",
"ERROR creating `registry-creds-dpr` secret": "",
"ERROR creating `registry-creds-ecr` secret: %v": "",
"ERROR creating `registry-creds-gcr` secret: %v": "",
"ERROR creating `registry-creds-ecr` secret: {{.error}}": "",
"ERROR creating `registry-creds-gcr` secret: {{.error}}": "",
"Enabling dashboard ...": "",
"Error checking driver version: %v": "",
"Error creating list template": "",
......@@ -51,7 +48,7 @@
"Error getting IP": "",
"Error getting bootstrapper": "",
"Error getting client": "",
"Error getting client: %v": "",
"Error getting client: {{.error}}": "",
"Error getting cluster": "",
"Error getting cluster bootstrapper": "",
"Error getting config": "",
......@@ -60,7 +57,7 @@
"Error getting machine logs": "",
"Error getting machine status": "",
"Error getting service status": "",
"Error getting service with namespace: %s and labels %s:%s: %v": "",
"Error getting service with namespace: {{.namespace}} and labels {{.labelName}}:{{.addonName}}: {{.error}}": "",
"Error getting the host IP address to use from within the VM": "",
"Error host driver ip status": "",
"Error killing mount process": "",
......@@ -119,7 +116,7 @@
"Install VirtualBox, ensure that VBoxManage is executable and in path, or select an alternative value for --vm-driver": "",
"Install the latest kvm2 driver and run 'virt-host-validate'": "",
"Install the latest minikube hyperkit driver, and run 'minikube delete'": "",
"Invalid size passed in argument: %v": "",
"Invalid size passed in argument: {{.error}}": "",
"IsEnabled failed": "",
"Kubernetes downgrade is not supported, will continue to use {{.version}}": "",
"Launching Kubernetes ... ": "Lançant Kubernetes ...",
......@@ -144,8 +141,8 @@
"Please specify the directory to be mounted: \n\tminikube mount \u003csource directory\u003e:\u003ctarget directory\u003e (example: \"/host-home:/vm-home\")": "",
"Please upgrade the 'docker-machine-driver-kvm2'. %s": "",
"Powering off %q via SSH ...": "",
"Problems detected in %q:": "",
"Problems detected in {{.entry}}:": "",
"Problems detected in {{.name}}:": "",
"Pulling images ...": "Extrayant les images ... ",
"Re-run 'minikube start' with --alsologtostderr -v=8 to see the VM driver error message": "",
"Re-using the currently running %s VM for %q ...": "",
......@@ -186,10 +183,10 @@
"The docker service is currently not active": "",
"The minikube VM is offline. Please run 'minikube start' to start it again.": "",
"The value passed to --format is invalid": "",
"The value passed to --format is invalid: %s": "",
"The value passed to --format is invalid: {{.error}}": "",
"The vmwarefusion driver is deprecated and support for it will be removed in a future release.\n\t\t\tPlease consider switching to the new vmware unified driver, which is intended to replace the vmwarefusion driver.\n\t\t\tSee https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#vmware-unified-driver for more information.\n\t\t\tTo disable this message, run [minikube config set ShowDriverDeprecationNotification false]": "",
"These changes will take effect upon a minikube delete and then a minikube start": "",
"This addon does not have an endpoint defined for the 'addons open' command.\nYou can add one by annotating a service with the label %s:%s": "",
"This addon does not have an endpoint defined for the 'addons open' command.\nYou can add one by annotating a service with the label {{.labelName}}:{{.addonName}}": "",
"This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true": "",
"Tip: Use 'minikube start -p \u003cname\u003e' to create a new cluster, or 'minikube delete' to delete this one.": "",
"To connect to this cluster, use: kubectl --context=%s": "",
......@@ -226,14 +223,14 @@
"Verifying:": "Vérifiant:",
"Version: {{.version}}": "",
"Wait failed": "",
"Wait failed: %v": "",
"Wait failed: {{.error}}": "",
"Waiting for SSH access ...": "Attendant l'accès SSH ...",
"You appear to be using a proxy, but your NO_PROXY environment does not include the minikube IP (%s). Please see https://github.com/kubernetes/minikube/blob/master/docs/http_proxy.md for more details": "",
"You must specify a service name": "",
"Your host does not support KVM virtualization. Ensure that qemu-kvm is installed, and run 'virt-host-validate' to debug the problem": "",
"Your host is failing to route packets to the minikube VM. If you have VPN software, try turning it off or configuring it so that it does not re-route traffic to the VM IP. If not, check your VM environment routing options.": "",
"addon '%s' is currently not enabled.\nTo enable this addon run:\nminikube addons enable %s": "",
"addon '%s' is not a valid addon packaged with minikube.\nTo see the list of available addons run:\nminikube addons list": "",
"addon '{{.name}}' is currently not enabled.\nTo enable this addon run:\nminikube addons enable {{.name}}": "",
"addon '{{.name}}' is not a valid addon packaged with minikube.\nTo see the list of available addons run:\nminikube addons list": "",
"addon list failed": "",
"api load": "",
"bash completion failed": "",
......@@ -281,8 +278,12 @@
"zsh completion failed": "",
"{{.addonName}} was successfully enabled": "",
"{{.error}}": "",
"{{.machine}} IP has been updated to point at {{.ip}}": "",
"{{.machine}} IP was already correctly configured for {{.ip}}": "",
"{{.msg}}: {{.err}}": "",
"{{.name}} cluster does not exist": "",
"{{.name}} has no available configuration options": "",
"{{.name}} was successfully configured": "",
"{{.type}} is not yet a supported filesystem. We will try anyways!": "",
"{{.url}}": "",
"{{.url}} is not accessible: {{.error}}": ""
......
......@@ -4,14 +4,11 @@
"%q host does not exist, unable to show an IP": "",
"%q profile does not exist": "",
"%q stopped.": "",
"%s IP has been updated to point at %s": "",
"%s IP was already correctly configured for %s": "",
"%s has no available configuration options": "",
"%s was successfully configured": "",
"%s was successfully disabled": "",
"'none' driver does not support 'minikube docker-env' command": "",
"'none' driver does not support 'minikube mount' command": "",
"'none' driver does not support 'minikube ssh' command": "",
"==\u003e {{.name}} \u003c==": "",
"A firewall is blocking Docker within the minikube VM from reaching the internet. You may need to configure it to use a proxy.": "",
"A firewall is interfering with minikube's ability to make outgoing HTTPS requests. You may need to change the value of the HTTPS_PROXY environment variable.": "",
"A firewall is likely blocking minikube from reaching the internet. You may need to configure minikube to use a proxy.": "",
......@@ -35,8 +32,8 @@
"Downloading Minikube ISO ...": "",
"Downloading {{.name}} {{.version}}": "",
"ERROR creating `registry-creds-dpr` secret": "",
"ERROR creating `registry-creds-ecr` secret: %v": "",
"ERROR creating `registry-creds-gcr` secret: %v": "",
"ERROR creating `registry-creds-ecr` secret: {{.error}}": "",
"ERROR creating `registry-creds-gcr` secret: {{.error}}": "",
"Enabling dashboard ...": "",
"Error checking driver version: %v": "",
"Error creating list template": "",
......@@ -51,7 +48,7 @@
"Error getting IP": "",
"Error getting bootstrapper": "",
"Error getting client": "",
"Error getting client: %v": "",
"Error getting client: {{.error}}": "",
"Error getting cluster": "",
"Error getting cluster bootstrapper": "",
"Error getting config": "",
......@@ -60,7 +57,7 @@
"Error getting machine logs": "",
"Error getting machine status": "",
"Error getting service status": "",
"Error getting service with namespace: %s and labels %s:%s: %v": "",
"Error getting service with namespace: {{.namespace}} and labels {{.labelName}}:{{.addonName}}: {{.error}}": "",
"Error getting the host IP address to use from within the VM": "",
"Error host driver ip status": "",
"Error killing mount process": "",
......@@ -119,7 +116,7 @@
"Install VirtualBox, ensure that VBoxManage is executable and in path, or select an alternative value for --vm-driver": "",
"Install the latest kvm2 driver and run 'virt-host-validate'": "",
"Install the latest minikube hyperkit driver, and run 'minikube delete'": "",
"Invalid size passed in argument: %v": "",
"Invalid size passed in argument: {{.error}}": "",
"IsEnabled failed": "",
"Kubernetes downgrade is not supported, will continue to use {{.version}}": "",
"Launching Kubernetes ... ": "正在启动 Kubernetes ... ",
......@@ -144,8 +141,8 @@
"Please specify the directory to be mounted: \n\tminikube mount \u003csource directory\u003e:\u003ctarget directory\u003e (example: \"/host-home:/vm-home\")": "",
"Please upgrade the 'docker-machine-driver-kvm2'. %s": "",
"Powering off %q via SSH ...": "",
"Problems detected in %q:": "",
"Problems detected in {{.entry}}:": "",
"Problems detected in {{.name}}:": "",
"Pulling images ...": "拉取镜像 ...",
"Re-run 'minikube start' with --alsologtostderr -v=8 to see the VM driver error message": "",
"Re-using the currently running %s VM for %q ...": "",
......@@ -186,10 +183,10 @@
"The docker service is currently not active": "",
"The minikube VM is offline. Please run 'minikube start' to start it again.": "",
"The value passed to --format is invalid": "",
"The value passed to --format is invalid: %s": "",
"The value passed to --format is invalid: {{.error}}": "",
"The vmwarefusion driver is deprecated and support for it will be removed in a future release.\n\t\t\tPlease consider switching to the new vmware unified driver, which is intended to replace the vmwarefusion driver.\n\t\t\tSee https://github.com/kubernetes/minikube/blob/master/docs/drivers.md#vmware-unified-driver for more information.\n\t\t\tTo disable this message, run [minikube config set ShowDriverDeprecationNotification false]": "",
"These changes will take effect upon a minikube delete and then a minikube start": "",
"This addon does not have an endpoint defined for the 'addons open' command.\nYou can add one by annotating a service with the label %s:%s": "",
"This addon does not have an endpoint defined for the 'addons open' command.\nYou can add one by annotating a service with the label {{.labelName}}:{{.addonName}}": "",
"This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true": "",
"Tip: Use 'minikube start -p \u003cname\u003e' to create a new cluster, or 'minikube delete' to delete this one.": "",
"To connect to this cluster, use: kubectl --context=%s": "",
......@@ -226,14 +223,14 @@
"Verifying:": "正在验证:",
"Version: {{.version}}": "",
"Wait failed": "",
"Wait failed: %v": "",
"Wait failed: {{.error}}": "",
"Waiting for SSH access ...": "",
"You appear to be using a proxy, but your NO_PROXY environment does not include the minikube IP (%s). Please see https://github.com/kubernetes/minikube/blob/master/docs/http_proxy.md for more details": "",
"You must specify a service name": "",
"Your host does not support KVM virtualization. Ensure that qemu-kvm is installed, and run 'virt-host-validate' to debug the problem": "",
"Your host is failing to route packets to the minikube VM. If you have VPN software, try turning it off or configuring it so that it does not re-route traffic to the VM IP. If not, check your VM environment routing options.": "",
"addon '%s' is currently not enabled.\nTo enable this addon run:\nminikube addons enable %s": "",
"addon '%s' is not a valid addon packaged with minikube.\nTo see the list of available addons run:\nminikube addons list": "",
"addon '{{.name}}' is currently not enabled.\nTo enable this addon run:\nminikube addons enable {{.name}}": "",
"addon '{{.name}}' is not a valid addon packaged with minikube.\nTo see the list of available addons run:\nminikube addons list": "",
"addon list failed": "",
"api load": "",
"bash completion failed": "",
......@@ -281,8 +278,12 @@
"zsh completion failed": "",
"{{.addonName}} was successfully enabled": "",
"{{.error}}": "",
"{{.machine}} IP has been updated to point at {{.ip}}": "",
"{{.machine}} IP was already correctly configured for {{.ip}}": "",
"{{.msg}}: {{.err}}": "",
"{{.name}} cluster does not exist": "",
"{{.name}} has no available configuration options": "",
"{{.name}} was successfully configured": "",
"{{.type}} is not yet a supported filesystem. We will try anyways!": "",
"{{.url}}": "",
"{{.url}} is not accessible: {{.error}}": ""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册