Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
20 changes: 12 additions & 8 deletions cmd/minikube/cmd/config/addons_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strings"

"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/tw"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/assets"
Expand Down Expand Up @@ -96,9 +97,10 @@ var printAddonsList = func(cc *config.ClusterConfig, printDocs bool) {
sort.Strings(addonNames)

table := tablewriter.NewWriter(os.Stdout)
table.SetAutoFormatHeaders(true)
table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
table.SetCenterSeparator("|")

table.Options(
tablewriter.WithHeaderAutoFormat(tw.On),
)

// Create table header
var tHeader []string
Expand All @@ -110,7 +112,7 @@ var printAddonsList = func(cc *config.ClusterConfig, printDocs bool) {
if printDocs {
tHeader = append(tHeader, "Docs")
}
table.SetHeader(tHeader)
table.Header(tHeader)

// Create table data
var tData [][]string
Expand All @@ -136,10 +138,12 @@ var printAddonsList = func(cc *config.ClusterConfig, printDocs bool) {
}
tData = append(tData, temp)
}
table.AppendBulk(tData)

table.Render()

if err := table.Bulk(tData); err != nil {
klog.Error("Error rendering table (bulk)", err)
}
if err := table.Render(); err != nil {
klog.Error("Error rendering table", err)
}
v, _, err := config.ListProfiles()
if err != nil {
klog.Errorf("list profiles returned error: %v", err)
Expand Down
18 changes: 10 additions & 8 deletions cmd/minikube/cmd/config/addons_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestAddonsList(t *testing.T) {
printDocs bool
want int
}{
{"DisabledDocs", false, 9},
{"EnabledDocs", true, 12},
{"DisabledDocs", false, 3},
{"EnabledDocs", true, 4},
}

for _, tt := range tests {
Expand All @@ -57,17 +57,19 @@ func TestAddonsList(t *testing.T) {
if !buf.Scan() {
t.Fatalf("failed to read stdout")
}
pipeCount += strings.Count(buf.Text(), "|")
pipeCount += strings.Count(buf.Text(), "")
got += buf.Text()
}
if err := buf.Err(); err != nil {
t.Errorf("failed to read stdout: %v", err)
}
// The lines we pull should look something like
// |------------|------------|(------|)
// | ADDON NAME | MAINTAINER |( DOCS |)
// |------------|------------|(------|)
// which has 9 or 12 pipes
// ┌─────────────────────────────┬────────────────────────────────────────┐
// │ ADDON NAME │ MAINTAINER │
// ├─────────────────────────────┼────────────────────────────────────────┤
// ┌─────────────────────────────┬────────────────────────────────────────┬───────────────────────────────────────────────────────────────────────────────┐
// │ ADDON NAME │ MAINTAINER │ DOCS │
// ├─────────────────────────────┼────────────────────────────────────────┼───────────────────────────────────────────────────────────────────────────────┤

expected := tt.want
if pipeCount != expected {
t.Errorf("Expected header to have %d pipes; got = %d: %q", expected, pipeCount, got)
Expand Down
19 changes: 13 additions & 6 deletions cmd/minikube/cmd/config/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
"strings"

"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/tw"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/out"
Expand Down Expand Up @@ -63,17 +65,22 @@ func printAddonImagesTable(addon string) {

var tData [][]string
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Image Name", "Default Image", "Default Registry"})
table.SetAutoFormatHeaders(true)
table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
table.SetCenterSeparator("|")
table.Header([]string{"Image Name", "Default Image", "Default Registry"})
table.Header("Image Name", "Default Image", "Default Registry")
table.Options(
tablewriter.WithHeaderAutoFormat(tw.On),
)

for imageName, defaultImage := range conf.Images {
tData = append(tData, []string{imageName, defaultImage, conf.Registries[imageName]})
}

table.AppendBulk(tData)
table.Render()
if err := table.Bulk(tData); err != nil {
klog.Error("Error rendering table (bulk)", err)
}
if err := table.Render(); err != nil {
klog.Error("Error rendering table", err)
}
} else {
out.Infof("{{.name}} doesn't have images.", out.V{"name": addon})
}
Expand Down
25 changes: 15 additions & 10 deletions cmd/minikube/cmd/config/profile_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (

"github.com/docker/machine/libmachine"
"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/tw"
"github.com/spf13/cobra"

"k8s.io/klog/v2"
Expand Down Expand Up @@ -134,17 +135,21 @@ func profileStatus(p *config.Profile, api libmachine.API) cluster.State {
func renderProfilesTable(ps [][]string) {
table := tablewriter.NewWriter(os.Stdout)
if isDetailed {
table.SetHeader([]string{"Profile", "Driver", "Runtime", "IP", "Port", "Version",
"Status", "Nodes", "Active Profile", "Active Kubecontext"})
table.Header("Profile", "Driver", "Runtime", "IP", "Port", "Version",
"Status", "Nodes", "Active Profile", "Active Kubecontext")
} else {
table.SetHeader([]string{"Profile", "Driver", "Runtime", "IP", "Version", "Status",
"Nodes", "Active Profile", "Active Kubecontext"})
}
table.SetAutoFormatHeaders(false)
table.SetBorders(tablewriter.Border{Left: true, Top: true, Right: true, Bottom: true})
table.SetCenterSeparator("|")
table.AppendBulk(ps)
table.Render()
table.Header("Profile", "Driver", "Runtime", "IP", "Version", "Status",
"Nodes", "Active Profile", "Active Kubecontext")
}
table.Options(
tablewriter.WithHeaderAutoFormat(tw.Off),
)
if err := table.Bulk(ps); err != nil {
klog.Error("Error while bulk render table: ", err)
}
if err := table.Render(); err != nil {
klog.Error("Error while rendering profile table: ", err)
}
}

func profilesToTableData(profiles []*config.Profile) [][]string {
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ require (
github.com/mitchellh/go-ps v1.0.0
github.com/moby/hyperkit v0.0.0-20210108224842-2f061e447e14
github.com/moby/patternmatcher v0.6.0
github.com/olekukonko/tablewriter v0.0.5
github.com/olekukonko/tablewriter v1.0.8
github.com/opencontainers/cgroups v0.0.1
github.com/opencontainers/go-digest v1.0.0
github.com/otiai10/copy v1.14.1
Expand Down Expand Up @@ -181,6 +181,8 @@ require (
github.com/muesli/reflow v0.3.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6 // indirect
github.com/olekukonko/ll v0.0.8 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/otiai10/mint v1.6.3 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
Expand Down
9 changes: 6 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,6 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
Expand Down Expand Up @@ -1246,8 +1245,12 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6 h1:r3FaAI0NZK3hSmtTDrBVREhKULp8oUeqLT5Eyl2mSPo=
github.com/olekukonko/errors v0.0.0-20250405072817-4e6d85265da6/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=
github.com/olekukonko/ll v0.0.8 h1:sbGZ1Fx4QxJXEqL/6IG8GEFnYojUSQ45dJVwN2FH2fc=
github.com/olekukonko/ll v0.0.8/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
github.com/olekukonko/tablewriter v1.0.8 h1:f6wJzHg4QUtJdvrVPKco4QTrAylgaU0+b9br/lJxEiQ=
github.com/olekukonko/tablewriter v1.0.8/go.mod h1:H428M+HzoUXC6JU2Abj9IT9ooRmdq9CxuDmKMtrOCMs=
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
Loading