forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
76 lines (63 loc) · 2.07 KB
/
main.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
72
73
74
75
76
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/argoproj/argo-cd/application"
"github.com/argoproj/argo-cd/cmd/argocd/commands"
"github.com/argoproj/argo-cd/controller"
appclientset "github.com/argoproj/argo-cd/pkg/client/clientset/versioned"
"github.com/argoproj/argo-cd/server/repository"
"github.com/argoproj/argo-cd/util/git"
"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
const (
// CLIName is the name of the CLI
cliName = "application-controller"
)
func newCommand() *cobra.Command {
var (
kubeConfigOverrides clientcmd.ConfigOverrides
kubeConfigPath string
)
var command = cobra.Command{
Use: cliName,
Short: "application-controller is a controller to operate on applications CRD",
RunE: func(c *cobra.Command, args []string) error {
kubeConfig := commands.GetKubeConfig(kubeConfigPath, kubeConfigOverrides)
nativeGitClient, err := git.NewNativeGitClient()
if err != nil {
return err
}
kubeClient := kubernetes.NewForConfigOrDie(kubeConfig)
appClient := appclientset.NewForConfigOrDie(kubeConfig)
// TODO (amatyushentsev): Use config map to store controller configuration
namespace := "default"
appResyncPeriod := time.Minute * 10
appManager := application.NewAppManager(
nativeGitClient,
repository.NewServer(namespace, kubeClient, appClient),
application.NewKsonnetAppComparator(),
appResyncPeriod)
appController := controller.NewApplicationController(kubeClient, appClient, appManager, appResyncPeriod)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go appController.Run(ctx, 1)
// Wait forever
select {}
},
}
command.Flags().StringVar(&kubeConfigPath, "kubeconfig", "", "Path to the config file to use for CLI requests.")
kubeConfigOverrides = clientcmd.ConfigOverrides{}
clientcmd.BindOverrideFlags(&kubeConfigOverrides, command.Flags(), clientcmd.RecommendedConfigOverrideFlags(""))
return &command
}
func main() {
if err := newCommand().Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}