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 DispatchCloud systemServiceInstance `json:"arvados-dispatch-cloud"`
47 RailsAPI systemServiceInstance `json:"arvados-api-server"`
48 Websocket systemServiceInstance `json:"arvados-ws"`
49 Workbench1 systemServiceInstance `json:"arvados-workbench"`
52 type systemServiceInstance struct {
58 func (ldr *Loader) applyDeprecatedConfig(cfg *arvados.Config) error {
59 var dc deprecatedConfig
60 err := yaml.Unmarshal(ldr.configdata, &dc)
64 hostname, err := os.Hostname()
68 for id, dcluster := range dc.Clusters {
69 cluster, ok := cfg.Clusters[id]
71 return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
73 for name, np := range dcluster.NodeProfiles {
74 if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
76 } else if ldr.Logger != nil {
77 ldr.Logger.Warnf("overriding Clusters.%s.Services using Clusters.%s.NodeProfiles.%s (guessing %q is a hostname)", id, id, name, name)
79 applyDeprecatedNodeProfile(name, np.RailsAPI, &cluster.Services.RailsAPI)
80 applyDeprecatedNodeProfile(name, np.Controller, &cluster.Services.Controller)
81 applyDeprecatedNodeProfile(name, np.DispatchCloud, &cluster.Services.DispatchCloud)
83 if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
86 if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
90 // Google* moved to Google.*
91 if dst, n := &cluster.Login.Google.ClientID, dcluster.Login.GoogleClientID; n != nil && *n != *dst {
94 // In old config, non-empty ClientID meant enable
95 cluster.Login.Google.Enable = true
98 if dst, n := &cluster.Login.Google.ClientSecret, dcluster.Login.GoogleClientSecret; n != nil && *n != *dst {
101 if dst, n := &cluster.Login.Google.AlternateEmailAddresses, dcluster.Login.GoogleAlternateEmailAddresses; n != nil && *n != *dst {
105 // Provider* moved to SSO.Provider*
106 if dst, n := &cluster.Login.SSO.ProviderAppID, dcluster.Login.ProviderAppID; n != nil && *n != *dst {
109 // In old config, non-empty ID meant enable
110 cluster.Login.SSO.Enable = true
113 if dst, n := &cluster.Login.SSO.ProviderAppSecret, dcluster.Login.ProviderAppSecret; n != nil && *n != *dst {
117 cfg.Clusters[id] = cluster
122 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
127 if svc.InternalURLs == nil {
128 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
134 if strings.HasPrefix(host, ":") {
135 host = hostname + host
137 svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host, Path: "/"}] = arvados.ServiceInstance{}
140 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
144 buf, err := ioutil.ReadFile(path)
149 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)
151 err = yaml.Unmarshal(buf, target)
153 return fmt.Errorf("%s: %s", path, err)
158 type oldCrunchDispatchSlurmConfig struct {
159 Client *arvados.Client
161 SbatchArguments *[]string
162 PollPeriod *arvados.Duration
163 PrioritySpread *int64
165 // crunch-run command to invoke. The container UUID will be
166 // appended. If nil, []string{"crunch-run"} will be used.
168 // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
169 CrunchRunCommand *[]string
171 // Extra RAM to reserve (in Bytes) for SLURM job, in addition
172 // to the amount specified in the container's RuntimeConstraints
173 ReserveExtraRAM *int64
175 // Minimum time between two attempts to run the same container
176 MinRetryPeriod *arvados.Duration
178 // Batch size for container queries
182 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
184 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
188 if client.APIHost != "" {
189 cluster.Services.Controller.ExternalURL.Host = client.APIHost
190 cluster.Services.Controller.ExternalURL.Path = "/"
192 if client.Scheme != "" {
193 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
195 cluster.Services.Controller.ExternalURL.Scheme = "https"
197 if client.AuthToken != "" {
198 cluster.SystemRootToken = client.AuthToken
200 cluster.TLS.Insecure = client.Insecure
202 for i, u := range client.KeepServiceURIs {
208 cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
211 // update config using values from an crunch-dispatch-slurm config file.
212 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
213 if ldr.CrunchDispatchSlurmPath == "" {
216 var oc oldCrunchDispatchSlurmConfig
217 err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
218 if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
220 } else if err != nil {
224 cluster, err := cfg.GetCluster("")
229 loadOldClientConfig(cluster, oc.Client)
231 if oc.SbatchArguments != nil {
232 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
234 if oc.PollPeriod != nil {
235 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
237 if oc.PrioritySpread != nil {
238 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
240 if oc.CrunchRunCommand != nil {
241 if len(*oc.CrunchRunCommand) >= 1 {
242 cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
244 if len(*oc.CrunchRunCommand) >= 2 {
245 cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
248 if oc.ReserveExtraRAM != nil {
249 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
251 if oc.MinRetryPeriod != nil {
252 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
254 if oc.BatchSize != nil {
255 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
258 cfg.Clusters[cluster.ClusterID] = *cluster
262 type oldWsConfig struct {
263 Client *arvados.Client
264 Postgres *arvados.PostgreSQLConnection
270 PingTimeout *arvados.Duration
271 ClientEventQueue *int
272 ServerEventQueue *int
274 ManagementToken *string
277 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
279 // update config using values from an crunch-dispatch-slurm config file.
280 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
281 if ldr.WebsocketPath == "" {
285 err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
286 if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
288 } else if err != nil {
292 cluster, err := cfg.GetCluster("")
297 loadOldClientConfig(cluster, oc.Client)
299 if oc.Postgres != nil {
300 cluster.PostgreSQL.Connection = *oc.Postgres
302 if oc.PostgresPool != nil {
303 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
305 if oc.Listen != nil {
306 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
308 if oc.LogLevel != nil {
309 cluster.SystemLogs.LogLevel = *oc.LogLevel
311 if oc.LogFormat != nil {
312 cluster.SystemLogs.Format = *oc.LogFormat
314 if oc.PingTimeout != nil {
315 cluster.API.SendTimeout = *oc.PingTimeout
317 if oc.ClientEventQueue != nil {
318 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
320 if oc.ServerEventQueue != nil {
321 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
323 if oc.ManagementToken != nil {
324 cluster.ManagementToken = *oc.ManagementToken
327 cfg.Clusters[cluster.ClusterID] = *cluster
331 type oldKeepProxyConfig struct {
332 Client *arvados.Client
337 Timeout *arvados.Duration
340 ManagementToken *string
343 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
345 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
346 if ldr.KeepproxyPath == "" {
349 var oc oldKeepProxyConfig
350 err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
351 if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
353 } else if err != nil {
357 cluster, err := cfg.GetCluster("")
362 loadOldClientConfig(cluster, oc.Client)
364 if oc.Listen != nil {
365 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
367 if oc.DefaultReplicas != nil {
368 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
370 if oc.Timeout != nil {
371 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
374 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
375 cluster.SystemLogs.LogLevel = "debug"
376 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
377 cluster.SystemLogs.LogLevel = "info"
380 if oc.ManagementToken != nil {
381 cluster.ManagementToken = *oc.ManagementToken
384 // The following legacy options are no longer supported. If they are set to
385 // true or PIDFile has a value, error out and notify the user
386 unsupportedEntry := func(cfgEntry string) error {
387 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
389 if oc.DisableGet != nil && *oc.DisableGet {
390 return unsupportedEntry("DisableGet")
392 if oc.DisablePut != nil && *oc.DisablePut {
393 return unsupportedEntry("DisablePut")
395 if oc.PIDFile != nil && *oc.PIDFile != "" {
396 return unsupportedEntry("PIDFile")
399 cfg.Clusters[cluster.ClusterID] = *cluster
403 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
405 type oldKeepWebConfig struct {
406 Client *arvados.Client
410 AnonymousTokens *[]string
411 AttachmentOnlyHost *string
412 TrustAllContent *bool
415 TTL *arvados.Duration
416 UUIDTTL *arvados.Duration
417 MaxCollectionEntries *int
418 MaxCollectionBytes *int64
419 MaxPermissionEntries *int
423 // Hack to support old command line flag, which is a bool
424 // meaning "get actual token from environment".
425 deprecatedAllowAnonymous *bool
427 // Authorization token to be included in all health check requests.
428 ManagementToken *string
431 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
432 if ldr.KeepWebPath == "" {
435 var oc oldKeepWebConfig
436 err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
437 if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
439 } else if err != nil {
443 cluster, err := cfg.GetCluster("")
448 loadOldClientConfig(cluster, oc.Client)
450 if oc.Listen != nil {
451 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
452 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
454 if oc.AttachmentOnlyHost != nil {
455 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: *oc.AttachmentOnlyHost, Path: "/"}
457 if oc.ManagementToken != nil {
458 cluster.ManagementToken = *oc.ManagementToken
460 if oc.TrustAllContent != nil {
461 cluster.Collections.TrustAllContent = *oc.TrustAllContent
463 if oc.Cache.TTL != nil {
464 cluster.Collections.WebDAVCache.TTL = *oc.Cache.TTL
466 if oc.Cache.UUIDTTL != nil {
467 cluster.Collections.WebDAVCache.UUIDTTL = *oc.Cache.UUIDTTL
469 if oc.Cache.MaxCollectionEntries != nil {
470 cluster.Collections.WebDAVCache.MaxCollectionEntries = *oc.Cache.MaxCollectionEntries
472 if oc.Cache.MaxCollectionBytes != nil {
473 cluster.Collections.WebDAVCache.MaxCollectionBytes = *oc.Cache.MaxCollectionBytes
475 if oc.Cache.MaxPermissionEntries != nil {
476 cluster.Collections.WebDAVCache.MaxPermissionEntries = *oc.Cache.MaxPermissionEntries
478 if oc.Cache.MaxUUIDEntries != nil {
479 cluster.Collections.WebDAVCache.MaxUUIDEntries = *oc.Cache.MaxUUIDEntries
481 if oc.AnonymousTokens != nil {
482 if len(*oc.AnonymousTokens) > 0 {
483 cluster.Users.AnonymousUserToken = (*oc.AnonymousTokens)[0]
484 if len(*oc.AnonymousTokens) > 1 {
485 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
490 cfg.Clusters[cluster.ClusterID] = *cluster
494 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
496 type oldGitHttpdConfig struct {
497 Client *arvados.Client
502 ManagementToken *string
505 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
506 if ldr.GitHttpdPath == "" {
509 var oc oldGitHttpdConfig
510 err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
511 if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
513 } else if err != nil {
517 cluster, err := cfg.GetCluster("")
522 loadOldClientConfig(cluster, oc.Client)
524 if oc.Listen != nil {
525 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
527 if oc.ManagementToken != nil {
528 cluster.ManagementToken = *oc.ManagementToken
530 if oc.GitCommand != nil {
531 cluster.Git.GitCommand = *oc.GitCommand
533 if oc.GitoliteHome != nil {
534 cluster.Git.GitoliteHome = *oc.GitoliteHome
536 if oc.RepoRoot != nil {
537 cluster.Git.Repositories = *oc.RepoRoot
540 cfg.Clusters[cluster.ClusterID] = *cluster
544 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
546 type oldKeepBalanceConfig struct {
547 Client *arvados.Client
549 KeepServiceTypes *[]string
550 KeepServiceList *arvados.KeepServiceList
551 RunPeriod *arvados.Duration
552 CollectionBatchSize *int
553 CollectionBuffers *int
554 RequestTimeout *arvados.Duration
555 LostBlocksFile *string
556 ManagementToken *string
559 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
560 if ldr.KeepBalancePath == "" {
563 var oc oldKeepBalanceConfig
564 err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
565 if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
567 } else if err != nil {
571 cluster, err := cfg.GetCluster("")
576 loadOldClientConfig(cluster, oc.Client)
578 if oc.Listen != nil {
579 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
581 if oc.ManagementToken != nil {
582 cluster.ManagementToken = *oc.ManagementToken
584 if oc.RunPeriod != nil {
585 cluster.Collections.BalancePeriod = *oc.RunPeriod
587 if oc.LostBlocksFile != nil {
588 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
590 if oc.CollectionBatchSize != nil {
591 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
593 if oc.CollectionBuffers != nil {
594 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
596 if oc.RequestTimeout != nil {
597 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
600 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."
602 // If the keep service type provided is "disk" silently ignore it, since
603 // this is what ends up being done anyway.
604 if oc.KeepServiceTypes != nil {
605 numTypes := len(*oc.KeepServiceTypes)
606 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
607 return fmt.Errorf(msg, "KeepServiceTypes")
611 if oc.KeepServiceList != nil {
612 return fmt.Errorf(msg, "KeepServiceList")
615 cfg.Clusters[cluster.ClusterID] = *cluster
619 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
620 if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
623 cluster, err := cfg.GetCluster("")
627 if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
628 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
629 cluster.SystemRootToken = tok
631 if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
632 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
633 u, err := url.Parse("https://" + apihost)
635 return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
637 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
638 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
639 cluster.TLS.Insecure = true
642 cfg.Clusters[cluster.ClusterID] = *cluster