1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.curoverse.com/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}] = 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
157 if client.Scheme != "" {
158 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
160 cluster.Services.Controller.ExternalURL.Scheme = "https"
162 if client.AuthToken != "" {
163 cluster.SystemRootToken = client.AuthToken
165 cluster.TLS.Insecure = client.Insecure
167 for i, u := range client.KeepServiceURIs {
173 cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
176 // update config using values from an crunch-dispatch-slurm config file.
177 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
178 if ldr.CrunchDispatchSlurmPath == "" {
181 var oc oldCrunchDispatchSlurmConfig
182 err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
183 if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
185 } else if err != nil {
189 cluster, err := cfg.GetCluster("")
194 loadOldClientConfig(cluster, oc.Client)
196 if oc.SbatchArguments != nil {
197 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
199 if oc.PollPeriod != nil {
200 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
202 if oc.PrioritySpread != nil {
203 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
205 if oc.CrunchRunCommand != nil {
206 if len(*oc.CrunchRunCommand) >= 1 {
207 cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
209 if len(*oc.CrunchRunCommand) >= 2 {
210 cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
213 if oc.ReserveExtraRAM != nil {
214 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
216 if oc.MinRetryPeriod != nil {
217 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
219 if oc.BatchSize != nil {
220 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
223 cfg.Clusters[cluster.ClusterID] = *cluster
227 type oldWsConfig struct {
228 Client *arvados.Client
229 Postgres *arvados.PostgreSQLConnection
235 PingTimeout *arvados.Duration
236 ClientEventQueue *int
237 ServerEventQueue *int
239 ManagementToken *string
242 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
244 // update config using values from an crunch-dispatch-slurm config file.
245 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
246 if ldr.WebsocketPath == "" {
250 err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
251 if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
253 } else if err != nil {
257 cluster, err := cfg.GetCluster("")
262 loadOldClientConfig(cluster, oc.Client)
264 if oc.Postgres != nil {
265 cluster.PostgreSQL.Connection = *oc.Postgres
267 if oc.PostgresPool != nil {
268 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
270 if oc.Listen != nil {
271 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
273 if oc.LogLevel != nil {
274 cluster.SystemLogs.LogLevel = *oc.LogLevel
276 if oc.LogFormat != nil {
277 cluster.SystemLogs.Format = *oc.LogFormat
279 if oc.PingTimeout != nil {
280 cluster.API.SendTimeout = *oc.PingTimeout
282 if oc.ClientEventQueue != nil {
283 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
285 if oc.ServerEventQueue != nil {
286 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
288 if oc.ManagementToken != nil {
289 cluster.ManagementToken = *oc.ManagementToken
292 cfg.Clusters[cluster.ClusterID] = *cluster
296 type oldKeepProxyConfig struct {
297 Client *arvados.Client
302 Timeout *arvados.Duration
305 ManagementToken *string
308 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
310 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
311 if ldr.KeepproxyPath == "" {
314 var oc oldKeepProxyConfig
315 err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
316 if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
318 } else if err != nil {
322 cluster, err := cfg.GetCluster("")
327 loadOldClientConfig(cluster, oc.Client)
329 if oc.Listen != nil {
330 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
332 if oc.DefaultReplicas != nil {
333 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
335 if oc.Timeout != nil {
336 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
339 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
340 cluster.SystemLogs.LogLevel = "debug"
341 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
342 cluster.SystemLogs.LogLevel = "info"
345 if oc.ManagementToken != nil {
346 cluster.ManagementToken = *oc.ManagementToken
349 // The following legacy options are no longer supported. If they are set to
350 // true or PIDFile has a value, error out and notify the user
351 unsupportedEntry := func(cfgEntry string) error {
352 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
354 if oc.DisableGet != nil && *oc.DisableGet {
355 return unsupportedEntry("DisableGet")
357 if oc.DisablePut != nil && *oc.DisablePut {
358 return unsupportedEntry("DisablePut")
360 if oc.PIDFile != nil && *oc.PIDFile != "" {
361 return unsupportedEntry("PIDFile")
364 cfg.Clusters[cluster.ClusterID] = *cluster
368 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
370 type oldKeepWebConfig struct {
371 Client *arvados.Client
375 AnonymousTokens []string
376 AttachmentOnlyHost string
381 UUIDTTL arvados.Duration
382 MaxCollectionEntries int
383 MaxCollectionBytes int64
384 MaxPermissionEntries int
388 // Hack to support old command line flag, which is a bool
389 // meaning "get actual token from environment".
390 deprecatedAllowAnonymous bool
392 // Authorization token to be included in all health check requests.
393 ManagementToken string
396 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
397 if ldr.KeepWebPath == "" {
400 var oc oldKeepWebConfig
401 err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
402 if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
404 } else if err != nil {
408 cluster, err := cfg.GetCluster("")
413 loadOldClientConfig(cluster, oc.Client)
415 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: oc.Listen}] = arvados.ServiceInstance{}
416 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: oc.Listen}] = arvados.ServiceInstance{}
417 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: oc.AttachmentOnlyHost}
418 cluster.TLS.Insecure = oc.Client.Insecure
419 cluster.ManagementToken = oc.ManagementToken
420 cluster.Collections.TrustAllContent = oc.TrustAllContent
421 cluster.Collections.WebDAVCache.TTL = oc.Cache.TTL
422 cluster.Collections.WebDAVCache.UUIDTTL = oc.Cache.UUIDTTL
423 cluster.Collections.WebDAVCache.MaxCollectionEntries = oc.Cache.MaxCollectionEntries
424 cluster.Collections.WebDAVCache.MaxCollectionBytes = oc.Cache.MaxCollectionBytes
425 cluster.Collections.WebDAVCache.MaxPermissionEntries = oc.Cache.MaxPermissionEntries
426 cluster.Collections.WebDAVCache.MaxUUIDEntries = oc.Cache.MaxUUIDEntries
427 if len(oc.AnonymousTokens) > 0 {
428 cluster.Users.AnonymousUserToken = oc.AnonymousTokens[0]
429 if len(oc.AnonymousTokens) > 1 {
430 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
434 cfg.Clusters[cluster.ClusterID] = *cluster
438 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
440 type oldGitHttpdConfig struct {
441 Client *arvados.Client
446 ManagementToken string
449 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
450 if ldr.GitHttpdPath == "" {
453 var oc oldGitHttpdConfig
454 err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
455 if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
457 } else if err != nil {
461 cluster, err := cfg.GetCluster("")
466 loadOldClientConfig(cluster, oc.Client)
468 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: oc.Listen}] = arvados.ServiceInstance{}
469 cluster.TLS.Insecure = oc.Client.Insecure
470 cluster.ManagementToken = oc.ManagementToken
471 cluster.Git.GitCommand = oc.GitCommand
472 cluster.Git.GitoliteHome = oc.GitoliteHome
473 cluster.Git.Repositories = oc.RepoRoot
475 cfg.Clusters[cluster.ClusterID] = *cluster
479 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
481 type oldKeepBalanceConfig struct {
482 Client *arvados.Client
484 KeepServiceTypes *[]string
485 KeepServiceList *arvados.KeepServiceList
486 RunPeriod *arvados.Duration
487 CollectionBatchSize *int
488 CollectionBuffers *int
489 RequestTimeout *arvados.Duration
490 LostBlocksFile *string
491 ManagementToken *string
494 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
495 if ldr.KeepBalancePath == "" {
498 var oc oldKeepBalanceConfig
499 err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
500 if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
502 } else if err != nil {
506 cluster, err := cfg.GetCluster("")
511 loadOldClientConfig(cluster, oc.Client)
513 if oc.Listen != nil {
514 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
516 if oc.ManagementToken != nil {
517 cluster.ManagementToken = *oc.ManagementToken
519 if oc.RunPeriod != nil {
520 cluster.Collections.BalancePeriod = *oc.RunPeriod
522 if oc.LostBlocksFile != nil {
523 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
525 if oc.CollectionBatchSize != nil {
526 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
528 if oc.CollectionBuffers != nil {
529 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
531 if oc.RequestTimeout != nil {
532 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
535 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."
537 // If the keep service type provided is "disk" silently ignore it, since
538 // this is what ends up being done anyway.
539 if oc.KeepServiceTypes != nil {
540 numTypes := len(*oc.KeepServiceTypes)
541 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
542 return fmt.Errorf(msg, "KeepServiceTypes")
546 if oc.KeepServiceList != nil {
547 return fmt.Errorf(msg, "KeepServiceList")
550 cfg.Clusters[cluster.ClusterID] = *cluster
554 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
555 if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
558 cluster, err := cfg.GetCluster("")
562 if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
563 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
564 cluster.SystemRootToken = tok
566 if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
567 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
568 u, err := url.Parse("https://" + apihost)
570 return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
572 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
573 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
574 cluster.TLS.Insecure = true
577 cfg.Clusters[cluster.ClusterID] = *cluster