Skip to content

Commit

Permalink
Merge pull request #10603 from spowelljr/fixStepTests
Browse files Browse the repository at this point in the history
Fix Tests: Added a new step and changed Step to ErrT for err logs
  • Loading branch information
medyagh committed Mar 3, 2021
2 parents 5a7440e + f77abd1 commit 1562092
Show file tree
Hide file tree
Showing 30 changed files with 107 additions and 83 deletions.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/addons_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ var printAddonsList = func(cc *config.ClusterConfig) {
klog.Errorf("list profiles returned error: %v", err)
}
if len(v) > 1 {
out.Step(style.Tip, "To see addons list for other profiles use: `minikube addons -p name list`")
out.Styled(style.Tip, "To see addons list for other profiles use: `minikube addons -p name list`")
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/config/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var addonsEnableCmd = &cobra.Command{
addon := args[0]
// replace heapster as metrics-server because heapster is deprecated
if addon == "heapster" {
out.Step(style.Waiting, "enable metrics-server addon instead of heapster addon because heapster is deprecated")
out.Styled(style.Waiting, "enable metrics-server addon instead of heapster addon because heapster is deprecated")
addon = "metrics-server"
}
viper.Set(config.AddonImages, images)
Expand All @@ -56,7 +56,7 @@ var addonsEnableCmd = &cobra.Command{
if ClusterFlagValue() != constants.DefaultClusterName {
tipProfileArg = fmt.Sprintf(" -p %s", ClusterFlagValue())
}
out.Step(style.Tip, `Some dashboard features require the metrics-server addon. To enable all features please run:
out.Styled(style.Tip, `Some dashboard features require the metrics-server addon. To enable all features please run:
minikube{{.profileArg}} addons enable metrics-server
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ You can add one by annotating a service with the label {{.labelName}}:{{.addonNa
}

if len(urlString) != 0 {
out.Step(style.Celebrate, "Opening Kubernetes service {{.namespace_name}}/{{.service_name}} in default browser...", out.V{"namespace_name": namespace, "service_name": svc})
out.Styled(style.Celebrate, "Opening Kubernetes service {{.namespace_name}}/{{.service_name}} in default browser...", out.V{"namespace_name": namespace, "service_name": svc})
for _, url := range urlString {
if err := browser.OpenURL(url); err != nil {
exit.Error(reason.HostBrowser, fmt.Sprintf("browser failed to open url %s", url), err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var ProfileCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
profile := ClusterFlagValue()
out.Step(style.Empty, profile)
out.Styled(style.Empty, profile)
os.Exit(0)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var dashboardCmd = &cobra.Command{
if dashboardURLMode || user.Uid == "0" {
out.Ln(url)
} else {
out.Step(style.Celebrate, "Opening {{.url}} in your default browser...", out.V{"url": url})
out.Styled(style.Celebrate, "Opening {{.url}} in your default browser...", out.V{"url": url})
if err = browser.OpenURL(url); err != nil {
exit.Message(reason.HostBrowser, "failed to open browser: {{.error}}", out.V{"error": err})
}
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 @@ -145,7 +145,7 @@ func runDelete(cmd *cobra.Command, args []string) {
if purge && len(profilesToDelete) > 1 && !deleteAll {
out.ErrT(style.Notice, "Multiple minikube profiles were found - ")
for _, p := range profilesToDelete {
out.Step(style.Notice, " - {{.profile}}", out.V{"profile": p.Name})
out.Styled(style.Notice, " - {{.profile}}", out.V{"profile": p.Name})
}
exit.Message(reason.Usage, "Usage: minikube delete --all --purge")
}
Expand Down Expand Up @@ -307,7 +307,7 @@ func deleteHosts(api libmachine.API, cc *config.ClusterConfig) {
klog.Infof("Host %s does not exist. Proceeding ahead with cleanup.", machineName)
default:
out.FailureT("Failed to delete cluster: {{.error}}", out.V{"error": err})
out.Step(style.Notice, `You may need to manually remove the "{{.name}}" VM from your hypervisor`, out.V{"name": machineName})
out.Styled(style.Notice, `You may need to manually remove the "{{.name}}" VM from your hypervisor`, out.V{"name": machineName})
}
}
}
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 @@ -168,7 +168,7 @@ var mountCmd = &cobra.Command{
if cfg.Type == nineP {
wg.Add(1)
go func() {
out.Step(style.Fileserver, "Userspace file server: ")
out.Styled(style.Fileserver, "Userspace file server: ")
ufs.StartServer(net.JoinHostPort(bindIP, strconv.Itoa(port)), debugVal, hostPath)
out.Step(style.Stopped, "Userspace file server is shutdown")
wg.Done()
Expand All @@ -195,7 +195,7 @@ var mountCmd = &cobra.Command{
}
out.Step(style.Success, "Successfully mounted {{.sourcePath}} to {{.destinationPath}}", out.V{"sourcePath": hostPath, "destinationPath": vmPath})
out.Ln("")
out.Step(style.Notice, "NOTE: This process must stay alive for the mount to be accessible ...")
out.Styled(style.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/node_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var nodeStartCmd = &cobra.Command{

machineName := config.MachineName(*cc, *n)
if machine.IsRunning(api, machineName) {
out.Step(style.Check, "{{.name}} is already running", out.V{"name": name})
out.Styled(style.Check, "{{.name}} is already running", out.V{"name": name})
os.Exit(0)
}

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 @@ -164,7 +164,7 @@ func openURLs(svc string, urls []string) {
continue
}

out.Step(style.Celebrate, "Opening service {{.namespace_name}}/{{.service_name}} in default browser...", out.V{"namespace_name": namespace, "service_name": svc})
out.Styled(style.Celebrate, "Opening service {{.namespace_name}}/{{.service_name}} in default browser...", out.V{"namespace_name": namespace, "service_name": svc})
if err := browser.OpenURL(u); err != nil {
exit.Error(reason.HostBrowser, fmt.Sprintf("open url failed: %s", u), err)
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ func showKubectlInfo(kcs *kubeconfig.Settings, k8sVersion string, machineName st

path, err := exec.LookPath("kubectl")
if err != nil {
out.Step(style.Tip, "kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'")
out.Styled(style.Tip, "kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'")
return nil
}

Expand Down Expand Up @@ -729,7 +729,7 @@ func validateDriver(ds registry.DriverState, existing *config.ClusterConfig) {
klog.Infof("status for %s: %+v", name, st)

if st.NeedsImprovement {
out.Step(style.Improvement, `For improved {{.driver}} performance, {{.fix}}`, out.V{"driver": driver.FullName(ds.Name), "fix": translate.T(st.Fix)})
out.Styled(style.Improvement, `For improved {{.driver}} performance, {{.fix}}`, out.V{"driver": driver.FullName(ds.Name), "fix": translate.T(st.Fix)})
}

if ds.Priority == registry.Obsolete {
Expand Down Expand Up @@ -1016,7 +1016,7 @@ func validateCPUCount(drvName string) {

si, err := oci.CachedDaemonInfo(drvName)
if err != nil {
out.Step(style.Confused, "Failed to verify '{{.driver_name}} info' will try again ...", out.V{"driver_name": drvName})
out.Styled(style.Confused, "Failed to verify '{{.driver_name}} info' will try again ...", out.V{"driver_name": drvName})
si, err = oci.DaemonInfo(drvName)
if err != nil {
exit.Message(reason.Usage, "Ensure your {{.driver_name}} is running and is healthy.", out.V{"driver_name": driver.FullName(drvName)})
Expand All @@ -1027,13 +1027,13 @@ func validateCPUCount(drvName string) {
if si.CPUs < cpuCount {

if driver.IsDockerDesktop(drvName) {
out.Step(style.Empty, `- Ensure your {{.driver_name}} daemon has access to enough CPU/memory resources.`, out.V{"driver_name": drvName})
out.Styled(style.Empty, `- Ensure your {{.driver_name}} daemon has access to enough CPU/memory resources.`, out.V{"driver_name": drvName})
if runtime.GOOS == "darwin" {
out.Step(style.Empty, `- Docs https://docs.docker.com/docker-for-mac/#resources`, out.V{"driver_name": drvName})
out.Styled(style.Empty, `- Docs https://docs.docker.com/docker-for-mac/#resources`, out.V{"driver_name": drvName})
}
if runtime.GOOS == "windows" {
out.String("\n\t")
out.Step(style.Empty, `- Docs https://docs.docker.com/docker-for-windows/#resources`, out.V{"driver_name": drvName})
out.Styled(style.Empty, `- Docs https://docs.docker.com/docker-for-windows/#resources`, out.V{"driver_name": drvName})
}
}

Expand Down Expand Up @@ -1346,7 +1346,7 @@ func validateKubernetesVersion(old *config.ClusterConfig) {

}
if defaultVersion.GT(nvs) {
out.Step(style.New, "Kubernetes {{.new}} is now available. If you would like to upgrade, specify: --kubernetes-version={{.prefix}}{{.new}}", out.V{"prefix": version.VersionPrefix, "new": defaultVersion})
out.Styled(style.New, "Kubernetes {{.new}} is now available. If you would like to upgrade, specify: --kubernetes-version={{.prefix}}{{.new}}", out.V{"prefix": version.VersionPrefix, "new": defaultVersion})
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
}

if cmd.Flags().Changed(imageRepository) || cmd.Flags().Changed(imageMirrorCountry) {
out.Step(style.Success, "Using image repository {{.name}}", out.V{"name": repository})
out.Styled(style.Success, "Using image repository {{.name}}", out.V{"name": repository})
}

// Backwards compatibility with --enable-default-cni
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 @@ -166,7 +166,7 @@ func stop(api libmachine.API, machineName string) bool {

switch err := errors.Cause(err).(type) {
case mcnerror.ErrHostDoesNotExist:
out.Step(style.Meh, `"{{.machineName}}" does not exist, nothing to stop`, out.V{"machineName": machineName})
out.Styled(style.Meh, `"{{.machineName}}" does not exist, nothing to stop`, out.V{"machineName": machineName})
nonexistent = true
return nil
default:
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 @@ -44,13 +44,13 @@ var updateContextCmd = &cobra.Command{
if updated {
out.Step(style.Celebrate, `"{{.context}}" context has been updated to point to {{.hostname}}:{{.port}}`, out.V{"context": cname, "hostname": co.CP.Hostname, "port": co.CP.Port})
} else {
out.Step(style.Meh, `No changes required for the "{{.context}}" context`, out.V{"context": cname})
out.Styled(style.Meh, `No changes required for the "{{.context}}" context`, out.V{"context": cname})
}

if err := kubeconfig.SetCurrentContext(cname, kubeconfig.PathFromEnv()); err != nil {
out.ErrT(style.Sad, `Error while setting kubectl current context: {{.error}}`, out.V{"error": err})
} else {
out.Step(style.Kubectl, `Current context is "{{.context}}"`, out.V{"context": cname})
out.Styled(style.Kubectl, `Current context is "{{.context}}"`, out.V{"context": cname})
}
},
}
10 changes: 5 additions & 5 deletions pkg/addons/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func EnableOrDisableAddon(cc *config.ClusterConfig, name string, val string) err
if strings.HasPrefix(name, "ingress") && enable {
if driver.IsKIC(cc.Driver) {
if runtime.GOOS == "windows" {
out.Step(style.Tip, `After the addon is enabled, please run "minikube tunnel" and your ingress resources would be available at "127.0.0.1"`)
out.Styled(style.Tip, `After the addon is enabled, please run "minikube tunnel" and your ingress resources would be available at "127.0.0.1"`)
} else if runtime.GOOS != "linux" {
exit.Message(reason.Usage, `Due to networking limitations of driver {{.driver_name}} on {{.os_name}}, {{.addon_name}} addon is not supported.
Alternatively to use this addon you can use a vm-based driver:
Expand Down Expand Up @@ -199,8 +199,8 @@ https://github.com/kubernetes/minikube/issues/7332`, out.V{"driver_name": cc.Dri
if err != nil {
return errors.Wrap(err, "registry port")
}
out.Step(style.Tip, `Registry addon on with {{.driver}} uses {{.port}} please use that instead of default 5000`, out.V{"driver": cc.Driver, "port": port})
out.Step(style.Documentation, `For more information see: https://minikube.sigs.k8s.io/docs/drivers/{{.driver}}`, out.V{"driver": cc.Driver})
out.Styled(style.Tip, `Registry addon on with {{.driver}} uses {{.port}} please use that instead of default 5000`, out.V{"driver": cc.Driver, "port": port})
out.Styled(style.Documentation, `For more information see: https://minikube.sigs.k8s.io/docs/drivers/{{.driver}}`, out.V{"driver": cc.Driver})
}
}

Expand Down Expand Up @@ -341,8 +341,8 @@ func verifyGCPAuthAddon(cc *config.ClusterConfig, name string, val string) error
err = verifyAddonStatusInternal(cc, name, val, "gcp-auth")

if enable && err == nil {
out.Step(style.Notice, "Your GCP credentials will now be mounted into every pod created in the {{.name}} cluster.", out.V{"name": cc.Name})
out.Step(style.Notice, "If you don't want your credentials mounted into a specific pod, add a label with the `gcp-auth-skip-secret` key to your pod configuration.")
out.Styled(style.Notice, "Your GCP credentials will now be mounted into every pod created in the {{.name}} cluster.", out.V{"name": cc.Name})
out.Styled(style.Notice, "If you don't want your credentials mounted into a specific pod, add a label with the `gcp-auth-skip-secret` key to your pod configuration.")
}

return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/addons/gcpauth/enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func enableAddon(cfg *config.ClusterConfig) error {
}

out.WarningT("Could not determine a Google Cloud project, which might be ok.")
out.Step(style.Tip, `To set your Google Cloud project, run:
out.Styled(style.Tip, `To set your Google Cloud project, run:
gcloud config set project <project name>
Expand Down
38 changes: 24 additions & 14 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (k *Bootstrapper) init(cfg config.ClusterConfig) error {
}
kw.Close()
wg.Wait()
if err := k.applyCNI(cfg); err != nil {
if err := k.applyCNI(cfg, true); err != nil {
return errors.Wrap(err, "apply cni")
}

Expand Down Expand Up @@ -323,7 +323,12 @@ func outputKubeadmInitSteps(logs io.Reader, wg *sync.WaitGroup) {
}

// applyCNI applies CNI to a cluster. Needs to be done every time a VM is powered up.
func (k *Bootstrapper) applyCNI(cfg config.ClusterConfig) error {
func (k *Bootstrapper) applyCNI(cfg config.ClusterConfig, registerStep ...bool) error {
regStep := false
if len(registerStep) > 0 {
regStep = registerStep[0]
}

cnm, err := cni.New(cfg)
if err != nil {
return errors.Wrap(err, "cni config")
Expand All @@ -333,8 +338,13 @@ func (k *Bootstrapper) applyCNI(cfg config.ClusterConfig) error {
return nil
}

register.Reg.SetStep(register.ConfiguringCNI)
out.Step(style.CNI, "Configuring {{.name}} (Container Networking Interface) ...", out.V{"name": cnm.String()})
// when not on init, can run in parallel and break step output order
if regStep {
register.Reg.SetStep(register.ConfiguringCNI)
out.Step(style.CNI, "Configuring {{.name}} (Container Networking Interface) ...", out.V{"name": cnm.String()})
} else {
out.Styled(style.CNI, "Configuring {{.name}} (Container Networking Interface) ...", out.V{"name": cnm.String()})
}

if err := cnm.Apply(k.c); err != nil {
return errors.Wrap(err, "cni apply")
Expand Down Expand Up @@ -1055,16 +1065,16 @@ func adviseNodePressure(err error, name string, drv string) {
klog.Warning(diskErr)
out.WarningT("The node {{.name}} has ran out of disk space.", out.V{"name": name})
// generic advice for all drivers
out.Step(style.Tip, "Please free up disk or prune images.")
out.Styled(style.Tip, "Please free up disk or prune images.")
if driver.IsVM(drv) {
out.Step(style.Stopped, "Please create a cluster with bigger disk size: `minikube start --disk SIZE_MB` ")
out.Styled(style.Stopped, "Please create a cluster with bigger disk size: `minikube start --disk SIZE_MB` ")
} else if drv == oci.Docker && runtime.GOOS != "linux" {
out.Step(style.Stopped, "Please increse Desktop's disk size.")
out.Styled(style.Stopped, "Please increse Desktop's disk size.")
if runtime.GOOS == "darwin" {
out.Step(style.Documentation, "Documentation: {{.url}}", out.V{"url": "https://docs.docker.com/docker-for-mac/space/"})
out.Styled(style.Documentation, "Documentation: {{.url}}", out.V{"url": "https://docs.docker.com/docker-for-mac/space/"})
}
if runtime.GOOS == "windows" {
out.Step(style.Documentation, "Documentation: {{.url}}", out.V{"url": "https://docs.docker.com/docker-for-windows/"})
out.Styled(style.Documentation, "Documentation: {{.url}}", out.V{"url": "https://docs.docker.com/docker-for-windows/"})
}
}
out.ErrLn("")
Expand All @@ -1075,16 +1085,16 @@ func adviseNodePressure(err error, name string, drv string) {
out.ErrLn("")
klog.Warning(memErr)
out.WarningT("The node {{.name}} has ran out of memory.", out.V{"name": name})
out.Step(style.Tip, "Check if you have unnecessary pods running by running 'kubectl get po -A")
out.Styled(style.Tip, "Check if you have unnecessary pods running by running 'kubectl get po -A")
if driver.IsVM(drv) {
out.Step(style.Stopped, "Consider creating a cluster with larger memory size using `minikube start --memory SIZE_MB` ")
out.Styled(style.Stopped, "Consider creating a cluster with larger memory size using `minikube start --memory SIZE_MB` ")
} else if drv == oci.Docker && runtime.GOOS != "linux" {
out.Step(style.Stopped, "Consider increasing Docker Desktop's memory size.")
out.Styled(style.Stopped, "Consider increasing Docker Desktop's memory size.")
if runtime.GOOS == "darwin" {
out.Step(style.Documentation, "Documentation: {{.url}}", out.V{"url": "https://docs.docker.com/docker-for-mac/space/"})
out.Styled(style.Documentation, "Documentation: {{.url}}", out.V{"url": "https://docs.docker.com/docker-for-mac/space/"})
}
if runtime.GOOS == "windows" {
out.Step(style.Documentation, "Documentation: {{.url}}", out.V{"url": "https://docs.docker.com/docker-for-windows/"})
out.Styled(style.Documentation, "Documentation: {{.url}}", out.V{"url": "https://docs.docker.com/docker-for-windows/"})
}
}
out.ErrLn("")
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func OpenURL(url string) error {
if runtime.GOOS == "linux" {
_, err := exec.LookPath("xdg-open")
if err != nil {
out.Step(style.URL, url)
out.Styled(style.URL, url)
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/driver/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func fixDriverPermissions(name string, path string, interactive bool) error {
example.WriteString(fmt.Sprintf(" $ %s \n", strings.Join(c.Args, " ")))
}

out.Step(style.Permissions, "The '{{.driver}}' driver requires elevated permissions. The following commands will be executed:\n\n{{ .example }}\n", out.V{"driver": name, "example": example.String()})
out.Styled(style.Permissions, "The '{{.driver}}' driver requires elevated permissions. The following commands will be executed:\n\n{{ .example }}\n", out.V{"driver": name, "example": example.String()})
for _, c := range cmds {
testArgs := append([]string{"-n"}, c.Args[1:]...)
test := exec.Command("sudo", testArgs...)
Expand Down
Loading

0 comments on commit 1562092

Please sign in to comment.