1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.curoverse.com/arvados.git/sdk/go/arvados"
14 "github.com/ghodss/yaml"
17 type deprRequestLimits struct {
18 MaxItemsPerResponse *int
19 MultiClusterRequestConcurrency *int
22 type deprCluster struct {
23 RequestLimits deprRequestLimits
24 NodeProfiles map[string]nodeProfile
27 type deprecatedConfig struct {
28 Clusters map[string]deprCluster
31 type nodeProfile struct {
32 Controller systemServiceInstance `json:"arvados-controller"`
33 Health systemServiceInstance `json:"arvados-health"`
34 Keepbalance systemServiceInstance `json:"keep-balance"`
35 Keepproxy systemServiceInstance `json:"keepproxy"`
36 Keepstore systemServiceInstance `json:"keepstore"`
37 Keepweb systemServiceInstance `json:"keep-web"`
38 Nodemanager systemServiceInstance `json:"arvados-node-manager"`
39 DispatchCloud systemServiceInstance `json:"arvados-dispatch-cloud"`
40 RailsAPI systemServiceInstance `json:"arvados-api-server"`
41 Websocket systemServiceInstance `json:"arvados-ws"`
42 Workbench1 systemServiceInstance `json:"arvados-workbench"`
45 type systemServiceInstance struct {
51 func (ldr *Loader) applyDeprecatedConfig(cfg *arvados.Config) error {
52 var dc deprecatedConfig
53 err := yaml.Unmarshal(ldr.configdata, &dc)
57 hostname, err := os.Hostname()
61 for id, dcluster := range dc.Clusters {
62 cluster, ok := cfg.Clusters[id]
64 return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
66 for name, np := range dcluster.NodeProfiles {
67 if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
69 } else if ldr.Logger != nil {
70 ldr.Logger.Warnf("overriding Clusters.%s.Services using Clusters.%s.NodeProfiles.%s (guessing %q is a hostname)", id, id, name, name)
72 applyDeprecatedNodeProfile(name, np.RailsAPI, &cluster.Services.RailsAPI)
73 applyDeprecatedNodeProfile(name, np.Controller, &cluster.Services.Controller)
74 applyDeprecatedNodeProfile(name, np.DispatchCloud, &cluster.Services.DispatchCloud)
76 if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
79 if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
82 cfg.Clusters[id] = cluster
87 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
92 if svc.InternalURLs == nil {
93 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
99 if strings.HasPrefix(host, ":") {
100 host = hostname + host
102 svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host}] = arvados.ServiceInstance{}
105 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
109 buf, err := ioutil.ReadFile(path)
114 ldr.Logger.Warnf("you should remove the legacy %v config file (%s) after migrating all config keys to the cluster configuration file (%s)", component, path, ldr.Path)
116 err = yaml.Unmarshal(buf, target)
118 return fmt.Errorf("%s: %s", path, err)
123 type oldCrunchDispatchSlurmConfig struct {
124 Client *arvados.Client
126 SbatchArguments *[]string
127 PollPeriod *arvados.Duration
128 PrioritySpread *int64
130 // crunch-run command to invoke. The container UUID will be
131 // appended. If nil, []string{"crunch-run"} will be used.
133 // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
134 CrunchRunCommand *[]string
136 // Extra RAM to reserve (in Bytes) for SLURM job, in addition
137 // to the amount specified in the container's RuntimeConstraints
138 ReserveExtraRAM *int64
140 // Minimum time between two attempts to run the same container
141 MinRetryPeriod *arvados.Duration
143 // Batch size for container queries
147 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
149 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
153 if client.APIHost != "" {
154 cluster.Services.Controller.ExternalURL.Host = client.APIHost
156 if client.Scheme != "" {
157 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
159 cluster.Services.Controller.ExternalURL.Scheme = "https"
161 if client.AuthToken != "" {
162 cluster.SystemRootToken = client.AuthToken
164 cluster.TLS.Insecure = client.Insecure
166 for i, u := range client.KeepServiceURIs {
172 cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
175 // update config using values from an crunch-dispatch-slurm config file.
176 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
177 if ldr.CrunchDispatchSlurmPath == "" {
180 var oc oldCrunchDispatchSlurmConfig
181 err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
182 if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
184 } else if err != nil {
188 cluster, err := cfg.GetCluster("")
193 loadOldClientConfig(cluster, oc.Client)
195 if oc.SbatchArguments != nil {
196 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
198 if oc.PollPeriod != nil {
199 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
201 if oc.PrioritySpread != nil {
202 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
204 if oc.CrunchRunCommand != nil {
205 if len(*oc.CrunchRunCommand) >= 1 {
206 cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
208 if len(*oc.CrunchRunCommand) >= 2 {
209 cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
212 if oc.ReserveExtraRAM != nil {
213 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
215 if oc.MinRetryPeriod != nil {
216 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
218 if oc.BatchSize != nil {
219 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
222 cfg.Clusters[cluster.ClusterID] = *cluster
226 type oldWsConfig struct {
227 Client *arvados.Client
228 Postgres *arvados.PostgreSQLConnection
234 PingTimeout *arvados.Duration
235 ClientEventQueue *int
236 ServerEventQueue *int
238 ManagementToken *string
241 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
243 // update config using values from an crunch-dispatch-slurm config file.
244 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
245 if ldr.WebsocketPath == "" {
249 err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
250 if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
252 } else if err != nil {
256 cluster, err := cfg.GetCluster("")
261 loadOldClientConfig(cluster, oc.Client)
263 if oc.Postgres != nil {
264 cluster.PostgreSQL.Connection = *oc.Postgres
266 if oc.PostgresPool != nil {
267 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
269 if oc.Listen != nil {
270 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
272 if oc.LogLevel != nil {
273 cluster.SystemLogs.LogLevel = *oc.LogLevel
275 if oc.LogFormat != nil {
276 cluster.SystemLogs.Format = *oc.LogFormat
278 if oc.PingTimeout != nil {
279 cluster.API.SendTimeout = *oc.PingTimeout
281 if oc.ClientEventQueue != nil {
282 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
284 if oc.ServerEventQueue != nil {
285 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
287 if oc.ManagementToken != nil {
288 cluster.ManagementToken = *oc.ManagementToken
291 cfg.Clusters[cluster.ClusterID] = *cluster
295 type oldKeepProxyConfig struct {
296 Client *arvados.Client
301 Timeout *arvados.Duration
304 ManagementToken *string
307 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
309 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
310 if ldr.KeepproxyPath == "" {
313 var oc oldKeepProxyConfig
314 err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
315 if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
317 } else if err != nil {
321 cluster, err := cfg.GetCluster("")
326 loadOldClientConfig(cluster, oc.Client)
328 if oc.Listen != nil {
329 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
331 if oc.DefaultReplicas != nil {
332 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
334 if oc.Timeout != nil {
335 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
338 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
339 cluster.SystemLogs.LogLevel = "debug"
340 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
341 cluster.SystemLogs.LogLevel = "info"
344 if oc.ManagementToken != nil {
345 cluster.ManagementToken = *oc.ManagementToken
348 // The following legacy options are no longer supported. If they are set to
349 // true or PIDFile has a value, error out and notify the user
350 unsupportedEntry := func(cfgEntry string) error {
351 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
353 if oc.DisableGet != nil && *oc.DisableGet {
354 return unsupportedEntry("DisableGet")
356 if oc.DisablePut != nil && *oc.DisablePut {
357 return unsupportedEntry("DisablePut")
359 if oc.PIDFile != nil && *oc.PIDFile != "" {
360 return unsupportedEntry("PIDFile")
363 cfg.Clusters[cluster.ClusterID] = *cluster
367 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
369 type oldKeepWebConfig struct {
370 Client *arvados.Client
374 AnonymousTokens []string
375 AttachmentOnlyHost string
380 UUIDTTL arvados.Duration
381 MaxCollectionEntries int
382 MaxCollectionBytes int64
383 MaxPermissionEntries int
387 // Hack to support old command line flag, which is a bool
388 // meaning "get actual token from environment".
389 deprecatedAllowAnonymous bool
391 // Authorization token to be included in all health check requests.
392 ManagementToken string
395 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
396 if ldr.KeepWebPath == "" {
399 var oc oldKeepWebConfig
400 err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
401 if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
403 } else if err != nil {
407 cluster, err := cfg.GetCluster("")
412 loadOldClientConfig(cluster, oc.Client)
414 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: oc.Listen}] = arvados.ServiceInstance{}
415 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: oc.Listen}] = arvados.ServiceInstance{}
416 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: oc.AttachmentOnlyHost}
417 cluster.TLS.Insecure = oc.Client.Insecure
418 cluster.ManagementToken = oc.ManagementToken
419 cluster.Collections.TrustAllContent = oc.TrustAllContent
420 cluster.Collections.WebDAVCache.TTL = oc.Cache.TTL
421 cluster.Collections.WebDAVCache.UUIDTTL = oc.Cache.UUIDTTL
422 cluster.Collections.WebDAVCache.MaxCollectionEntries = oc.Cache.MaxCollectionEntries
423 cluster.Collections.WebDAVCache.MaxCollectionBytes = oc.Cache.MaxCollectionBytes
424 cluster.Collections.WebDAVCache.MaxPermissionEntries = oc.Cache.MaxPermissionEntries
425 cluster.Collections.WebDAVCache.MaxUUIDEntries = oc.Cache.MaxUUIDEntries
426 if len(oc.AnonymousTokens) > 0 {
427 cluster.Users.AnonymousUserToken = oc.AnonymousTokens[0]
428 if len(oc.AnonymousTokens) > 1 {
429 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
433 cfg.Clusters[cluster.ClusterID] = *cluster
437 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
439 type oldGitHttpdConfig struct {
440 Client *arvados.Client
445 ManagementToken string
448 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
449 if ldr.GitHttpdPath == "" {
452 var oc oldGitHttpdConfig
453 err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
454 if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
456 } else if err != nil {
460 cluster, err := cfg.GetCluster("")
465 loadOldClientConfig(cluster, oc.Client)
467 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: oc.Listen}] = arvados.ServiceInstance{}
468 cluster.TLS.Insecure = oc.Client.Insecure
469 cluster.ManagementToken = oc.ManagementToken
470 cluster.Git.GitCommand = oc.GitCommand
471 cluster.Git.GitoliteHome = oc.GitoliteHome
472 cluster.Git.Repositories = oc.RepoRoot
474 cfg.Clusters[cluster.ClusterID] = *cluster