Skip to content
Open
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
3 changes: 3 additions & 0 deletions pkg/minikube/cruntime/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/download"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/style"
"k8s.io/minikube/pkg/minikube/sysinit"
"k8s.io/minikube/pkg/util/retry"
Expand Down Expand Up @@ -227,6 +228,7 @@ func generateContainerdConfig(cr CommandRunner, imageRepository string, kv semve
// Enable idempotently enables containerd on a host
// It is also called by docker.Enable() - if bound to containerd, to enforce proper containerd configuration completed by service restart.
func (r *Containerd) Enable(disOthers bool, cgroupDriver string, inUserNamespace bool) error {
out.Styled(style.SubStep, "starting container runtime...")
if inUserNamespace {
if err := CheckKernelCompatibility(r.Runner, 5, 11); err != nil {
// For using overlayfs
Expand Down Expand Up @@ -521,6 +523,7 @@ func (r *Containerd) Preload(cc config.ClusterConfig) error {
if !download.PreloadExists(cc.KubernetesConfig.KubernetesVersion, cc.KubernetesConfig.ContainerRuntime, cc.Driver) {
return nil
}
out.Styled(style.SubStep, "Loading preloaded images...")

k8sVersion := cc.KubernetesConfig.KubernetesVersion
cRuntime := cc.KubernetesConfig.ContainerRuntime
Expand Down
4 changes: 3 additions & 1 deletion pkg/minikube/cruntime/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/download"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/style"
"k8s.io/minikube/pkg/minikube/sysinit"
)
Expand Down Expand Up @@ -215,6 +216,7 @@ Environment="_CRIO_ROOTLESS=1"

// Enable idempotently enables CRIO on a host
func (r *CRIO) Enable(disOthers bool, cgroupDriver string, inUserNamespace bool) error {
out.Styled(style.SubStep, "starting container runtime...")
if disOthers {
if err := disableOthers(r, r.Runner); err != nil {
klog.Warningf("disableOthers: %v", err)
Expand Down Expand Up @@ -420,7 +422,7 @@ func (r *CRIO) Preload(cc config.ClusterConfig) error {
if !download.PreloadExists(cc.KubernetesConfig.KubernetesVersion, cc.KubernetesConfig.ContainerRuntime, cc.Driver) {
return nil
}

out.Styled(style.SubStep, "Loading preloaded images...")
k8sVersion := cc.KubernetesConfig.KubernetesVersion
cRuntime := cc.KubernetesConfig.ContainerRuntime

Expand Down
3 changes: 3 additions & 0 deletions pkg/minikube/cruntime/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"k8s.io/minikube/pkg/minikube/docker"
"k8s.io/minikube/pkg/minikube/download"
"k8s.io/minikube/pkg/minikube/image"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/style"
"k8s.io/minikube/pkg/minikube/sysinit"
"k8s.io/minikube/pkg/util/retry"
Expand Down Expand Up @@ -133,6 +134,7 @@ func (r *Docker) Active() bool {

// Enable idempotently enables Docker on a host
func (r *Docker) Enable(disOthers bool, cgroupDriver string, inUserNamespace bool) error {
out.Styled(style.SubStep, "starting container runtime...")
if inUserNamespace {
if err := CheckKernelCompatibility(r.Runner, 5, 11); err != nil {
// For using overlayfs
Expand Down Expand Up @@ -621,6 +623,7 @@ func (r *Docker) Preload(cc config.ClusterConfig) error {
if !download.PreloadExists(cc.KubernetesConfig.KubernetesVersion, cc.KubernetesConfig.ContainerRuntime, cc.Driver) {
return nil
}
out.Styled(style.SubStep, "Loading preloaded images...")
k8sVersion := cc.KubernetesConfig.KubernetesVersion
cRuntime := cc.KubernetesConfig.ContainerRuntime

Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/machine/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func deleteHost(api libmachine.API, h *host.Host, machineName string) error {
// demolish destroys a host by any means necessary - use only if state is inconsistent
func demolish(api libmachine.API, cc config.ClusterConfig, n config.Node, h *host.Host) {
machineName := config.MachineName(cc, n)
out.Styled(style.SubStep, "Demolishing {{.machine_name}}...", out.V{"machine_name": machineName})
klog.Infof("DEMOLISHING %s ...", machineName)

// This will probably fail
Expand Down
4 changes: 4 additions & 0 deletions pkg/minikube/machine/filesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/command"
"k8s.io/minikube/pkg/minikube/localpath"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/style"
"k8s.io/minikube/pkg/minikube/vmpath"
)

Expand All @@ -42,6 +44,8 @@ var guaranteed = map[string]bool{

// syncLocalAssets syncs files from MINIKUBE_HOME into the cluster
func syncLocalAssets(cr command.Runner) error {
out.Styled(style.SubStep, "Syncing local assets ...")

fs, err := localAssets()
defer func() {
for _, f := range fs {
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/machine/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func ensureSyncedGuestClock(h hostRunner, drv string) error {
if !driver.IsVM(drv) {
return nil
}
out.Styled(style.SubStep, "Syncing guest system clock ...")
d, err := guestClockDelta(h, time.Now())
if err != nil {
klog.Warningf("Unable to measure system clock delta: %v", err)
Expand Down
4 changes: 3 additions & 1 deletion pkg/minikube/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/style"
"k8s.io/minikube/pkg/minikube/vmpath"
"k8s.io/minikube/pkg/provision"
"k8s.io/minikube/pkg/util/retry"
Expand Down Expand Up @@ -100,7 +102,7 @@
if err != nil {
return errors.Wrap(err, "fast detect")
}

out.Styled(style.SubStep, "Waiting for SSH server ...")
// avoid costly need to stop/power off/delete and then re-create docker machine due to the un-ready ssh server and hence errors like:
// 'error starting host: creating host: create: provisioning: ssh command error: command : sudo hostname minikube-m02 && echo "minikube-m02" | sudo tee /etc/hostname; err: exit status 255'
// so retry only on "exit status 255" ssh error and fall through in all other cases
Expand Down Expand Up @@ -188,7 +190,7 @@
}

// check first if we have anything to restore
out, err := r.RunCmd(exec.Command("sudo", "ls", "--almost-all", "-1", vmpath.GuestBackupDir))

Check failure on line 193 in pkg/minikube/machine/machine.go

View workflow job for this annotation

GitHub Actions / lint

importShadow: shadow of imported from 'k8s.io/minikube/pkg/minikube/out' package 'out' (gocritic)
if err != nil {
return errors.Wrapf(err, "read dir")
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/minikube/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func engineOptions(cfg config.ClusterConfig) *engine.Options {
}

func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) (*host.Host, error) {
out.Styled(style.SubStep, "Creating host {{.name}}...", out.V{"name": n.Name})
klog.Infof("createHost starting for %q (driver=%q)", n.Name, cfg.Driver)
start := time.Now()
defer func() {
Expand Down Expand Up @@ -205,6 +206,8 @@ func postStartValidations(h *host.Host, drvName string) {
if !driver.IsKIC(drvName) {
return
}
out.Styled(style.SubStep, "Post start validation ...")

r, err := CommandRunner(h)
if err != nil {
klog.Warningf("error getting command runner: %v", err)
Expand Down Expand Up @@ -320,6 +323,7 @@ func postStartSetup(h *host.Host, mc config.ClusterConfig) error {
}

klog.Infof("creating required directories: %v", requiredDirectories)
out.Styled(style.SubStep, "Creating Dirs ...")

r, err := CommandRunner(h)
if err != nil {
Expand Down
35 changes: 24 additions & 11 deletions pkg/minikube/out/out.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func Step(st style.Enum, format string, a ...V) {
Infof(format, a...)
return
}
outStyled, _ := stylized(st, useColor, format, a...)
outStyled, _, _ := stylized(st, useColor, format, a...)
if JSON {
register.PrintStep(outStyled)
klog.Info(outStyled)
Expand All @@ -107,9 +107,9 @@ func Styled(st style.Enum, format string, a ...V) {
Infof(format, a...)
return
}
outStyled, useSpinner := stylized(st, useColor, format, a...)
outStyled, useSpinner, hideAfterSpin := stylized(st, useColor, format, a...)
if useSpinner {
spinnerString(outStyled)
spinnerString(outStyled, hideAfterSpin)
} else {
String(outStyled)
}
Expand Down Expand Up @@ -146,13 +146,13 @@ func BoxedWithConfig(cfg box.Config, st style.Enum, title string, text string, a

// Sprintf is used for returning the string (doesn't write anything)
func Sprintf(st style.Enum, format string, a ...V) string {
outStyled, _ := stylized(st, useColor, format, a...)
outStyled, _, _ := stylized(st, useColor, format, a...)
return outStyled
}

// Infof is used for informational logs (options, env variables, etc)
func Infof(format string, a ...V) {
outStyled, _ := stylized(style.Option, useColor, format, a...)
outStyled, _, _ := stylized(style.Option, useColor, format, a...)
if JSON {
register.PrintInfo(outStyled)
}
Expand Down Expand Up @@ -214,6 +214,21 @@ func Output(file fdWriter, s string) {
}
}

// outputSpining writes a basic string with spinining
func outputSpining(file fdWriter, s string, hideAfterSpin bool) {
spin.Writer = file
spin.Prefix = s
if hideAfterSpin {
spin.UpdateCharSet(spinner.CharSets[style.SpinnerSubStepCharacter])
spin.FinalMSG = ""
} else {
spin.UpdateCharSet(spinner.CharSets[style.SpinnerCharacter])
spin.FinalMSG = s + "\n"
}
spin.Start()

}

// Outputf writes a basic formatted string
func Outputf(file fdWriter, format string, a ...interface{}) {
_, err := fmt.Fprintf(file, format, a...)
Expand All @@ -223,7 +238,7 @@ func Outputf(file fdWriter, format string, a ...interface{}) {
}

// spinnerString writes a basic formatted string to stdout with spinner character
func spinnerString(s string) {
func spinnerString(s string, hideAfterSpin bool) {
// Flush log buffer so that output order makes sense
klog.Flush()

Expand All @@ -237,9 +252,7 @@ func spinnerString(s string) {
if spin.Active() {
spin.Stop()
}
Output(outFile, s)
// Start spinning at the end of the printed line
spin.Start()
outputSpining(outFile, s, hideAfterSpin)
}

// Ln writes a basic formatted string with a newline to stdout
Expand All @@ -249,7 +262,7 @@ func Ln(format string, a ...interface{}) {

// ErrT writes a stylized and templated error message to stderr
func ErrT(st style.Enum, format string, a ...V) {
errStyled, _ := stylized(st, useColor, format, a...)
errStyled, _, _ := stylized(st, useColor, format, a...)
Err(errStyled)
}

Expand Down Expand Up @@ -316,7 +329,7 @@ func WarningT(format string, a ...V) {
if spin.Active() {
spin.Stop()
}
st, _ := stylized(style.Warning, useColor, format, a...)
st, _, _ := stylized(style.Warning, useColor, format, a...)
register.PrintWarning(st)
klog.Warning(st)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/out/out_reason.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ func determineOutput(st style.Enum, format string, a ...V) {
ErrT(st, format, a...)
return
}
errStyled, _ := stylized(st, useColor, format, a...)
errStyled, _, _ := stylized(st, useColor, format, a...)
klog.Warning(errStyled)
}
20 changes: 11 additions & 9 deletions pkg/minikube/out/out_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,33 @@ func applyPrefix(prefix, format string) string {
}

// applyStyle translates the given string if necessary then adds any appropriate style prefix.
func applyStyle(st style.Enum, useColor bool, format string) (string, bool) {
func applyStyle(st style.Enum, useColor bool, format string) (string, bool, bool) {
format = translate.T(format)

s, ok := style.Config[st]
if !s.OmitNewline {
// becaue of https://github.com/kubernetes/minikube/issues/21148
// will handle making new lines with spinner library itself
if !s.ShouldSpin {
format += "\n"
}

// Similar to CSS styles, if no style matches, output an unformatted string.
if !ok || JSON {
return format, s.Spinner
return format, s.ShouldSpin, s.HideAfterSpin
}

if !useColor {
return applyPrefix(style.LowPrefix(s), format), s.Spinner
return applyPrefix(style.LowPrefix(s), format), s.ShouldSpin, s.HideAfterSpin
}
return applyPrefix(s.Prefix, format), s.Spinner
return applyPrefix(s.Prefix, format), s.ShouldSpin, s.HideAfterSpin
}

// stylized applies formatting to the provided template
func stylized(st style.Enum, useColor bool, format string, a ...V) (string, bool) {
var spinner bool
func stylized(st style.Enum, useColor bool, format string, a ...V) (string, bool, bool) {
var shouldSpin, hideAfterSpin bool
if a == nil {
a = []V{}
}
format, spinner = applyStyle(st, useColor, format)
return Fmt(format, a...), spinner
format, shouldSpin, hideAfterSpin = applyStyle(st, useColor, format)
return Fmt(format, a...), shouldSpin, hideAfterSpin
}
4 changes: 2 additions & 2 deletions pkg/minikube/out/out_style_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestApplyStyle(t *testing.T) {
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
rawGot, _ := applyStyle(test.styleEnum, test.useColor, test.format)
rawGot, _, _ := applyStyle(test.styleEnum, test.useColor, test.format)
got := strings.TrimSpace(rawGot)
if got != test.expected {
t.Errorf("Expected '%v' but got '%v'", test.expected, got)
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestApplyTemplateFormating(t *testing.T) {
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
rawGot, _ := stylized(test.styleEnum, test.useColor, test.format, test.a...)
rawGot, _, _ := stylized(test.styleEnum, test.useColor, test.format, test.a...)
got := strings.TrimSpace(rawGot)
if got != test.expected {
t.Errorf("Expected '%v' but got '%v'", test.expected, got)
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/registry/drvs/krunkit/krunkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func configure(cfg config.ClusterConfig, n config.Node) (interface{}, error) {

func status() registry.State {
if runtime.GOOS != "darwin" && runtime.GOARCH != "arm64" {
err := errors.New("The krunkit driver is only supported on macOS arm64 machines")
err := errors.New("the krunkit driver is only supported on macOS arm64 machines")
return registry.State{Error: err, Fix: "Use another driver", Doc: docURL}
}
if _, err := exec.LookPath("krunkit"); err != nil {
Expand Down
26 changes: 14 additions & 12 deletions pkg/minikube/style/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ type Options struct {
Prefix string
// LowPrefix is the 7-bit compatible prefix we fallback to for less-awesome terminals
LowPrefix string
// OmitNewline omits a newline at the end of a message.
OmitNewline bool
// Spinner is a character to place at ending of message
Spinner bool
// ShouldSpin is a character to place at ending of message
ShouldSpin bool
HideAfterSpin bool // Hide the prefix after spinning
}

// SpinnerCharacter is which of the spinner.CharSets to use
const SpinnerCharacter = 9

// SpinnerSubStepCharacter is Character to use for sub-steps in a spinner (it looks like a progress bar)
const SpinnerSubStepCharacter = 35

// Config is a map of style name to style struct
// For consistency, ensure that emojis added render with the same width across platforms.
var Config = map[Enum]Options{
Expand All @@ -72,8 +74,8 @@ var Config = map[Enum]Options{
Pause: {Prefix: "⏸️ "},
Provisioning: {Prefix: "🌱 "},
Ready: {Prefix: "🏄 "},
Restarting: {Prefix: "🔄 "},
Running: {Prefix: "🏃 "},
Restarting: {Prefix: "🔄 ", ShouldSpin: true},
Running: {Prefix: "🏃 ", ShouldSpin: true}, // this is used when minikube start for a second time (already started)
Sparkle: {Prefix: "✨ "},
Stopped: {Prefix: "🛑 "},
Stopping: {Prefix: "✋ "},
Expand All @@ -84,7 +86,7 @@ var Config = map[Enum]Options{
URL: {Prefix: "👉 ", LowPrefix: LowIndent},
Usage: {Prefix: "💡 "},
Waiting: {Prefix: "⌛ "},
WaitingWithSpinner: {Prefix: "⌛ ", OmitNewline: true, Spinner: true},
WaitingWithSpinner: {Prefix: "⌛ ", ShouldSpin: true},
Unsupported: {Prefix: "🚡 "},
Workaround: {Prefix: "👉 ", LowPrefix: LowIndent},

Expand Down Expand Up @@ -113,11 +115,11 @@ var Config = map[Enum]Options{
Copying: {Prefix: "✨ "},
CRIO: {Prefix: "🎁 "}, // This should be a snow-flake, but the emoji has a strange width on macOS
DeletingHost: {Prefix: "🔥 "},
Docker: {Prefix: "🐳 ", OmitNewline: true, Spinner: true},
Docker: {Prefix: "🐳 ", ShouldSpin: true},
DryRun: {Prefix: "🌵 "},
Enabling: {Prefix: "🔌 "},
FileDownload: {Prefix: "💾 "},
Fileserver: {Prefix: "🚀 ", OmitNewline: true},
Fileserver: {Prefix: "🚀 "},
HealthCheck: {Prefix: "🔎 "},
Internet: {Prefix: "🌐 "},
ISODownload: {Prefix: "💿 "},
Expand All @@ -132,11 +134,11 @@ var Config = map[Enum]Options{
Shutdown: {Prefix: "🛑 "},
StartingNone: {Prefix: "🤹 "},
StartingSSH: {Prefix: "🔗 "},
StartingVM: {Prefix: "🔥 ", OmitNewline: true, Spinner: true},
SubStep: {Prefix: " ▪ ", LowPrefix: LowIndentBullet, OmitNewline: true, Spinner: true},
StartingVM: {Prefix: "🔥 ", ShouldSpin: true},
SubStep: {Prefix: " ▪ ", LowPrefix: LowIndentBullet, ShouldSpin: true, HideAfterSpin: true},
Tip: {Prefix: "💡 "},
Unmount: {Prefix: "🔥 "},
VerifyingNoLine: {Prefix: "🤔 ", OmitNewline: true},
VerifyingNoLine: {Prefix: "🤔 "},
Verifying: {Prefix: "🤔 "},
CNI: {Prefix: "🔗 "},
Toolkit: {Prefix: "🛠️ "},
Expand Down
Loading
Loading