Skip to content

Commit

Permalink
Merge pull request #4376 from sharifelgamal/style-enum
Browse files Browse the repository at this point in the history
Change console style string to enum
  • Loading branch information
sharifelgamal authored May 30, 2019
2 parents b56c5ab + 94932dd commit 16af8b4
Show file tree
Hide file tree
Showing 26 changed files with 267 additions and 189 deletions.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ minikube addons list`, addonName)
exit.WithError("IsEnabled failed", err)
}
if !ok {
console.ErrStyle("conflict", `addon '%s' is currently not enabled.
console.ErrStyle(console.Conflict, `addon '%s' is currently not enabled.
To enable this addon run:
minikube addons enable %s`, addonName, addonName)
os.Exit(exit.Unavailable)
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 @@ -55,7 +55,7 @@ func IsValidDriver(string, driver string) error {

// RequiresRestartMsg returns the "requires restart" message
func RequiresRestartMsg(string, string) error {
console.OutStyle("warning", "These changes will take effect upon a minikube delete and then a minikube start")
console.OutStyle(console.WarningType, "These changes will take effect upon a minikube delete and then a minikube start")
return nil
}

Expand Down
10 changes: 5 additions & 5 deletions cmd/minikube/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var dashboardCmd = &cobra.Command{
cluster.EnsureMinikubeRunningOrExit(api, 1)

// Send status messages to stderr for folks re-using this output.
console.ErrStyle("enabling", "Enabling dashboard ...")
console.ErrStyle(console.Enabling, "Enabling dashboard ...")
// Enable the dashboard add-on
err = configcmd.Set("dashboard", "true")
if err != nil {
Expand All @@ -91,27 +91,27 @@ var dashboardCmd = &cobra.Command{

ns := "kube-system"
svc := "kubernetes-dashboard"
console.ErrStyle("verifying", "Verifying dashboard health ...")
console.ErrStyle(console.Verifying, "Verifying dashboard health ...")
if err = util.RetryAfter(180, func() error { return service.CheckService(ns, svc) }, 1*time.Second); err != nil {
exit.WithCode(exit.Unavailable, "%s:%s is not running: %v", ns, svc, err)
}

console.ErrStyle("launch", "Launching proxy ...")
console.ErrStyle(console.Launch, "Launching proxy ...")
p, hostPort, err := kubectlProxy(kubectl)
if err != nil {
exit.WithError("kubectl proxy", err)
}
url := dashboardURL(hostPort, ns, svc)

console.ErrStyle("verifying", "Verifying proxy health ...")
console.ErrStyle(console.Verifying, "Verifying proxy health ...")
if err = util.RetryAfter(60, func() error { return checkURL(url) }, 1*time.Second); err != nil {
exit.WithCode(exit.Unavailable, "%s is not responding properly: %v", url, err)
}

if dashboardURLMode {
console.OutLn(url)
} else {
console.ErrStyle("celebrate", "Opening %s in your default browser...", url)
console.ErrStyle(console.Celebrate, "Opening %s in your default browser...", url)
if err = browser.OpenURL(url); err != nil {
console.Failure("failed to open browser: %v", err)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ associated files.`,
if err == nil && cc.MachineConfig.VMDriver == "none" {
kc := cc.KubernetesConfig
bsName := viper.GetString(cmdcfg.Bootstrapper)
console.OutStyle("resetting", "Uninstalling Kubernetes %s using %s ...", kc.KubernetesVersion, bsName)
console.OutStyle(console.Resetting, "Uninstalling Kubernetes %s using %s ...", kc.KubernetesVersion, bsName)
clusterBootstrapper, err := GetClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
if err != nil {
console.ErrLn("Unable to get bootstrapper: %v", err)
Expand All @@ -73,7 +73,7 @@ associated files.`,
if err = cluster.DeleteHost(api); err != nil {
switch err := errors.Cause(err).(type) {
case mcnerror.ErrHostDoesNotExist:
console.OutStyle("meh", "%q cluster does not exist", profile)
console.OutStyle(console.Meh, "%q cluster does not exist", profile)
default:
exit.WithError("Failed to delete cluster", err)
}
Expand All @@ -85,12 +85,12 @@ associated files.`,

if err := os.Remove(constants.GetProfileFile(viper.GetString(pkg_config.MachineProfile))); err != nil {
if os.IsNotExist(err) {
console.OutStyle("meh", "%q profile does not exist", profile)
console.OutStyle(console.Meh, "%q profile does not exist", profile)
os.Exit(0)
}
exit.WithError("Failed to remove profile", err)
}
console.OutStyle("crushed", "The %q cluster has been deleted.", profile)
console.OutStyle(console.Crushed, "The %q cluster has been deleted.", profile)
},
}

Expand Down
32 changes: 16 additions & 16 deletions cmd/minikube/cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,29 @@ var mountCmd = &cobra.Command{
cfg.Options[parts[0]] = parts[1]
}

console.OutStyle("mounting", "Mounting host path %s into VM as %s ...", hostPath, vmPath)
console.OutStyle("mount-options", "Mount options:")
console.OutStyle("option", "Type: %s", cfg.Type)
console.OutStyle("option", "UID: %s", cfg.UID)
console.OutStyle("option", "GID: %s", cfg.GID)
console.OutStyle("option", "Version: %s", cfg.Version)
console.OutStyle("option", "MSize: %d", cfg.MSize)
console.OutStyle("option", "Mode: %o (%s)", cfg.Mode, cfg.Mode)
console.OutStyle("option", "Options: %s", cfg.Options)
console.OutStyle(console.Mounting, "Mounting host path %s into VM as %s ...", hostPath, vmPath)
console.OutStyle(console.MountOptions, "Mount options:")
console.OutStyle(console.Option, "Type: %s", cfg.Type)
console.OutStyle(console.Option, "UID: %s", cfg.UID)
console.OutStyle(console.Option, "GID: %s", cfg.GID)
console.OutStyle(console.Option, "Version: %s", cfg.Version)
console.OutStyle(console.Option, "MSize: %d", cfg.MSize)
console.OutStyle(console.Option, "Mode: %o (%s)", cfg.Mode, cfg.Mode)
console.OutStyle(console.Option, "Options: %s", cfg.Options)

// An escape valve to allow future hackers to try NFS, VirtFS, or other FS types.
if !supportedFilesystems[cfg.Type] {
console.OutLn("")
console.OutStyle("warning", "%s is not yet a supported filesystem. We will try anyways!", cfg.Type)
console.OutStyle(console.WarningType, "%s is not yet a supported filesystem. We will try anyways!", cfg.Type)
}

var wg sync.WaitGroup
if cfg.Type == nineP {
wg.Add(1)
go func() {
console.OutStyle("fileserver", "Userspace file server: ")
console.OutStyle(console.Fileserver, "Userspace file server: ")
ufs.StartServer(net.JoinHostPort(ip.String(), strconv.Itoa(port)), debugVal, hostPath)
console.OutStyle("stopped", "Userspace file server is shutdown")
console.OutStyle(console.Stopped, "Userspace file server is shutdown")
wg.Done()
}()
}
Expand All @@ -180,10 +180,10 @@ var mountCmd = &cobra.Command{
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
for sig := range c {
console.OutStyle("unmount", "Unmounting %s ...", vmPath)
console.OutStyle(console.Unmount, "Unmounting %s ...", vmPath)
err := cluster.Unmount(runner, vmPath)
if err != nil {
console.ErrStyle("failure", "Failed unmount: %v", err)
console.ErrStyle(console.FailureType, "Failed unmount: %v", err)
}
exit.WithCode(exit.Interrupted, "Exiting due to %s signal", sig)
}
Expand All @@ -193,9 +193,9 @@ var mountCmd = &cobra.Command{
if err != nil {
exit.WithError("mount failed", err)
}
console.OutStyle("success", "Successfully mounted %s to %s", hostPath, vmPath)
console.OutStyle(console.SuccessType, "Successfully mounted %s to %s", hostPath, vmPath)
console.OutLn("")
console.OutStyle("notice", "NOTE: This process must stay alive for the mount to be accessible ...")
console.OutStyle(console.Notice, "NOTE: This process must stay alive for the mount to be accessible ...")
wg.Wait()
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/service_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var serviceListCmd = &cobra.Command{
serviceURLs, err := service.GetServiceURLs(api, serviceListNamespace, serviceURLTemplate)
if err != nil {
console.Fatal("Failed to get service URL: %v", err)
console.ErrStyle("notice", "Check that minikube is running and that you have specified the correct namespace (-n flag) if required.")
console.ErrStyle(console.Notice, "Check that minikube is running and that you have specified the correct namespace (-n flag) if required.")
os.Exit(exit.Unavailable)
}

Expand Down
52 changes: 26 additions & 26 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ assumes you have already installed one of the VM drivers: virtualbox/parallels/v

// runStart handles the executes the flow of "minikube start"
func runStart(cmd *cobra.Command, args []string) {
console.OutStyle("happy", "minikube %s on %s (%s)", version.GetVersion(), runtime.GOOS, runtime.GOARCH)
console.OutStyle(console.Happy, "minikube %s on %s (%s)", version.GetVersion(), runtime.GOOS, runtime.GOARCH)
validateConfig()

oldConfig, err := cfg.Load()
Expand Down Expand Up @@ -216,7 +216,7 @@ func runStart(cmd *cobra.Command, args []string) {
if err := CacheImagesInConfigFile(); err != nil {
exit.WithError("Failed to cache images", err)
}
console.OutStyle("check", "Download complete!")
console.OutStyle(console.Check, "Download complete!")
return
}

Expand All @@ -226,7 +226,7 @@ func runStart(cmd *cobra.Command, args []string) {
// Makes minikube node ip to bypass http(s) proxy. since it is local traffic.
err = proxy.ExcludeIP(ip)
if err != nil {
console.ErrStyle("Failed to set NO_PROXY Env. please Use `export NO_PROXY=$NO_PROXY,%s`.", ip)
console.ErrStyle(console.FailureType, "Failed to set NO_PROXY Env. please Use `export NO_PROXY=$NO_PROXY,%s`.", ip)
}
// Save IP to configuration file for subsequent use
config.KubernetesConfig.NodeIP = ip
Expand All @@ -240,12 +240,12 @@ func runStart(cmd *cobra.Command, args []string) {

cr := configureRuntimes(runner)
version, _ := cr.Version()
console.OutStyle(cr.Name(), "Configuring environment for Kubernetes %s on %s %s", k8sVersion, cr.Name(), version)
console.OutStyle(cr.Style(), "Configuring environment for Kubernetes %s on %s %s", k8sVersion, cr.Name(), version)
for _, v := range dockerOpt {
console.OutStyle("option", "opt %s", v)
console.OutStyle(console.Option, "opt %s", v)
}
for _, v := range dockerEnv {
console.OutStyle("option", "env %s", v)
console.OutStyle(console.Option, "env %s", v)
}

// prepareHostEnvironment uses the downloaded images, so we need to wait for background task completion.
Expand All @@ -262,7 +262,7 @@ func runStart(cmd *cobra.Command, args []string) {
}

if config.MachineConfig.VMDriver == constants.DriverNone {
console.OutStyle("starting-none", "Configuring local host environment ...")
console.OutStyle(console.StartingNone, "Configuring local host environment ...")
prepareNone()
}

Expand All @@ -275,13 +275,13 @@ func runStart(cmd *cobra.Command, args []string) {

func showKubectlConnectInfo(kubeconfig *pkgutil.KubeConfigSetup) {
if kubeconfig.KeepContext {
console.OutStyle("kubectl", "To connect to this cluster, use: kubectl --context=%s", kubeconfig.ClusterName)
console.OutStyle(console.Kubectl, "To connect to this cluster, use: kubectl --context=%s", kubeconfig.ClusterName)
} else {
console.OutStyle("ready", "Done! kubectl is now configured to use %q", cfg.GetMachineName())
console.OutStyle(console.Ready, "Done! kubectl is now configured to use %q", cfg.GetMachineName())
}
_, err := exec.LookPath("kubectl")
if err != nil {
console.OutStyle("tip", "For best results, install kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/")
console.OutStyle(console.Tip, "For best results, install kubectl: https://kubernetes.io/docs/tasks/tools/install-kubectl/")
}
}

Expand Down Expand Up @@ -416,7 +416,7 @@ func generateConfig(cmd *cobra.Command, k8sVersion string) (cfg.Config, error) {
repository := viper.GetString(imageRepository)
mirrorCountry := strings.ToLower(viper.GetString(imageMirrorCountry))
if strings.ToLower(repository) == "auto" || mirrorCountry != "" {
console.OutStyle("connectivity", "checking main repository and mirrors for images")
console.OutStyle(console.Connectivity, "checking main repository and mirrors for images")
found, autoSelectedRepository, err := selectImageRepository(mirrorCountry, k8sVersion)
if err != nil {
exit.WithError("Failed to check main repository and mirrors for images for images", err)
Expand All @@ -434,7 +434,7 @@ func generateConfig(cmd *cobra.Command, k8sVersion string) (cfg.Config, error) {
}

if repository != "" {
console.OutStyle("success", "using image repository %s", repository)
console.OutStyle(console.SuccessType, "using image repository %s", repository)
}

cfg := cfg.Config{
Expand Down Expand Up @@ -492,7 +492,7 @@ func prepareNone() {
console.OutLn("")
console.Warning("The 'none' driver provides limited isolation and may reduce system security and reliability.")
console.Warning("For more information, see:")
console.OutStyle("url", "https://github.com/kubernetes/minikube/blob/master/docs/vmdriver-none.md")
console.OutStyle(console.URL, "https://github.com/kubernetes/minikube/blob/master/docs/vmdriver-none.md")
console.OutLn("")
}

Expand All @@ -503,11 +503,11 @@ func prepareNone() {
console.Warning("need to relocate them. For example, to overwrite your own settings:")

console.OutLn("")
console.OutStyle("command", "sudo mv %s/.kube %s/.minikube $HOME", home, home)
console.OutStyle("command", "sudo chown -R $USER $HOME/.kube $HOME/.minikube")
console.OutStyle(console.Command, "sudo mv %s/.kube %s/.minikube $HOME", home, home)
console.OutStyle(console.Command, "sudo chown -R $USER $HOME/.kube $HOME/.minikube")
console.OutLn("")

console.OutStyle("tip", "This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true")
console.OutStyle(console.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 {
Expand Down Expand Up @@ -548,10 +548,10 @@ func validateNetwork(h *host.Host) string {
for _, k := range proxy.EnvVars {
if v := os.Getenv(k); v != "" {
if !optSeen {
console.OutStyle("internet", "Found network options:")
console.OutStyle(console.Internet, "Found network options:")
optSeen = true
}
console.OutStyle("option", "%s=%s", k, v)
console.OutStyle(console.Option, "%s=%s", k, v)
ipExcluded := proxy.IsIPExcluded(ip) // Skip warning if minikube ip is already in NO_PROXY
if (k == "HTTP_PROXY" || k == "HTTPS_PROXY") && !ipExcluded && !warnedOnce {
console.Warning("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", ip)
Expand Down Expand Up @@ -587,11 +587,11 @@ func validateKubernetesVersions(old *cfg.Config) (string, bool) {

if nvs.LT(ovs) {
nv = version.VersionPrefix + ovs.String()
console.ErrStyle("conflict", "Kubernetes downgrade is not supported, will continue to use %v", nv)
console.ErrStyle(console.Conflict, "Kubernetes downgrade is not supported, will continue to use %v", nv)
return nv, isUpgrade
}
if nvs.GT(ovs) {
console.OutStyle("thumbs-up", "minikube will upgrade the local cluster from Kubernetes %s to %s", ovs, nvs)
console.OutStyle(console.ThumbsUp, "minikube will upgrade the local cluster from Kubernetes %s to %s", ovs, nvs)
isUpgrade = true
}
return nv, isUpgrade
Expand All @@ -604,7 +604,7 @@ func prepareHostEnvironment(api libmachine.API, kc cfg.KubernetesConfig) bootstr
exit.WithError("Failed to get bootstrapper", err)
}
for _, eo := range extraOptions {
console.OutStyle("option", "%s.%s=%s", eo.Component, eo.Key, eo.Value)
console.OutStyle(console.Option, "%s.%s=%s", eo.Component, eo.Key, eo.Value)
}
// Loads cached images, generates config files, download binaries
if err := bs.UpdateCluster(kc); err != nil {
Expand Down Expand Up @@ -666,21 +666,21 @@ func bootstrapCluster(bs bootstrapper.Bootstrapper, r cruntime.Manager, runner b
bsName := viper.GetString(cmdcfg.Bootstrapper)

if isUpgrade || !preexisting {
console.OutStyle("pulling", "Pulling images ...")
console.OutStyle(console.Pulling, "Pulling images ...")
if err := bs.PullImages(kc); err != nil {
console.OutStyle("failure", "Unable to pull images, which may be OK: %v", err)
console.OutStyle(console.FailureType, "Unable to pull images, which may be OK: %v", err)
}
}

if preexisting {
console.OutStyle("restarting", "Relaunching Kubernetes %s using %s ... ", kc.KubernetesVersion, bsName)
console.OutStyle(console.Restarting, "Relaunching Kubernetes %s using %s ... ", kc.KubernetesVersion, bsName)
if err := bs.RestartCluster(kc); err != nil {
exit.WithLogEntries("Error restarting cluster", err, logs.FindProblems(r, bs, runner))
}
return
}

console.OutStyle("launch", "Launching Kubernetes ... ")
console.OutStyle(console.Launch, "Launching Kubernetes ... ")
if err := bs.StartCluster(kc); err != nil {
exit.WithLogEntries("Error starting cluster", err, logs.FindProblems(r, bs, runner))
}
Expand All @@ -692,7 +692,7 @@ func configureMounts() {
return
}

console.OutStyle("mounting", "Creating mount %s ...", viper.GetString(mountString))
console.OutStyle(console.Mounting, "Creating mount %s ...", viper.GetString(mountString))
path := os.Args[0]
mountDebugVal := 0
if glog.V(8) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/minikube/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ itself, leaving all files intact. The cluster can be started again with the "sta
err = cluster.StopHost(api)
switch err := errors.Cause(err).(type) {
case mcnerror.ErrHostDoesNotExist:
console.OutStyle("meh", "%q VM does not exist, nothing to stop", profile)
console.OutStyle(console.Meh, "%q VM does not exist, nothing to stop", profile)
nonexistent = true
return nil
default:
Expand All @@ -64,11 +64,11 @@ itself, leaving all files intact. The cluster can be started again with the "sta
exit.WithError("Unable to stop VM", err)
}
if !nonexistent {
console.OutStyle("stopped", "%q stopped.", profile)
console.OutStyle(console.Stopped, "%q stopped.", profile)
}

if err := cmdUtil.KillMountProcess(); err != nil {
console.OutStyle("warning", "Unable to kill mount process: %s", err)
console.OutStyle(console.WarningType, "Unable to kill mount process: %s", err)
}

machineName := pkg_config.GetMachineName()
Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/update-context.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ var updateContextCmd = &cobra.Command{
exit.WithError("update config", err)
}
if updated {
console.OutStyle("celebrate", "%s IP has been updated to point at %s", machineName, ip)
console.OutStyle(console.Celebrate, "%s IP has been updated to point at %s", machineName, ip)
} else {
console.OutStyle("meh", "%s IP was already correctly configured for %s", machineName, ip)
console.OutStyle(console.Meh, "%s IP was already correctly configured for %s", machineName, ip)
}

},
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,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.OutStyle("waiting-pods", "Verifying:")
console.OutStyle(console.WaitingPods, "Verifying:")
client, err := util.GetClient()
if err != nil {
return errors.Wrap(err, "k8s client")
Expand Down
Loading

0 comments on commit 16af8b4

Please sign in to comment.