|
1 |
| -package controller |
| 1 | +package config |
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "context" |
5 |
| - "fmt" |
6 |
| - |
7 |
| - apiv1 "k8s.io/api/core/v1" |
8 |
| - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
9 |
| - "k8s.io/apimachinery/pkg/fields" |
10 |
| - "k8s.io/apimachinery/pkg/runtime" |
11 |
| - "k8s.io/apimachinery/pkg/watch" |
12 |
| - "k8s.io/client-go/tools/cache" |
13 |
| - |
14 |
| - "github.com/argoproj/argo/errors" |
15 | 4 | wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
|
16 |
| - "github.com/argoproj/argo/workflow/common" |
17 | 5 | "github.com/argoproj/argo/workflow/metrics"
|
18 |
| - "github.com/ghodss/yaml" |
19 |
| - log "github.com/sirupsen/logrus" |
| 6 | + apiv1 "k8s.io/api/core/v1" |
20 | 7 | )
|
21 | 8 |
|
22 | 9 | // WorkflowControllerConfig contain the configuration settings for the workflow controller
|
@@ -70,6 +57,9 @@ type WorkflowControllerConfig struct {
|
70 | 57 | // Parallelism limits the max total parallel workflows that can execute at the same time
|
71 | 58 | Parallelism int `json:"parallelism,omitempty"`
|
72 | 59 |
|
| 60 | + // Persistence contains the workflow persistence DB configuration |
| 61 | + Persistence *PersistConfig `json:"persistence,omitempty"` |
| 62 | + |
73 | 63 | // Config customized Docker Sock path
|
74 | 64 | DockerSockPath string `json:"dockerSockPath,omitempty"`
|
75 | 65 | }
|
@@ -101,6 +91,35 @@ type ArtifactRepository struct {
|
101 | 91 | HDFS *HDFSArtifactRepository `json:"hdfs,omitempty"`
|
102 | 92 | }
|
103 | 93 |
|
| 94 | +type PersistConfig struct { |
| 95 | + NodeStatusOffload bool `json:"nodeStatusOffLoad"` |
| 96 | + ConnectionPool *ConnectionPool `json:"connectionPool"` |
| 97 | + PostgreSQL *PostgreSQLConfig `json:"postgresql,omitempty"` |
| 98 | + MySQL *MySQLConfig `json:"mysql,omitempty"` |
| 99 | +} |
| 100 | +type ConnectionPool struct { |
| 101 | + MaxIdleConns int `json:"maxIdleConns"` |
| 102 | + MaxOpenConns int `json:"maxOpenConns"` |
| 103 | +} |
| 104 | +type PostgreSQLConfig struct { |
| 105 | + Host string `json:"host"` |
| 106 | + Port string `json:"port"` |
| 107 | + Database string `json:"database"` |
| 108 | + TableName string `json:"tableName"` |
| 109 | + UsernameSecret apiv1.SecretKeySelector `json:"userNameSecret"` |
| 110 | + PasswordSecret apiv1.SecretKeySelector `json:"passwordSecret"` |
| 111 | +} |
| 112 | + |
| 113 | +type MySQLConfig struct { |
| 114 | + Host string `json:"host"` |
| 115 | + Port string `json:"port"` |
| 116 | + Database string `json:"database"` |
| 117 | + TableName string `json:"tableName"` |
| 118 | + Options map[string]string `json:"options"` |
| 119 | + UsernameSecret apiv1.SecretKeySelector `json:"userNameSecret"` |
| 120 | + PasswordSecret apiv1.SecretKeySelector `json:"passwordSecret"` |
| 121 | +} |
| 122 | + |
104 | 123 | // S3ArtifactRepository defines the controller configuration for an S3 artifact repository
|
105 | 124 | type S3ArtifactRepository struct {
|
106 | 125 | wfv1.S3Bucket `json:",inline"`
|
@@ -130,114 +149,3 @@ type HDFSArtifactRepository struct {
|
130 | 149 | // Force copies a file forcibly even if it exists (default: false)
|
131 | 150 | Force bool `json:"force,omitempty"`
|
132 | 151 | }
|
133 |
| - |
134 |
| -// ResyncConfig reloads the controller config from the configmap |
135 |
| -func (wfc *WorkflowController) ResyncConfig() error { |
136 |
| - cmClient := wfc.kubeclientset.CoreV1().ConfigMaps(wfc.namespace) |
137 |
| - cm, err := cmClient.Get(wfc.configMap, metav1.GetOptions{}) |
138 |
| - if err != nil { |
139 |
| - return errors.InternalWrapError(err) |
140 |
| - } |
141 |
| - return wfc.updateConfig(cm) |
142 |
| -} |
143 |
| - |
144 |
| -func (wfc *WorkflowController) updateConfig(cm *apiv1.ConfigMap) error { |
145 |
| - configStr, ok := cm.Data[common.WorkflowControllerConfigMapKey] |
146 |
| - if !ok { |
147 |
| - log.Warnf("ConfigMap '%s' does not have key '%s'", wfc.configMap, common.WorkflowControllerConfigMapKey) |
148 |
| - return nil |
149 |
| - } |
150 |
| - var config WorkflowControllerConfig |
151 |
| - err := yaml.Unmarshal([]byte(configStr), &config) |
152 |
| - if err != nil { |
153 |
| - return errors.InternalWrapError(err) |
154 |
| - } |
155 |
| - log.Printf("workflow controller configuration from %s:\n%s", wfc.configMap, configStr) |
156 |
| - if wfc.cliExecutorImage == "" && config.ExecutorImage == "" { |
157 |
| - return errors.Errorf(errors.CodeBadRequest, "ConfigMap '%s' does not have executorImage", wfc.configMap) |
158 |
| - } |
159 |
| - wfc.Config = config |
160 |
| - wfc.throttler.SetParallelism(config.Parallelism) |
161 |
| - return nil |
162 |
| -} |
163 |
| - |
164 |
| -// executorImage returns the image to use for the workflow executor |
165 |
| -func (wfc *WorkflowController) executorImage() string { |
166 |
| - if wfc.cliExecutorImage != "" { |
167 |
| - return wfc.cliExecutorImage |
168 |
| - } |
169 |
| - return wfc.Config.ExecutorImage |
170 |
| -} |
171 |
| - |
172 |
| -// executorImagePullPolicy returns the imagePullPolicy to use for the workflow executor |
173 |
| -func (wfc *WorkflowController) executorImagePullPolicy() apiv1.PullPolicy { |
174 |
| - if wfc.cliExecutorImagePullPolicy != "" { |
175 |
| - return apiv1.PullPolicy(wfc.cliExecutorImagePullPolicy) |
176 |
| - } else if wfc.Config.Executor != nil && wfc.Config.Executor.ImagePullPolicy != "" { |
177 |
| - return wfc.Config.Executor.ImagePullPolicy |
178 |
| - } else { |
179 |
| - return apiv1.PullPolicy(wfc.Config.ExecutorImagePullPolicy) |
180 |
| - } |
181 |
| -} |
182 |
| - |
183 |
| -func (wfc *WorkflowController) watchControllerConfigMap(ctx context.Context) (cache.Controller, error) { |
184 |
| - source := wfc.newControllerConfigMapWatch() |
185 |
| - _, controller := cache.NewInformer( |
186 |
| - source, |
187 |
| - &apiv1.ConfigMap{}, |
188 |
| - 0, |
189 |
| - cache.ResourceEventHandlerFuncs{ |
190 |
| - AddFunc: func(obj interface{}) { |
191 |
| - if cm, ok := obj.(*apiv1.ConfigMap); ok { |
192 |
| - log.Infof("Detected ConfigMap update. Updating the controller config.") |
193 |
| - err := wfc.updateConfig(cm) |
194 |
| - if err != nil { |
195 |
| - log.Errorf("Update of config failed due to: %v", err) |
196 |
| - } |
197 |
| - } |
198 |
| - }, |
199 |
| - UpdateFunc: func(old, new interface{}) { |
200 |
| - oldCM := old.(*apiv1.ConfigMap) |
201 |
| - newCM := new.(*apiv1.ConfigMap) |
202 |
| - if oldCM.ResourceVersion == newCM.ResourceVersion { |
203 |
| - return |
204 |
| - } |
205 |
| - if newCm, ok := new.(*apiv1.ConfigMap); ok { |
206 |
| - log.Infof("Detected ConfigMap update. Updating the controller config.") |
207 |
| - err := wfc.updateConfig(newCm) |
208 |
| - if err != nil { |
209 |
| - log.Errorf("Update of config failed due to: %v", err) |
210 |
| - } |
211 |
| - } |
212 |
| - }, |
213 |
| - }) |
214 |
| - |
215 |
| - go controller.Run(ctx.Done()) |
216 |
| - return controller, nil |
217 |
| -} |
218 |
| - |
219 |
| -func (wfc *WorkflowController) newControllerConfigMapWatch() *cache.ListWatch { |
220 |
| - c := wfc.kubeclientset.CoreV1().RESTClient() |
221 |
| - resource := "configmaps" |
222 |
| - name := wfc.configMap |
223 |
| - fieldSelector := fields.ParseSelectorOrDie(fmt.Sprintf("metadata.name=%s", name)) |
224 |
| - |
225 |
| - listFunc := func(options metav1.ListOptions) (runtime.Object, error) { |
226 |
| - options.FieldSelector = fieldSelector.String() |
227 |
| - req := c.Get(). |
228 |
| - Namespace(wfc.namespace). |
229 |
| - Resource(resource). |
230 |
| - VersionedParams(&options, metav1.ParameterCodec) |
231 |
| - return req.Do().Get() |
232 |
| - } |
233 |
| - watchFunc := func(options metav1.ListOptions) (watch.Interface, error) { |
234 |
| - options.Watch = true |
235 |
| - options.FieldSelector = fieldSelector.String() |
236 |
| - req := c.Get(). |
237 |
| - Namespace(wfc.namespace). |
238 |
| - Resource(resource). |
239 |
| - VersionedParams(&options, metav1.ParameterCodec) |
240 |
| - return req.Watch() |
241 |
| - } |
242 |
| - return &cache.ListWatch{ListFunc: listFunc, WatchFunc: watchFunc} |
243 |
| -} |
0 commit comments