1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.arvados.org/arvados.git/sdk/go/arvados"
15 "github.com/ghodss/yaml"
18 type deprRequestLimits struct {
19 MaxItemsPerResponse *int
20 MultiClusterRequestConcurrency *int
23 type deprCluster struct {
24 RequestLimits deprRequestLimits
25 NodeProfiles map[string]nodeProfile
28 type deprecatedConfig struct {
29 Clusters map[string]deprCluster
32 type nodeProfile struct {
33 Controller systemServiceInstance `json:"arvados-controller"`
34 Health systemServiceInstance `json:"arvados-health"`
35 Keepbalance systemServiceInstance `json:"keep-balance"`
36 Keepproxy systemServiceInstance `json:"keepproxy"`
37 Keepstore systemServiceInstance `json:"keepstore"`
38 Keepweb systemServiceInstance `json:"keep-web"`
39 Nodemanager systemServiceInstance `json:"arvados-node-manager"`
40 DispatchCloud systemServiceInstance `json:"arvados-dispatch-cloud"`
41 RailsAPI systemServiceInstance `json:"arvados-api-server"`
42 Websocket systemServiceInstance `json:"arvados-ws"`
43 Workbench1 systemServiceInstance `json:"arvados-workbench"`
46 type systemServiceInstance struct {
52 func (ldr *Loader) applyDeprecatedConfig(cfg *arvados.Config) error {
53 var dc deprecatedConfig
54 err := yaml.Unmarshal(ldr.configdata, &dc)
58 hostname, err := os.Hostname()
62 for id, dcluster := range dc.Clusters {
63 cluster, ok := cfg.Clusters[id]
65 return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
67 for name, np := range dcluster.NodeProfiles {
68 if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
70 } else if ldr.Logger != nil {
71 ldr.Logger.Warnf("overriding Clusters.%s.Services using Clusters.%s.NodeProfiles.%s (guessing %q is a hostname)", id, id, name, name)
73 applyDeprecatedNodeProfile(name, np.RailsAPI, &cluster.Services.RailsAPI)
74 applyDeprecatedNodeProfile(name, np.Controller, &cluster.Services.Controller)
75 applyDeprecatedNodeProfile(name, np.DispatchCloud, &cluster.Services.DispatchCloud)
77 if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
80 if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
83 cfg.Clusters[id] = cluster
88 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
93 if svc.InternalURLs == nil {
94 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
100 if strings.HasPrefix(host, ":") {
101 host = hostname + host
103 svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host, Path: "/"}] = arvados.ServiceInstance{}
106 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
110 buf, err := ioutil.ReadFile(path)
115 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)
117 err = yaml.Unmarshal(buf, target)
119 return fmt.Errorf("%s: %s", path, err)
124 type oldCrunchDispatchSlurmConfig struct {
125 Client *arvados.Client
127 SbatchArguments *[]string
128 PollPeriod *arvados.Duration
129 PrioritySpread *int64
131 // crunch-run command to invoke. The container UUID will be
132 // appended. If nil, []string{"crunch-run"} will be used.
134 // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
135 CrunchRunCommand *[]string
137 // Extra RAM to reserve (in Bytes) for SLURM job, in addition
138 // to the amount specified in the container's RuntimeConstraints
139 ReserveExtraRAM *int64
141 // Minimum time between two attempts to run the same container
142 MinRetryPeriod *arvados.Duration
144 // Batch size for container queries
148 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
150 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
154 if client.APIHost != "" {
155 cluster.Services.Controller.ExternalURL.Host = client.APIHost
156 cluster.Services.Controller.ExternalURL.Path = "/"
158 if client.Scheme != "" {
159 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
161 cluster.Services.Controller.ExternalURL.Scheme = "https"
163 if client.AuthToken != "" {
164 cluster.SystemRootToken = client.AuthToken
166 cluster.TLS.Insecure = client.Insecure
168 for i, u := range client.KeepServiceURIs {
174 cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
177 // update config using values from an crunch-dispatch-slurm config file.
178 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
179 if ldr.CrunchDispatchSlurmPath == "" {
182 var oc oldCrunchDispatchSlurmConfig
183 err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
184 if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
186 } else if err != nil {
190 cluster, err := cfg.GetCluster("")
195 loadOldClientConfig(cluster, oc.Client)
197 if oc.SbatchArguments != nil {
198 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
200 if oc.PollPeriod != nil {
201 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
203 if oc.PrioritySpread != nil {
204 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
206 if oc.CrunchRunCommand != nil {
207 if len(*oc.CrunchRunCommand) >= 1 {
208 cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
210 if len(*oc.CrunchRunCommand) >= 2 {
211 cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
214 if oc.ReserveExtraRAM != nil {
215 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
217 if oc.MinRetryPeriod != nil {
218 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
220 if oc.BatchSize != nil {
221 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
224 cfg.Clusters[cluster.ClusterID] = *cluster
228 type oldWsConfig struct {
229 Client *arvados.Client
230 Postgres *arvados.PostgreSQLConnection
236 PingTimeout *arvados.Duration
237 ClientEventQueue *int
238 ServerEventQueue *int
240 ManagementToken *string
243 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
245 // update config using values from an crunch-dispatch-slurm config file.
246 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
247 if ldr.WebsocketPath == "" {
251 err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
252 if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
254 } else if err != nil {
258 cluster, err := cfg.GetCluster("")
263 loadOldClientConfig(cluster, oc.Client)
265 if oc.Postgres != nil {
266 cluster.PostgreSQL.Connection = *oc.Postgres
268 if oc.PostgresPool != nil {
269 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
271 if oc.Listen != nil {
272 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
274 if oc.LogLevel != nil {
275 cluster.SystemLogs.LogLevel = *oc.LogLevel
277 if oc.LogFormat != nil {
278 cluster.SystemLogs.Format = *oc.LogFormat
280 if oc.PingTimeout != nil {
281 cluster.API.SendTimeout = *oc.PingTimeout
283 if oc.ClientEventQueue != nil {
284 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
286 if oc.ServerEventQueue != nil {
287 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
289 if oc.ManagementToken != nil {
290 cluster.ManagementToken = *oc.ManagementToken
293 cfg.Clusters[cluster.ClusterID] = *cluster
297 type oldKeepProxyConfig struct {
298 Client *arvados.Client
303 Timeout *arvados.Duration
306 ManagementToken *string
309 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
311 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
312 if ldr.KeepproxyPath == "" {
315 var oc oldKeepProxyConfig
316 err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
317 if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
319 } else if err != nil {
323 cluster, err := cfg.GetCluster("")
328 loadOldClientConfig(cluster, oc.Client)
330 if oc.Listen != nil {
331 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
333 if oc.DefaultReplicas != nil {
334 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
336 if oc.Timeout != nil {
337 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
340 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
341 cluster.SystemLogs.LogLevel = "debug"
342 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
343 cluster.SystemLogs.LogLevel = "info"
346 if oc.ManagementToken != nil {
347 cluster.ManagementToken = *oc.ManagementToken
350 // The following legacy options are no longer supported. If they are set to
351 // true or PIDFile has a value, error out and notify the user
352 unsupportedEntry := func(cfgEntry string) error {
353 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
355 if oc.DisableGet != nil && *oc.DisableGet {
356 return unsupportedEntry("DisableGet")
358 if oc.DisablePut != nil && *oc.DisablePut {
359 return unsupportedEntry("DisablePut")
361 if oc.PIDFile != nil && *oc.PIDFile != "" {
362 return unsupportedEntry("PIDFile")
365 cfg.Clusters[cluster.ClusterID] = *cluster
369 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
371 type oldKeepWebConfig struct {
372 Client *arvados.Client
376 AnonymousTokens *[]string
377 AttachmentOnlyHost *string
378 TrustAllContent *bool
381 TTL *arvados.Duration
382 UUIDTTL *arvados.Duration
383 MaxCollectionEntries *int
384 MaxCollectionBytes *int64
385 MaxPermissionEntries *int
389 // Hack to support old command line flag, which is a bool
390 // meaning "get actual token from environment".
391 deprecatedAllowAnonymous *bool
393 // Authorization token to be included in all health check requests.
394 ManagementToken *string
397 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
398 if ldr.KeepWebPath == "" {
401 var oc oldKeepWebConfig
402 err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
403 if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
405 } else if err != nil {
409 cluster, err := cfg.GetCluster("")
414 loadOldClientConfig(cluster, oc.Client)
416 if oc.Listen != nil {
417 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
418 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
420 if oc.AttachmentOnlyHost != nil {
421 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: *oc.AttachmentOnlyHost, Path: "/"}
423 if oc.ManagementToken != nil {
424 cluster.ManagementToken = *oc.ManagementToken
426 if oc.TrustAllContent != nil {
427 cluster.Collections.TrustAllContent = *oc.TrustAllContent
429 if oc.Cache.TTL != nil {
430 cluster.Collections.WebDAVCache.TTL = *oc.Cache.TTL
432 if oc.Cache.UUIDTTL != nil {
433 cluster.Collections.WebDAVCache.UUIDTTL = *oc.Cache.UUIDTTL
435 if oc.Cache.MaxCollectionEntries != nil {
436 cluster.Collections.WebDAVCache.MaxCollectionEntries = *oc.Cache.MaxCollectionEntries
438 if oc.Cache.MaxCollectionBytes != nil {
439 cluster.Collections.WebDAVCache.MaxCollectionBytes = *oc.Cache.MaxCollectionBytes
441 if oc.Cache.MaxPermissionEntries != nil {
442 cluster.Collections.WebDAVCache.MaxPermissionEntries = *oc.Cache.MaxPermissionEntries
444 if oc.Cache.MaxUUIDEntries != nil {
445 cluster.Collections.WebDAVCache.MaxUUIDEntries = *oc.Cache.MaxUUIDEntries
447 if oc.AnonymousTokens != nil {
448 if len(*oc.AnonymousTokens) > 0 {
449 cluster.Users.AnonymousUserToken = (*oc.AnonymousTokens)[0]
450 if len(*oc.AnonymousTokens) > 1 {
451 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
456 cfg.Clusters[cluster.ClusterID] = *cluster
460 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
462 type oldGitHttpdConfig struct {
463 Client *arvados.Client
468 ManagementToken *string
471 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
472 if ldr.GitHttpdPath == "" {
475 var oc oldGitHttpdConfig
476 err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
477 if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
479 } else if err != nil {
483 cluster, err := cfg.GetCluster("")
488 loadOldClientConfig(cluster, oc.Client)
490 if oc.Listen != nil {
491 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
493 if oc.ManagementToken != nil {
494 cluster.ManagementToken = *oc.ManagementToken
496 if oc.GitCommand != nil {
497 cluster.Git.GitCommand = *oc.GitCommand
499 if oc.GitoliteHome != nil {
500 cluster.Git.GitoliteHome = *oc.GitoliteHome
502 if oc.RepoRoot != nil {
503 cluster.Git.Repositories = *oc.RepoRoot
506 cfg.Clusters[cluster.ClusterID] = *cluster
510 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
512 type oldKeepBalanceConfig struct {
513 Client *arvados.Client
515 KeepServiceTypes *[]string
516 KeepServiceList *arvados.KeepServiceList
517 RunPeriod *arvados.Duration
518 CollectionBatchSize *int
519 CollectionBuffers *int
520 RequestTimeout *arvados.Duration
521 LostBlocksFile *string
522 ManagementToken *string
525 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
526 if ldr.KeepBalancePath == "" {
529 var oc oldKeepBalanceConfig
530 err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
531 if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
533 } else if err != nil {
537 cluster, err := cfg.GetCluster("")
542 loadOldClientConfig(cluster, oc.Client)
544 if oc.Listen != nil {
545 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
547 if oc.ManagementToken != nil {
548 cluster.ManagementToken = *oc.ManagementToken
550 if oc.RunPeriod != nil {
551 cluster.Collections.BalancePeriod = *oc.RunPeriod
553 if oc.LostBlocksFile != nil {
554 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
556 if oc.CollectionBatchSize != nil {
557 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
559 if oc.CollectionBuffers != nil {
560 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
562 if oc.RequestTimeout != nil {
563 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
566 msg := "The %s configuration option is no longer supported. Please remove it from your configuration file. See the keep-balance upgrade notes at https://doc.arvados.org/admin/upgrading.html for more details."
568 // If the keep service type provided is "disk" silently ignore it, since
569 // this is what ends up being done anyway.
570 if oc.KeepServiceTypes != nil {
571 numTypes := len(*oc.KeepServiceTypes)
572 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
573 return fmt.Errorf(msg, "KeepServiceTypes")
577 if oc.KeepServiceList != nil {
578 return fmt.Errorf(msg, "KeepServiceList")
581 cfg.Clusters[cluster.ClusterID] = *cluster
585 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
586 if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
589 cluster, err := cfg.GetCluster("")
593 if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
594 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
595 cluster.SystemRootToken = tok
597 if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
598 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
599 u, err := url.Parse("https://" + apihost)
601 return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
603 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
604 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
605 cluster.TLS.Insecure = true
608 cfg.Clusters[cluster.ClusterID] = *cluster