|
| 1 | +package apis |
| 2 | + |
| 3 | +import ( |
| 4 | + "errors" |
| 5 | + "fmt" |
| 6 | + "sort" |
| 7 | + |
| 8 | + k8sclient "github.com/aws/aws-k8s-tester/pkg/k8s-client" |
| 9 | + "github.com/spf13/cobra" |
| 10 | + "go.uber.org/zap" |
| 11 | +) |
| 12 | + |
| 13 | +func newSupportedCommand() *cobra.Command { |
| 14 | + ac := &cobra.Command{ |
| 15 | + Use: "supported", |
| 16 | + SuggestFor: []string{"support", "getsupportedapis", "getsupportedapi", "apiresources", "apiresource", "api-resource"}, |
| 17 | + Run: supportedFunc, |
| 18 | + Short: "List all supported APIs", |
| 19 | + Long: ` |
| 20 | +eks-utils apis \ |
| 21 | + --kubeconfig /tmp/kubeconfig.yaml \ |
| 22 | + supported |
| 23 | +
|
| 24 | +eks-utils apis \ |
| 25 | + --kubeconfig ~/.kube/config \ |
| 26 | + --kubeconfig-context prow-hkg \ |
| 27 | + supported |
| 28 | +`, |
| 29 | + } |
| 30 | + ac.PersistentFlags().Float32Var(&clientQPS, "client-qps", 5.0, "EKS client qps") |
| 31 | + ac.PersistentFlags().IntVar(&clientBurst, "client-burst", 10, "EKS client burst") |
| 32 | + ac.PersistentFlags().StringVar(&kubeConfigPath, "kubeconfig", "", "EKS KUBECONFIG") |
| 33 | + ac.PersistentFlags().StringVar(&kubeConfigContext, "kubeconfig-context", "", "EKS KUBECONFIG context") |
| 34 | + ac.PersistentFlags().StringVar(&kubectlPath, "kubectl", defaultKubectlPath, "kubectl path") |
| 35 | + return ac |
| 36 | +} |
| 37 | + |
| 38 | +func supportedFunc(cmd *cobra.Command, args []string) { |
| 39 | + if kubectlPath == "" { |
| 40 | + panic(errors.New("'kubectl' not found")) |
| 41 | + } |
| 42 | + fmt.Printf("\n\n************************\nstarting 'eks-utils apis supported'\n\n") |
| 43 | + |
| 44 | + lg := zap.NewExample() |
| 45 | + |
| 46 | + kcfg := &k8sclient.EKSConfig{ |
| 47 | + Logger: lg, |
| 48 | + ClientQPS: clientQPS, |
| 49 | + ClientBurst: clientBurst, |
| 50 | + KubeConfigPath: kubeConfigPath, |
| 51 | + KubeConfigContext: kubeConfigContext, |
| 52 | + KubectlPath: kubectlPath, |
| 53 | + } |
| 54 | + cli, err := k8sclient.NewEKS(kcfg) |
| 55 | + if err != nil { |
| 56 | + lg.Fatal("failed to create client", zap.Error(err)) |
| 57 | + } |
| 58 | + |
| 59 | + vv, apiVersions, err := cli.FetchSupportedAPIGroupVersions() |
| 60 | + if err != nil { |
| 61 | + panic(fmt.Errorf("failed to check health %v", err)) |
| 62 | + } |
| 63 | + ss := make([]string, 0, len(apiVersions)) |
| 64 | + |
| 65 | + fmt.Printf("\n\n************************\nchecking supported API group veresion for %.2f\n\n", vv) |
| 66 | + for k := range apiVersions { |
| 67 | + ss = append(ss, k) |
| 68 | + } |
| 69 | + sort.Strings(ss) |
| 70 | + for _, v := range ss { |
| 71 | + fmt.Println(v) |
| 72 | + } |
| 73 | + |
| 74 | + println() |
| 75 | + fmt.Println("'eks-utils apis supported' success") |
| 76 | +} |
0 commit comments