Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move errors and warnings to output to stderr #7382

Merged
merged 5 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/kubeconfig"
"k8s.io/minikube/pkg/minikube/mustload"
"k8s.io/minikube/pkg/minikube/out"
)

Expand All @@ -48,8 +49,7 @@ var ProfileCmd = &cobra.Command{
name is in the list of reserved keywords
*/
if config.ProfileNameInReservedKeywords(profile) {
out.ErrT(out.FailureType, `Profile name "{{.profilename}}" is minikube keyword. To delete profile use command minikube delete -p <profile name> `, out.V{"profilename": profile})
os.Exit(0)
exit.WithCodeT(exit.Config, `Profile name "{{.profilename}}" is reserved keyword. To delete this profile, run: "{{.cmd}}"`, out.V{"profilename": profile, "cmd": mustload.ExampleCmd(profile, "delete")})
}

if profile == "default" {
Expand Down
8 changes: 4 additions & 4 deletions cmd/minikube/cmd/config/profile_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ var printProfilesTable = func() {
table.Render()

if invalidProfiles != nil {
out.T(out.Warning, "Found {{.number}} invalid profile(s) ! ", out.V{"number": len(invalidProfiles)})
out.WarningT("Found {{.number}} invalid profile(s) ! ", out.V{"number": len(invalidProfiles)})
for _, p := range invalidProfiles {
out.T(out.Empty, "\t "+p.Name)
out.ErrT(out.Empty, "\t "+p.Name)
}
out.T(out.Tip, "You can delete them using the following command(s): ")
out.ErrT(out.Tip, "You can delete them using the following command(s): ")
for _, p := range invalidProfiles {
out.String(fmt.Sprintf("\t $ minikube delete -p %s \n", p.Name))
out.Err(fmt.Sprintf("\t $ minikube delete -p %s \n", p.Name))
}

}
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func IsValidDriver(string, name string) error {

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

Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func deleteProfile(profile *config.Profile) error {
}

if err := killMountProcess(); err != nil {
out.T(out.FailureType, "Failed to kill mount process: {{.error}}", out.V{"error": err})
out.FailureT("Failed to kill mount process: {{.error}}", out.V{"error": err})
}

deleteHosts(api, cc)
Expand Down Expand Up @@ -264,7 +264,7 @@ func deleteHosts(api libmachine.API, cc *config.ClusterConfig) {
case mcnerror.ErrHostDoesNotExist:
glog.Infof("Host %s does not exist. Proceeding ahead with cleanup.", machineName)
default:
out.T(out.FailureType, "Failed to delete cluster: {{.error}}", out.V{"error": err})
out.FailureT("Failed to delete cluster: {{.error}}", out.V{"error": err})
out.T(out.Notice, `You may need to manually remove the "{{.name}}" VM from your hypervisor`, out.V{"name": machineName})
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var logsCmd = &cobra.Command{
if err != nil {
out.Ln("")
// Avoid exit.WithError, since it outputs the issue URL
out.T(out.Warning, "{{.error}}", out.V{"error": err})
out.WarningT("{{.error}}", out.V{"error": err})
os.Exit(exit.Unavailable)
}
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var mountCmd = &cobra.Command{

// An escape valve to allow future hackers to try NFS, VirtFS, or other FS types.
if !supportedFilesystems[cfg.Type] {
out.T(out.Warning, "{{.type}} is not yet a supported filesystem. We will try anyways!", out.V{"type": cfg.Type})
out.WarningT("{{.type}} is not yet a supported filesystem. We will try anyways!", out.V{"type": cfg.Type})
}

bindIP := ip.String() // the ip to listen on the user's host machine
Expand Down Expand Up @@ -179,7 +179,7 @@ var mountCmd = &cobra.Command{
out.T(out.Unmount, "Unmounting {{.path}} ...", out.V{"path": vmPath})
err := cluster.Unmount(co.CP.Runner, vmPath)
if err != nil {
out.ErrT(out.FailureType, "Failed unmount: {{.error}}", out.V{"error": err})
out.FailureT("Failed unmount: {{.error}}", out.V{"error": err})
}
exit.WithCodeT(exit.Interrupted, "Received {{.name}} signal", out.V{"name": sig})
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/node_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var nodeAddCmd = &cobra.Command{
cc := co.Config

if driver.BareMetal(cc.Driver) {
out.ErrT(out.FailureType, "none driver does not support multi-node clusters")
out.FailureT("none driver does not support multi-node clusters")
}

name := node.Name(len(cc.Nodes) + 1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func startKicServiceTunnel(svc, configName string) {
service.PrintServiceList(os.Stdout, data)

openURLs(svc, urls)
out.T(out.Warning, "Because you are using docker driver on Mac, the terminal needs to be open to run it.")
out.WarningT("Because you are using docker driver on Mac, the terminal needs to be open to run it.")

<-ctrlC

Expand Down
18 changes: 9 additions & 9 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func showKubectlInfo(kcs *kubeconfig.Settings, k8sVersion string, machineName st

path, err := exec.LookPath("kubectl")
if err != nil {
out.T(out.Tip, "For best results, install kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/")
out.ErrT(out.Tip, "For best results, install kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/")
return nil
}

Expand All @@ -454,17 +454,17 @@ func showKubectlInfo(kcs *kubeconfig.Settings, k8sVersion string, machineName st

if client.Major != cluster.Major || minorSkew > 1 {
out.Ln("")
out.T(out.Warning, "{{.path}} is v{{.client_version}}, which may be incompatible with Kubernetes v{{.cluster_version}}.",
out.WarningT("{{.path}} is v{{.client_version}}, which may be incompatible with Kubernetes v{{.cluster_version}}.",
out.V{"path": path, "client_version": client, "cluster_version": cluster})
out.T(out.Tip, "You can also use 'minikube kubectl -- get pods' to invoke a matching version",
out.ErrT(out.Tip, "You can also use 'minikube kubectl -- get pods' to invoke a matching version",
out.V{"path": path, "client_version": client})
}
return nil
}

func maybeDeleteAndRetry(cc config.ClusterConfig, n config.Node, existingAddons map[string]bool, originalErr error) *kubeconfig.Settings {
if viper.GetBool(deleteOnFailure) {
out.T(out.Warning, "Node {{.name}} failed to start, deleting and trying again.", out.V{"name": n.Name})
out.WarningT("Node {{.name}} failed to start, deleting and trying again.", out.V{"name": n.Name})
// Start failed, delete the cluster and try again
profile, err := config.LoadProfile(cc.Name)
if err != nil {
Expand Down Expand Up @@ -541,7 +541,7 @@ func selectDriver(existing *config.ClusterConfig) registry.DriverState {

If vm-driver is set in the global config, please run "minikube config unset vm-driver" to resolve this warning.
`
out.T(out.Warning, warning, out.V{"driver": d, "vmd": vmd})
out.WarningT(warning, out.V{"driver": d, "vmd": vmd})
}
ds := driver.Status(d)
if ds.Name == "" {
Expand Down Expand Up @@ -750,17 +750,17 @@ func validateUser(drvName string) {
return
}

out.T(out.Stopped, `The "{{.driver_name}}" driver should not be used with root privileges.`, out.V{"driver_name": drvName})
out.T(out.Tip, "If you are running minikube within a VM, consider using --driver=none:")
out.T(out.Documentation, " https://minikube.sigs.k8s.io/docs/reference/drivers/none/")
out.ErrT(out.Stopped, `The "{{.driver_name}}" driver should not be used with root privileges.`, out.V{"driver_name": drvName})
out.ErrT(out.Tip, "If you are running minikube within a VM, consider using --driver=none:")
out.ErrT(out.Documentation, " https://minikube.sigs.k8s.io/docs/reference/drivers/none/")

if !useForce {
os.Exit(exit.Permissions)
}
cname := ClusterFlagValue()
_, err = config.Load(cname)
if err == nil || !config.IsNotExist(err) {
out.T(out.Tip, "Tip: To remove this root owned cluster, run: sudo {{.cmd}}", out.V{"cmd": mustload.ExampleCmd(cname, "delete")})
out.ErrT(out.Tip, "Tip: To remove this root owned cluster, run: sudo {{.cmd}}", out.V{"cmd": mustload.ExampleCmd(cname, "delete")})
}
if !useForce {
exit.WithCodeT(exit.Permissions, "Exiting")
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func runStop(cmd *cobra.Command, args []string) {
}

if err := killMountProcess(); err != nil {
out.T(out.Warning, "Unable to kill mount process: {{.error}}", out.V{"error": err})
out.WarningT("Unable to kill mount process: {{.error}}", out.V{"error": err})
}

if err := kubeconfig.UnsetCurrentContext(cname, kubeconfig.PathFromEnv()); err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ require (
google.golang.org/genproto v0.0.0-20200117163144-32f20d992d24 // indirect
google.golang.org/grpc v1.26.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
gopkg.in/yaml.v2 v2.2.8
gotest.tools/v3 v3.0.2 // indirect
k8s.io/api v0.17.3
k8s.io/apimachinery v0.17.3
Expand Down
2 changes: 1 addition & 1 deletion pkg/drivers/kic/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func WarnIfSlow(arg ...string) ([]byte, error) {
d := time.Since(start)
if d > warnTime {
out.WarningT(`Executing "{{.command}}" took an unusually long time: {{.duration}}`, out.V{"command": strings.Join(cmd.Args, " "), "duration": d})
out.T(out.Tip, `Restarting the {{.name}} service may improve performance.`, out.V{"name": arg[0]})
out.ErrT(out.Tip, `Restarting the {{.name}} service may improve performance.`, out.V{"name": arg[0]})
}

if ctx.Err() == context.DeadlineExceeded {
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (k *Bootstrapper) StartCluster(cfg config.ClusterConfig) error {
if rerr == nil {
return nil
}
out.T(out.Embarrassed, "Unable to restart cluster, will reset it: {{.error}}", out.V{"error": rerr})
out.ErrT(out.Embarrassed, "Unable to restart cluster, will reset it: {{.error}}", out.V{"error": rerr})
if err := k.DeleteCluster(cfg.KubernetesConfig); err != nil {
glog.Warningf("delete failed: %v", err)
}
Expand All @@ -309,7 +309,7 @@ func (k *Bootstrapper) StartCluster(cfg config.ClusterConfig) error {
return nil
}

out.T(out.Conflict, "initialization failed, will try again: {{.error}}", out.V{"error": err})
out.ErrT(out.Conflict, "initialization failed, will try again: {{.error}}", out.V{"error": err})
if err := k.DeleteCluster(cfg.KubernetesConfig); err != nil {
glog.Warningf("delete failed: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/exit/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func WithError(msg string, err error) {
// WithProblem outputs info related to a known problem and exits.
func WithProblem(msg string, err error, p *problem.Problem) {
out.ErrT(out.Empty, "")
out.ErrT(out.FailureType, "[{{.id}}] {{.msg}} {{.error}}", out.V{"msg": msg, "id": p.ID, "error": p.Err})
out.FailureT("[{{.id}}] {{.msg}} {{.error}}", out.V{"msg": msg, "id": p.ID, "error": p.Err})
p.Display()
if p.ShowIssueLink {
out.ErrT(out.Empty, "")
Expand All @@ -85,7 +85,7 @@ func WithLogEntries(msg string, err error, entries map[string][]string) {
displayError(msg, err)

for name, lines := range entries {
out.T(out.FailureType, "Problems detected in {{.entry}}:", out.V{"entry": name})
out.FailureT("Problems detected in {{.entry}}:", out.V{"entry": name})
if len(lines) > MaxLogEntries {
lines = lines[:MaxLogEntries]
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func FindProblems(r cruntime.Manager, bs bootstrapper.Bootstrapper, cfg config.C
// OutputProblems outputs discovered problems.
func OutputProblems(problems map[string][]string, maxLines int) {
for name, lines := range problems {
out.T(out.FailureType, "Problems detected in {{.name}}:", out.V{"name": name})
out.FailureT("Problems detected in {{.name}}:", out.V{"name": name})
if len(lines) > maxLines {
lines = lines[len(lines)-maxLines:]
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/machine/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func maybeWarnAboutEvalEnv(drver string, name string) {
}
out.T(out.Notice, "Noticed you have an activated docker-env on {{.driver_name}} driver in this terminal:", out.V{"driver_name": drver})
// TODO: refactor docker-env package to generate only eval command per shell. https://github.com/kubernetes/minikube/issues/6887
out.T(out.Warning, `Please re-eval your docker-env, To ensure your environment variables have updated ports:
out.WarningT(`Please re-eval your docker-env, To ensure your environment variables have updated ports:

'minikube -p {{.profile_name}} docker-env'

Expand Down
4 changes: 2 additions & 2 deletions pkg/minikube/mustload/mustload.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func Healthy(name string) ClusterController {

as, err := kverify.APIServerStatus(co.CP.Runner, co.CP.ForwardedIP, co.CP.ForwardedPort)
if err != nil {
out.T(out.FailureType, `Unable to get control plane status: {{.error}}`, out.V{"error": err})
out.FailureT(`Unable to get control plane status: {{.error}}`, out.V{"error": err})
exitTip("delete", name, exit.Unavailable)
}

Expand All @@ -162,7 +162,7 @@ func Healthy(name string) ClusterController {

if as != state.Running {
out.T(out.Shrug, `This control plane is not running! (state={{.state}})`, out.V{"state": as.String()})
out.T(out.Warning, `This is unusual - you may want to investigate using "{{.command}}"`, out.V{"command": ExampleCmd(name, "logs")})
out.WarningT(`This is unusual - you may want to investigate using "{{.command}}"`, out.V{"command": ExampleCmd(name, "logs")})
exitTip("start", name, exit.Unavailable)
}
return co
Expand Down
24 changes: 12 additions & 12 deletions pkg/minikube/node/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func Start(cc config.ClusterConfig, n config.Node, existingAddons map[string]boo
configureMounts()

if err := CacheAndLoadImagesInConfig(); err != nil {
out.T(out.FailureType, "Unable to load cached images from config file.")
out.FailureT("Unable to load cached images from config file.")
}

// enable addons, both old and new!
Expand Down Expand Up @@ -211,7 +211,7 @@ func configureRuntimes(runner cruntime.CommandRunner, drvName string, k8s config
if err := cr.Preload(k8s); err != nil {
switch err.(type) {
case *cruntime.ErrISOFeature:
out.T(out.Tip, "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'", out.V{"error": err})
out.ErrT(out.Tip, "Existing disk is missing new features ({{.error}}). To upgrade, run 'minikube delete'", out.V{"error": err})
default:
glog.Warningf("%s preload failed: %v, falling back to caching images", cr.Name(), err)
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func startMachine(cfg *config.ClusterConfig, node *config.Node) (runner command.
// Bypass proxy for minikube's vm host ip
err = proxy.ExcludeIP(ip)
if err != nil {
out.ErrT(out.FailureType, "Failed to set NO_PROXY Env. Please use `export NO_PROXY=$NO_PROXY,{{.ip}}`.", out.V{"ip": ip})
out.FailureT("Failed to set NO_PROXY Env. Please use `export NO_PROXY=$NO_PROXY,{{.ip}}`.", out.V{"ip": ip})
}

// Save IP to config file for subsequent use
Expand All @@ -333,7 +333,7 @@ func startHost(api libmachine.API, cc config.ClusterConfig, n config.Node) (*hos
if err == nil {
return host, exists
}
out.T(out.Embarrassed, "StartHost failed, but will try again: {{.error}}", out.V{"error": err})
out.ErrT(out.Embarrassed, "StartHost failed, but will try again: {{.error}}", out.V{"error": err})

// NOTE: People get very cranky if you delete their prexisting VM. Only delete new ones.
if !exists {
Expand Down Expand Up @@ -447,32 +447,32 @@ func tryRegistry(r command.Runner, driverName string) {
if rr, err := r.RunCmd(exec.Command("curl", opts...)); err != nil {
glog.Warningf("%s failed: %v", rr.Args, err)
out.WarningT("This {{.type}} is having trouble accessing https://{{.repository}}", out.V{"repository": repo, "type": driver.MachineType(driverName)})
out.T(out.Tip, "To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/")
out.ErrT(out.Tip, "To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/")
}
}

// prepareNone prepares the user and host for the joy of the "none" driver
func prepareNone() {
out.T(out.StartingNone, "Configuring local host environment ...")
if viper.GetBool(config.WantNoneDriverWarning) {
out.T(out.Empty, "")
out.ErrT(out.Empty, "")
out.WarningT("The 'none' driver is designed for experts who need to integrate with an existing VM")
out.ErrT(out.Tip, "Most users should use the newer 'docker' driver instead, which does not require root!")
out.ErrT(out.Documentation, "For more information, see: https://minikube.sigs.k8s.io/docs/reference/drivers/none/")
out.T(out.Empty, "")
out.ErrT(out.Empty, "")
}

if os.Getenv("CHANGE_MINIKUBE_NONE_USER") == "" {
home := os.Getenv("HOME")
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 need to relocate them. For example, to overwrite your own settings, run:")

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, "")
out.ErrT(out.Empty, "")
out.ErrT(out.Command, "sudo mv {{.home_folder}}/.kube {{.home_folder}}/.minikube $HOME", out.V{"home_folder": home})
out.ErrT(out.Command, "sudo chown -R $USER $HOME/.kube $HOME/.minikube")
out.ErrT(out.Empty, "")

out.T(out.Tip, "This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true")
out.ErrT(out.Tip, "This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true")
}

if err := util.MaybeChownDirRecursiveToMinikubeUser(localpath.MiniPath()); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func validateConfigCmd(ctx context.Context, t *testing.T, profile string) {
}{
{[]string{"unset", "cpus"}, "", ""},
{[]string{"get", "cpus"}, "", "Error: specified key could not be found in config"},
{[]string{"set", "cpus", "2"}, "! These changes will take effect upon a minikube delete and then a minikube start", ""},
{[]string{"set", "cpus", "2"}, "", "! These changes will take effect upon a minikube delete and then a minikube start"},
{[]string{"get", "cpus"}, "2", ""},
{[]string{"unset", "cpus"}, "", ""},
{[]string{"get", "cpus"}, "", "Error: specified key could not be found in config"},
Expand Down