Skip to content

Commit

Permalink
Merge pull request #631 from homeport/add/node-details
Browse files Browse the repository at this point in the history
Add node details in node-exec error
  • Loading branch information
HeavyWombat authored May 29, 2024
2 parents 2b99731 + 4ccf484 commit b302778
Show file tree
Hide file tree
Showing 24 changed files with 2,790 additions and 9 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/gonvenience/wrap v1.2.0
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/mattn/go-isatty v0.0.20
github.com/olekukonko/tablewriter v0.0.5
github.com/onsi/ginkgo/v2 v2.19.0
github.com/onsi/gomega v1.33.1
github.com/spf13/cobra v1.8.0
Expand Down Expand Up @@ -59,6 +60,7 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-ciede2000 v0.0.0-20170301095244-782e8c62fec3 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/spdystream v0.2.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ github.com/mattn/go-ciede2000 v0.0.0-20170301095244-782e8c62fec3 h1:BXxTozrOU8zg
github.com/mattn/go-ciede2000 v0.0.0-20170301095244-782e8c62fec3/go.mod h1:x1uk6vxTiVuNt6S5R2UYgdhpj3oKojXvOXauHZ7dEnI=
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.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
Expand All @@ -134,6 +136,8 @@ github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
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/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA=
github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To=
Expand Down
30 changes: 26 additions & 4 deletions internal/cmd/nexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package cmd

import (
"bytes"
"fmt"
"io"
"os"
Expand All @@ -35,6 +36,7 @@ import (

"github.com/gonvenience/bunt"
"github.com/homeport/havener/pkg/havener"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -300,13 +302,33 @@ func availableNodesError(h havener.Havener, title string, fArgs ...interface{})
return fmt.Errorf("failed to find any node in cluster")
}

names := make([]string, len(nodes))
for i, node := range nodes {
names[i] = node.Name
var buf bytes.Buffer
t := tablewriter.NewWriter(&buf)
t.SetBorder(false)
t.SetColumnSeparator("")
// t.SetAutoWrapText(false)
t.SetAlignment(tablewriter.ALIGN_LEFT)

for _, node := range nodes {
var tmp []string
for _, condition := range node.Status.Conditions {
if condition.Status == corev1.ConditionTrue {
tmp = append(tmp, string(condition.Type))
}
}

t.Append([]string{
node.Name,
strings.Join(tmp, ", "),
fmt.Sprintf("%s/%s", node.Status.NodeInfo.OperatingSystem, node.Status.NodeInfo.Architecture),
node.Status.NodeInfo.KubeletVersion,
})
}

t.Render()

return fmt.Errorf("%s: %w",
fmt.Sprintf(title, fArgs...),
bunt.Errorf("*list of available nodes:*\n%s\n\nor, use _all_ to target all nodes", strings.Join(names, "\n")),
bunt.Errorf("List of available nodes:\n%s\nAlternatively, use _all_ to target all nodes.", buf.String()),
)
}
26 changes: 21 additions & 5 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ import (
"github.com/gonvenience/wrap"
)

type wrappedError interface {
Error() string
Unwrap() error
}

func title(w wrappedError) string {
var parts = strings.SplitN(w.Error(), ":", 2)
return parts[0]
}

func cause(w wrappedError) string {
return w.Unwrap().Error()
}

var kubeConfig string

// rootCmd represents the base command when called without any subcommands
Expand Down Expand Up @@ -72,25 +86,27 @@ func Execute() {
}()

if err := rootCmd.Execute(); err != nil {
var (
headline string
content string
)
var headline, content string

switch err := err.(type) {
case wrap.ContextError:
headline = bunt.Sprintf("*Error:* _%s_", err.Context())
content = err.Cause().Error()

case wrappedError:
headline = title(err)
content = cause(err)

default:
headline = "Error occurred"
content = fmt.Sprint(err)
content = err.Error()
}

neat.Box(os.Stderr,
headline, strings.NewReader(content),
neat.HeadlineColor(bunt.Coral),
neat.ContentColor(bunt.DimGray),
neat.NoLineWrap(),
)

os.Exit(1)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/mattn/go-runewidth/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b302778

Please sign in to comment.