/
get.go
43 lines (41 loc) · 1.29 KB
/
get.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
package cluster
import (
_ "embed"
"fmt"
"github.com/argoproj/argo-cd/v2/util/cli"
"github.com/arlonproj/arlon/pkg/argocd"
"github.com/arlonproj/arlon/pkg/cluster"
"github.com/spf13/cobra"
"k8s.io/client-go/tools/clientcmd"
)
func getClusterCommand() *cobra.Command {
var clientConfig clientcmd.ClientConfig
var argocdNs string
var arlonNs string
command := &cobra.Command{
Use: "get <clustername> [flags]",
Short: "get information about existing cluster",
Long: "get information about existing cluster",
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
argoIf := argocd.NewArgocdClientOrDie("")
conn, appIf := argoIf.NewApplicationClientOrDie()
defer conn.Close()
config, err := clientConfig.ClientConfig()
if err != nil {
return fmt.Errorf("failed to get k8s client config: %s", err)
}
clusterName := args[0]
clust, err := cluster.Get(appIf, config, argocdNs, clusterName)
if err != nil {
return fmt.Errorf("failed to get cluster: %s", err)
}
fmt.Println(clust)
return nil
},
}
clientConfig = cli.AddKubectlFlagsToCmd(command)
command.Flags().StringVar(&argocdNs, "argocd-ns", "argocd", "the argocd namespace")
command.Flags().StringVar(&arlonNs, "arlon-ns", "arlon", "the arlon namespace")
return command
}