/
supported.go
78 lines (68 loc) · 2.12 KB
/
supported.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
package apis
import (
"errors"
"fmt"
"sort"
"time"
k8sclient "github.com/aws/aws-k8s-tester/pkg/k8s-client"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
func newSupportedCommand() *cobra.Command {
ac := &cobra.Command{
Use: "supported",
SuggestFor: []string{"support", "getsupportedapis", "getsupportedapi", "apiresources", "apiresource", "api-resource"},
Run: supportedFunc,
Short: "List all supported APIs",
Long: `
eks-utils apis \
--kubeconfig /tmp/kubeconfig.yaml \
supported
eks-utils apis \
--kubeconfig ~/.kube/config \
--kubeconfig-context prow-hkg \
supported
`,
}
ac.PersistentFlags().Float32Var(&clientQPS, "client-qps", 5.0, "EKS client qps")
ac.PersistentFlags().IntVar(&clientBurst, "client-burst", 10, "EKS client burst")
ac.PersistentFlags().StringVar(&kubeConfigPath, "kubeconfig", "", "EKS KUBECONFIG")
ac.PersistentFlags().StringVar(&kubeConfigContext, "kubeconfig-context", "", "EKS KUBECONFIG context")
ac.PersistentFlags().StringVar(&kubectlPath, "kubectl", defaultKubectlPath, "kubectl path")
return ac
}
func supportedFunc(cmd *cobra.Command, args []string) {
if kubectlPath == "" {
panic(errors.New("'kubectl' not found"))
}
fmt.Printf("\n\n************************\nstarting 'eks-utils apis supported'\n\n")
lg := zap.NewExample()
kcfg := &k8sclient.EKSConfig{
KubeConfigPath: kubeConfigPath,
KubeConfigContext: kubeConfigContext,
KubectlPath: kubectlPath,
Clients: 1,
ClientQPS: clientQPS,
ClientBurst: clientBurst,
ClientTimeout: 30 * time.Second,
}
cli, err := k8sclient.NewEKS(kcfg)
if err != nil {
lg.Fatal("failed to create client", zap.Error(err))
}
vv, apiVersions, err := cli.FetchSupportedAPIGroupVersions()
if err != nil {
panic(fmt.Errorf("failed to check health %v", err))
}
ss := make([]string, 0, len(apiVersions))
fmt.Printf("\n\n************************\nchecking supported API group veresion for %.2f\n\n", vv)
for k := range apiVersions {
ss = append(ss, k)
}
sort.Strings(ss)
for _, v := range ss {
fmt.Println(v)
}
println()
fmt.Println("'eks-utils apis supported' success")
}