forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
103 lines (88 loc) · 3.38 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"context"
"fmt"
"os"
"time"
"github.com/argoproj/pkg/cli"
kubecli "github.com/argoproj/pkg/kube/cli"
"github.com/argoproj/pkg/stats"
"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/azure"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
"k8s.io/client-go/tools/clientcmd"
wfclientset "github.com/argoproj/argo/pkg/client/clientset/versioned"
cmdutil "github.com/argoproj/argo/util/cmd"
"github.com/argoproj/argo/workflow/controller"
)
const (
// CLIName is the name of the CLI
CLIName = "workflow-controller"
)
// NewRootCommand returns an new instance of the workflow-controller main entrypoint
func NewRootCommand() *cobra.Command {
var (
clientConfig clientcmd.ClientConfig
configMap string // --configmap
executorImage string // --executor-image
executorImagePullPolicy string // --executor-image-pull-policy
logLevel string // --loglevel
glogLevel int // --gloglevel
workflowWorkers int // --workflow-workers
podWorkers int // --pod-workers
)
var command = cobra.Command{
Use: CLIName,
Short: "workflow-controller is the controller to operate on workflows",
RunE: func(c *cobra.Command, args []string) error {
cli.SetLogLevel(logLevel)
cli.SetGLogLevel(glogLevel)
stats.RegisterStackDumper()
stats.StartStatsTicker(5 * time.Minute)
config, err := clientConfig.ClientConfig()
if err != nil {
return err
}
config.Burst = 30
config.QPS = 20.0
namespace, _, err := clientConfig.Namespace()
if err != nil {
return err
}
kubeclientset := kubernetes.NewForConfigOrDie(config)
wflientset := wfclientset.NewForConfigOrDie(config)
// start a controller on instances of our custom resource
wfController := controller.NewWorkflowController(config, kubeclientset, wflientset, namespace, executorImage, executorImagePullPolicy, configMap)
err = wfController.ResyncConfig()
if err != nil {
return err
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go wfController.Run(ctx, workflowWorkers, podWorkers)
go wfController.MetricsServer(ctx)
go wfController.TelemetryServer(ctx)
go wfController.RunTTLController(ctx)
// Wait forever
select {}
},
}
clientConfig = kubecli.AddKubectlFlagsToCmd(&command)
command.AddCommand(cmdutil.NewVersionCmd(CLIName))
command.Flags().StringVar(&configMap, "configmap", "workflow-controller-configmap", "Name of K8s configmap to retrieve workflow controller configuration")
command.Flags().StringVar(&executorImage, "executor-image", "", "Executor image to use (overrides value in configmap)")
command.Flags().StringVar(&executorImagePullPolicy, "executor-image-pull-policy", "", "Executor imagePullPolicy to use (overrides value in configmap)")
command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
command.Flags().IntVar(&glogLevel, "gloglevel", 0, "Set the glog logging level")
command.Flags().IntVar(&workflowWorkers, "workflow-workers", 8, "Number of workflow workers")
command.Flags().IntVar(&podWorkers, "pod-workers", 8, "Number of pod workers")
return &command
}
func main() {
if err := NewRootCommand().Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}