-
Notifications
You must be signed in to change notification settings - Fork 6
/
command.go
96 lines (77 loc) · 2.3 KB
/
command.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
85
86
87
88
89
90
91
92
93
94
95
96
package nodepools
import (
"io"
"os"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"github.com/spf13/afero"
"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"
"github.com/giantswarm/kubectl-gs/pkg/middleware"
"github.com/giantswarm/kubectl-gs/pkg/middleware/renewtoken"
)
const (
name = "nodepools [nodepool-id]"
alias = "nodepool"
shortDescription = "Display one or many node pools"
longDescription = `Display one or many node pools
Output columns:
- ID: Unique identifier of the node pool.
- CLUSTER ID: Unique identifier of the cluster that the node pool belongs to.
- CREATED: Date and time of the node pool CR creation.
- CONDITION: Latest condition reported for the node pool.
- NODES MIN/MAX: Node pool autoscaler settings (if supported).
- NODES DESIRED: The total number of nodes that the node pool should have.
- NODES READY: The number of nodes in the node pool that are actually ready.
- DESCRIPTION: User friendly description for the node pool.`
examples = ` # List all node pools you have access to
kubectl gs get nodepools
# Get one specific nodepool by its ID
kubectl gs get nodepool 3f01a`
)
type Config struct {
Logger micrologger.Logger
FileSystem afero.Fs
K8sConfigAccess clientcmd.ConfigAccess
Stderr io.Writer
Stdout io.Writer
}
func New(config Config) (*cobra.Command, error) {
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}
if config.FileSystem == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.FileSystem must not be empty", config)
}
if config.K8sConfigAccess == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.K8sConfigAccess must not be empty", config)
}
if config.Stderr == nil {
config.Stderr = os.Stderr
}
if config.Stdout == nil {
config.Stdout = os.Stdout
}
f := &flag{}
r := &runner{
flag: f,
logger: config.Logger,
fs: config.FileSystem,
stderr: config.Stderr,
stdout: config.Stdout,
}
c := &cobra.Command{
Use: name,
Short: shortDescription,
Long: longDescription,
Example: examples,
Aliases: []string{alias},
Args: cobra.MaximumNArgs(1),
RunE: r.Run,
PreRunE: middleware.Compose(
renewtoken.Middleware(config.K8sConfigAccess),
),
}
f.Init(c)
return c, nil
}