-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
84 lines (64 loc) · 1.81 KB
/
get.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"os"
"github.com/kubicorn/kubicorn/pkg/logger"
"github.com/spf13/cobra"
"github.com/weaveworks/eksctl/pkg/eks"
"github.com/weaveworks/eksctl/pkg/eks/api"
)
const (
DEFAULT_CHUNK_SIZE = 100
)
var (
chunkSize int
output string
)
func getCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "get",
Short: "Get resource(s)",
Run: func(c *cobra.Command, _ []string) {
c.Help()
},
}
cmd.AddCommand(getClusterCmd())
return cmd
}
func getClusterCmd() *cobra.Command {
cfg := &api.ClusterConfig{}
cmd := &cobra.Command{
Use: "cluster",
Short: "Get cluster(s)",
Aliases: []string{"clusters"},
Run: func(_ *cobra.Command, args []string) {
if err := doGetCluster(cfg, getNameArg(args)); err != nil {
logger.Critical("%s\n", err.Error())
os.Exit(1)
}
},
}
fs := cmd.Flags()
fs.StringVarP(&cfg.ClusterName, "name", "n", "", "EKS cluster name")
fs.IntVar(&chunkSize, "chunk-size", DEFAULT_CHUNK_SIZE, "Return large lists in chunks rather than all at once. Pass 0 to disable.")
fs.StringVarP(&cfg.Region, "region", "r", api.DEFAULT_EKS_REGION, "AWS region")
fs.StringVarP(&cfg.Profile, "profile", "p", "", "AWS credentials profile to use (overrides the AWS_PROFILE environment variable)")
fs.StringVarP(&output, "output", "o", "table", "Specifies the output format. Choose from table,json,yaml. Defaults to table.")
return cmd
}
func doGetCluster(cfg *api.ClusterConfig, name string) error {
ctl := eks.New(cfg)
if err := ctl.CheckAuth(); err != nil {
return err
}
if cfg.ClusterName != "" && name != "" {
return fmt.Errorf("--name=%s and argument %s cannot be used at the same time", cfg.ClusterName, name)
}
if name != "" {
cfg.ClusterName = name
}
if err := ctl.ListClusters(chunkSize, output); err != nil {
return err
}
return nil
}