/
check.go
55 lines (48 loc) · 1.08 KB
/
check.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
package eks
import (
"fmt"
"os"
"github.com/aws/aws-k8s-tester/eks"
"github.com/aws/aws-k8s-tester/eksconfig"
"github.com/spf13/cobra"
)
func newCheck() *cobra.Command {
ac := &cobra.Command{
Use: "check <subcommand>",
Short: "Check EKS resources",
}
ac.AddCommand(
newCheckCluster(),
)
return ac
}
func newCheckCluster() *cobra.Command {
return &cobra.Command{
Use: "cluster",
Short: "Check EKS cluster status",
Run: checkClusterFunc,
}
}
func checkClusterFunc(cmd *cobra.Command, args []string) {
cfg, err := eksconfig.Load(path)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to load configuration %q (%v)\n", path, err)
os.Exit(1)
}
tester, err := eks.New(cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create EKS deployer %v\n", err)
os.Exit(1)
}
var up bool
up, err = tester.IsUp()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to check cluster status %v\n", err)
os.Exit(1)
}
if !up {
fmt.Fprintln(os.Stderr, "failed to check cluster status: not up")
os.Exit(1)
}
fmt.Println("'aws-k8s-tester eks check cluster' success")
}