/
eks-config-cmd.go
71 lines (62 loc) · 1.89 KB
/
eks-config-cmd.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
package clustercmd
import (
"fmt"
"github.com/Appkube-awsx/awsx-common/authenticate"
"log"
"github.com/Appkube-awsx/awsx-common/client"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/eks"
"github.com/spf13/cobra"
)
// getConfigDataCmd represents the getConfigData command
var GetConfigDataCmd = &cobra.Command{
Use: "getConfigData",
Short: "config data for eks cluster",
Long: `config data for eks cluster`,
Run: func(cmd *cobra.Command, args []string) {
authFlag, clientAuth, err := authenticate.SubCommandAuth(cmd)
if err != nil {
cmd.Help()
return
}
if authFlag {
clusterName, _ := cmd.Flags().GetString("clusterName")
if clusterName != "" {
getClusterDetails(clusterName, *clientAuth)
} else {
log.Fatalln("cluster name not provided. program exit")
}
}
},
}
func getClusterDetails(clusterName string, auth client.Auth) *eks.DescribeClusterOutput {
log.Println("Getting aws eks cluster data")
listClusterClient := client.GetClient(auth, client.EKS_CLIENT).(*eks.EKS)
input := &eks.DescribeClusterInput{
Name: aws.String(clusterName),
}
clusterDetailsResponse, err := listClusterClient.DescribeCluster(input)
log.Println(clusterDetailsResponse.String())
if err != nil {
log.Fatalln("Error:", err)
}
return clusterDetailsResponse
}
func GetCluster(eksClient *eks.EKS, clusterName string) *eks.DescribeClusterOutput {
log.Println("Getting aws cluster detail for cluster: ", clusterName)
input := &eks.DescribeClusterInput{
Name: aws.String(clusterName),
}
clusterDetailsResponse, err := eksClient.DescribeCluster(input)
log.Println(clusterDetailsResponse.String())
if err != nil {
log.Fatalln("Error:", err)
}
return clusterDetailsResponse
}
func init() {
GetConfigDataCmd.Flags().StringP("clusterName", "c", "", "cluster name")
if err := GetConfigDataCmd.MarkFlagRequired("clusterName"); err != nil {
fmt.Println(err)
}
}