/
cluster.go
50 lines (46 loc) · 1.47 KB
/
cluster.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
package cluster
import (
"context"
"fmt"
"os"
apppkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
"github.com/argoproj/argo-cd/v2/util/io"
"github.com/arlonproj/arlon/pkg/argocd"
"github.com/spf13/cobra"
)
func NewCommand() *cobra.Command {
command := &cobra.Command{
Use: "cluster",
Short: "Manage clusters",
Long: "Manage clusters",
DisableAutoGenTag: true,
PersistentPreRun: checkForArgocd,
Run: func(c *cobra.Command, args []string) {
c.Usage()
},
}
// `cluster deploy` is only for gen1 clusters
//command.AddCommand(deployClusterCommand())
command.AddCommand(listClustersCommand())
// `cluster update` is only for gen1 clusters
//command.AddCommand(updateClusterCommand())
command.AddCommand(manageClusterCommand())
command.AddCommand(unmanageClusterCommand())
command.AddCommand(createClusterCommand())
command.AddCommand(getClusterCommand())
command.AddCommand(deleteClusterCommand())
command.AddCommand(ngupdateClusterCommand())
command.AddCommand(setAppProfilesCommand())
return command
}
func checkForArgocd(c *cobra.Command, args []string) {
conn, appIf := argocd.NewArgocdClientOrDie("").NewApplicationClientOrDie()
defer io.Close(conn)
query := "managed-by=arlon,arlon-type=cluster"
_, err := appIf.List(context.Background(), &apppkg.ApplicationQuery{Selector: &query})
if err != nil {
fmt.Println("ArgoCD auth token has expired....Login to ArgoCD again")
fmt.Println(err)
os.Exit(1)
}
}