forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
132 lines (114 loc) · 5.06 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"context"
"fmt"
"os"
"time"
log "github.com/sirupsen/logrus"
"github.com/argoproj/argo/workflow/cron"
"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
containerRuntimeExecutor string
logLevel string // --loglevel
glogLevel int // --gloglevel
workflowWorkers int // --workflow-workers
podWorkers int // --pod-workers
namespaced bool // --namespaced
managedNamespace string // --managed-namespace
)
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)
wfclientset := wfclientset.NewForConfigOrDie(config)
if !namespaced && managedNamespace != "" {
log.Warn("ignoring --managed-namespace because --namespaced is false")
managedNamespace = ""
}
if namespaced && managedNamespace == "" {
managedNamespace = namespace
}
// start a controller on instances of our custom resource
wfController := controller.NewWorkflowController(config, kubeclientset, wfclientset, namespace, managedNamespace, executorImage, executorImagePullPolicy, containerRuntimeExecutor, configMap)
err = wfController.ResyncConfig()
if err != nil {
return err
}
// TODO: following code will be updated in next major release to remove configmap
// setting for namespace installation mode.
if len(wfController.Config.Namespace) > 0 {
fmt.Fprintf(os.Stderr, "\n------------------------ WARNING ------------------------\n")
fmt.Fprintf(os.Stderr, "Namespaced installation with configmap setting is deprecated, \n")
fmt.Fprintf(os.Stderr, "it will be removed in next major release. Instead please add \n")
fmt.Fprintf(os.Stderr, "\"--namespaced\" to workflow-controller start args.\n")
fmt.Fprintf(os.Stderr, "-----------------------------------------------------------------\n\n")
}
cronController := cron.NewCronController(wfclientset, config, namespace, wfController.GetManagedNamespace())
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)
go cronController.Run(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(&containerRuntimeExecutor, "container-runtime-executor", "", "Container runtime executor 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")
command.Flags().BoolVar(&namespaced, "namespaced", false, "run workflow-controller as namespaced mode")
command.Flags().StringVar(&managedNamespace, "managed-namespace", "", "namespace that workflow-controller watches, default to the installation namespace")
return &command
}
func main() {
if err := NewRootCommand().Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}