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
27 GoogleClientID *string
28 GoogleClientSecret *string
29 GoogleAlternateEmailAddresses *bool
31 ProviderAppSecret *string
35 type deprecatedConfig struct {
36 Clusters map[string]deprCluster
39 type nodeProfile struct {
40 Controller systemServiceInstance `json:"arvados-controller"`
41 Health systemServiceInstance `json:"arvados-health"`
42 Keepbalance systemServiceInstance `json:"keep-balance"`
43 Keepproxy systemServiceInstance `json:"keepproxy"`
44 Keepstore systemServiceInstance `json:"keepstore"`
45 Keepweb systemServiceInstance `json:"keep-web"`
46 Nodemanager systemServiceInstance `json:"arvados-node-manager"`
47 DispatchCloud systemServiceInstance `json:"arvados-dispatch-cloud"`
48 RailsAPI systemServiceInstance `json:"arvados-api-server"`
49 Websocket systemServiceInstance `json:"arvados-ws"`
50 Workbench1 systemServiceInstance `json:"arvados-workbench"`
53 type systemServiceInstance struct {
59 func (ldr *Loader) applyDeprecatedConfig(cfg *arvados.Config) error {
60 var dc deprecatedConfig
61 err := yaml.Unmarshal(ldr.configdata, &dc)
65 hostname, err := os.Hostname()
69 for id, dcluster := range dc.Clusters {
70 cluster, ok := cfg.Clusters[id]
72 return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
74 for name, np := range dcluster.NodeProfiles {
75 if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
77 } else if ldr.Logger != nil {
78 ldr.Logger.Warnf("overriding Clusters.%s.Services using Clusters.%s.NodeProfiles.%s (guessing %q is a hostname)", id, id, name, name)
80 applyDeprecatedNodeProfile(name, np.RailsAPI, &cluster.Services.RailsAPI)
81 applyDeprecatedNodeProfile(name, np.Controller, &cluster.Services.Controller)
82 applyDeprecatedNodeProfile(name, np.DispatchCloud, &cluster.Services.DispatchCloud)
84 if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
87 if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
91 // Google* moved to Google.*
92 if dst, n := &cluster.Login.Google.ClientID, dcluster.Login.GoogleClientID; n != nil && *n != *dst {
95 // In old config, non-empty ClientID meant enable
96 cluster.Login.Google.Enable = true
99 if dst, n := &cluster.Login.Google.ClientSecret, dcluster.Login.GoogleClientSecret; n != nil && *n != *dst {
102 if dst, n := &cluster.Login.Google.AlternateEmailAddresses, dcluster.Login.GoogleAlternateEmailAddresses; n != nil && *n != *dst {
106 // Provider* moved to SSO.Provider*
107 if dst, n := &cluster.Login.SSO.ProviderAppID, dcluster.Login.ProviderAppID; n != nil && *n != *dst {
110 // In old config, non-empty ID meant enable
111 cluster.Login.SSO.Enable = true
114 if dst, n := &cluster.Login.SSO.ProviderAppSecret, dcluster.Login.ProviderAppSecret; n != nil && *n != *dst {
118 cfg.Clusters[id] = cluster
123 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
128 if svc.InternalURLs == nil {
129 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
135 if strings.HasPrefix(host, ":") {
136 host = hostname + host
138 svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host, Path: "/"}] = arvados.ServiceInstance{}
141 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
145 buf, err := ioutil.ReadFile(path)
150 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)
152 err = yaml.Unmarshal(buf, target)
154 return fmt.Errorf("%s: %s", path, err)
159 type oldCrunchDispatchSlurmConfig struct {
160 Client *arvados.Client
162 SbatchArguments *[]string
163 PollPeriod *arvados.Duration
164 PrioritySpread *int64
166 // crunch-run command to invoke. The container UUID will be
167 // appended. If nil, []string{"crunch-run"} will be used.
169 // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
170 CrunchRunCommand *[]string
172 // Extra RAM to reserve (in Bytes) for SLURM job, in addition
173 // to the amount specified in the container's RuntimeConstraints
174 ReserveExtraRAM *int64
176 // Minimum time between two attempts to run the same container
177 MinRetryPeriod *arvados.Duration
179 // Batch size for container queries
183 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
185 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
189 if client.APIHost != "" {
190 cluster.Services.Controller.ExternalURL.Host = client.APIHost
191 cluster.Services.Controller.ExternalURL.Path = "/"
193 if client.Scheme != "" {
194 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
196 cluster.Services.Controller.ExternalURL.Scheme = "https"
198 if client.AuthToken != "" {
199 cluster.SystemRootToken = client.AuthToken
201 cluster.TLS.Insecure = client.Insecure
203 for i, u := range client.KeepServiceURIs {
209 cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
212 // update config using values from an crunch-dispatch-slurm config file.
213 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
214 if ldr.CrunchDispatchSlurmPath == "" {
217 var oc oldCrunchDispatchSlurmConfig
218 err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
219 if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
221 } else if err != nil {
225 cluster, err := cfg.GetCluster("")
230 loadOldClientConfig(cluster, oc.Client)
232 if oc.SbatchArguments != nil {
233 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
235 if oc.PollPeriod != nil {
236 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
238 if oc.PrioritySpread != nil {
239 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
241 if oc.CrunchRunCommand != nil {
242 if len(*oc.CrunchRunCommand) >= 1 {
243 cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
245 if len(*oc.CrunchRunCommand) >= 2 {
246 cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
249 if oc.ReserveExtraRAM != nil {
250 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
252 if oc.MinRetryPeriod != nil {
253 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
255 if oc.BatchSize != nil {
256 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
259 cfg.Clusters[cluster.ClusterID] = *cluster
263 type oldWsConfig struct {
264 Client *arvados.Client
265 Postgres *arvados.PostgreSQLConnection
271 PingTimeout *arvados.Duration
272 ClientEventQueue *int
273 ServerEventQueue *int
275 ManagementToken *string
278 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
280 // update config using values from an crunch-dispatch-slurm config file.
281 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
282 if ldr.WebsocketPath == "" {
286 err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
287 if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
289 } else if err != nil {
293 cluster, err := cfg.GetCluster("")
298 loadOldClientConfig(cluster, oc.Client)
300 if oc.Postgres != nil {
301 cluster.PostgreSQL.Connection = *oc.Postgres
303 if oc.PostgresPool != nil {
304 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
306 if oc.Listen != nil {
307 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
309 if oc.LogLevel != nil {
310 cluster.SystemLogs.LogLevel = *oc.LogLevel
312 if oc.LogFormat != nil {
313 cluster.SystemLogs.Format = *oc.LogFormat
315 if oc.PingTimeout != nil {
316 cluster.API.SendTimeout = *oc.PingTimeout
318 if oc.ClientEventQueue != nil {
319 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
321 if oc.ServerEventQueue != nil {
322 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
324 if oc.ManagementToken != nil {
325 cluster.ManagementToken = *oc.ManagementToken
328 cfg.Clusters[cluster.ClusterID] = *cluster
332 type oldKeepProxyConfig struct {
333 Client *arvados.Client
338 Timeout *arvados.Duration
341 ManagementToken *string
344 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
346 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
347 if ldr.KeepproxyPath == "" {
350 var oc oldKeepProxyConfig
351 err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
352 if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
354 } else if err != nil {
358 cluster, err := cfg.GetCluster("")
363 loadOldClientConfig(cluster, oc.Client)
365 if oc.Listen != nil {
366 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
368 if oc.DefaultReplicas != nil {
369 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
371 if oc.Timeout != nil {
372 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
375 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
376 cluster.SystemLogs.LogLevel = "debug"
377 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
378 cluster.SystemLogs.LogLevel = "info"
381 if oc.ManagementToken != nil {
382 cluster.ManagementToken = *oc.ManagementToken
385 // The following legacy options are no longer supported. If they are set to
386 // true or PIDFile has a value, error out and notify the user
387 unsupportedEntry := func(cfgEntry string) error {
388 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
390 if oc.DisableGet != nil && *oc.DisableGet {
391 return unsupportedEntry("DisableGet")
393 if oc.DisablePut != nil && *oc.DisablePut {
394 return unsupportedEntry("DisablePut")
396 if oc.PIDFile != nil && *oc.PIDFile != "" {
397 return unsupportedEntry("PIDFile")
400 cfg.Clusters[cluster.ClusterID] = *cluster
404 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
406 type oldKeepWebConfig struct {
407 Client *arvados.Client
411 AnonymousTokens *[]string
412 AttachmentOnlyHost *string
413 TrustAllContent *bool
416 TTL *arvados.Duration
417 UUIDTTL *arvados.Duration
418 MaxCollectionEntries *int
419 MaxCollectionBytes *int64
420 MaxPermissionEntries *int
424 // Hack to support old command line flag, which is a bool
425 // meaning "get actual token from environment".
426 deprecatedAllowAnonymous *bool
428 // Authorization token to be included in all health check requests.
429 ManagementToken *string
432 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
433 if ldr.KeepWebPath == "" {
436 var oc oldKeepWebConfig
437 err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
438 if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
440 } else if err != nil {
444 cluster, err := cfg.GetCluster("")
449 loadOldClientConfig(cluster, oc.Client)
451 if oc.Listen != nil {
452 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
453 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
455 if oc.AttachmentOnlyHost != nil {
456 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: *oc.AttachmentOnlyHost, Path: "/"}
458 if oc.ManagementToken != nil {
459 cluster.ManagementToken = *oc.ManagementToken
461 if oc.TrustAllContent != nil {
462 cluster.Collections.TrustAllContent = *oc.TrustAllContent
464 if oc.Cache.TTL != nil {
465 cluster.Collections.WebDAVCache.TTL = *oc.Cache.TTL
467 if oc.Cache.UUIDTTL != nil {
468 cluster.Collections.WebDAVCache.UUIDTTL = *oc.Cache.UUIDTTL
470 if oc.Cache.MaxCollectionEntries != nil {
471 cluster.Collections.WebDAVCache.MaxCollectionEntries = *oc.Cache.MaxCollectionEntries
473 if oc.Cache.MaxCollectionBytes != nil {
474 cluster.Collections.WebDAVCache.MaxCollectionBytes = *oc.Cache.MaxCollectionBytes
476 if oc.Cache.MaxPermissionEntries != nil {
477 cluster.Collections.WebDAVCache.MaxPermissionEntries = *oc.Cache.MaxPermissionEntries
479 if oc.Cache.MaxUUIDEntries != nil {
480 cluster.Collections.WebDAVCache.MaxUUIDEntries = *oc.Cache.MaxUUIDEntries
482 if oc.AnonymousTokens != nil {
483 if len(*oc.AnonymousTokens) > 0 {
484 cluster.Users.AnonymousUserToken = (*oc.AnonymousTokens)[0]
485 if len(*oc.AnonymousTokens) > 1 {
486 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
491 cfg.Clusters[cluster.ClusterID] = *cluster
495 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
497 type oldGitHttpdConfig struct {
498 Client *arvados.Client
503 ManagementToken *string
506 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
507 if ldr.GitHttpdPath == "" {
510 var oc oldGitHttpdConfig
511 err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
512 if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
514 } else if err != nil {
518 cluster, err := cfg.GetCluster("")
523 loadOldClientConfig(cluster, oc.Client)
525 if oc.Listen != nil {
526 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
528 if oc.ManagementToken != nil {
529 cluster.ManagementToken = *oc.ManagementToken
531 if oc.GitCommand != nil {
532 cluster.Git.GitCommand = *oc.GitCommand
534 if oc.GitoliteHome != nil {
535 cluster.Git.GitoliteHome = *oc.GitoliteHome
537 if oc.RepoRoot != nil {
538 cluster.Git.Repositories = *oc.RepoRoot
541 cfg.Clusters[cluster.ClusterID] = *cluster
545 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
547 type oldKeepBalanceConfig struct {
548 Client *arvados.Client
550 KeepServiceTypes *[]string
551 KeepServiceList *arvados.KeepServiceList
552 RunPeriod *arvados.Duration
553 CollectionBatchSize *int
554 CollectionBuffers *int
555 RequestTimeout *arvados.Duration
556 LostBlocksFile *string
557 ManagementToken *string
560 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
561 if ldr.KeepBalancePath == "" {
564 var oc oldKeepBalanceConfig
565 err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
566 if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
568 } else if err != nil {
572 cluster, err := cfg.GetCluster("")
577 loadOldClientConfig(cluster, oc.Client)
579 if oc.Listen != nil {
580 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
582 if oc.ManagementToken != nil {
583 cluster.ManagementToken = *oc.ManagementToken
585 if oc.RunPeriod != nil {
586 cluster.Collections.BalancePeriod = *oc.RunPeriod
588 if oc.LostBlocksFile != nil {
589 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
591 if oc.CollectionBatchSize != nil {
592 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
594 if oc.CollectionBuffers != nil {
595 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
597 if oc.RequestTimeout != nil {
598 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
601 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."
603 // If the keep service type provided is "disk" silently ignore it, since
604 // this is what ends up being done anyway.
605 if oc.KeepServiceTypes != nil {
606 numTypes := len(*oc.KeepServiceTypes)
607 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
608 return fmt.Errorf(msg, "KeepServiceTypes")
612 if oc.KeepServiceList != nil {
613 return fmt.Errorf(msg, "KeepServiceList")
616 cfg.Clusters[cluster.ClusterID] = *cluster
620 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
621 if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
624 cluster, err := cfg.GetCluster("")
628 if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
629 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
630 cluster.SystemRootToken = tok
632 if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
633 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
634 u, err := url.Parse("https://" + apihost)
636 return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
638 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
639 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
640 cluster.TLS.Insecure = true
643 cfg.Clusters[cluster.ClusterID] = *cluster