/
k8sDetails.go
60 lines (51 loc) · 1.45 KB
/
k8sDetails.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
package daiteapcli
import (
"encoding/json"
"fmt"
"os"
"github.com/Daiteap/daiteapcli/pkg/daiteapcli"
"github.com/spf13/cobra"
)
var k8sDetailsCmd = &cobra.Command{
SilenceUsage: true,
SilenceErrors: true,
Use: "details",
Aliases: []string{},
Short: "Command to get Kubernetes cluster's detail information",
Args: cobra.ExactArgs(0),
PreRunE: func(cmd *cobra.Command, args []string) error {
requiredFlags := []string{"cluster"}
checkForRequiredFlags(requiredFlags, cmd)
return nil
},
Run: func(cmd *cobra.Command, args []string) {
verbose, _ := cmd.Flags().GetString("verbose")
dryRun, _ := cmd.Flags().GetString("dry-run")
clusterID, _ := cmd.Flags().GetString("cluster")
isKubernetes, err := IsKubernetes(clusterID)
if err != nil {
fmt.Println(err)
os.Exit(0)
}
if isKubernetes == false {
fmt.Println("Please enter valid Kubernetes cluster ID")
os.Exit(0)
}
method := "GET"
endpoint := "/clusters/" + clusterID
responseBody, err := daiteapcli.SendDaiteapRequest(method, endpoint, "", "true", verbose, dryRun)
if err != nil {
fmt.Println(err)
} else if dryRun == "false" {
output, _ := json.MarshalIndent(responseBody, "", " ")
fmt.Println(string(output))
}
},
}
func init() {
k8sCmd.AddCommand(k8sDetailsCmd)
parameters := [][]interface{}{
[]interface{}{"cluster", "ID of the Kubernetes cluster", "string"},
}
addParameterFlags(parameters, k8sDetailsCmd)
}