-
Notifications
You must be signed in to change notification settings - Fork 20
/
describeNodeCommand.go
56 lines (47 loc) · 1.29 KB
/
describeNodeCommand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"os"
"github.com/ernoaapa/eliot/cmd"
"github.com/ernoaapa/eliot/pkg/api"
"github.com/ernoaapa/eliot/pkg/config"
"github.com/ernoaapa/eliot/pkg/printers"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
var describeNodeCommand = cli.Command{
Name: "node",
Aliases: []string{"nodes", "device"}, // device is deprecated command
Usage: "Return details of node",
UsageText: `eli describe node [options] [NAME | IP]
# Describe node
eli describe node my-node
# Describe all pods
eli describe nodes
`,
Action: func(clicontext *cli.Context) error {
cfg := cmd.GetConfigProvider(clicontext)
podName := clicontext.Args().First()
endpoints := cfg.GetEndpoints()
if podName != "" {
endpoint, ok := cfg.GetEndpointByName(podName)
if !ok {
return fmt.Errorf("No endpoint found with name %s", podName)
}
endpoints = []config.Endpoint{endpoint}
}
writer := printers.GetNewTabWriter(os.Stdout)
defer writer.Flush()
printer := cmd.GetPrinter(clicontext)
for _, endpoint := range endpoints {
info, err := api.NewClient(cfg.GetNamespace(), endpoint).GetInfo()
if err != nil {
return errors.Wrap(err, "Failed to fetch node info")
}
if err := printer.PrintNode(info, writer); err != nil {
return err
}
}
return nil
},
}