1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.arvados.org/arvados.git/sdk/go/arvados"
16 "github.com/ghodss/yaml"
19 type deprRequestLimits struct {
20 MaxItemsPerResponse *int
21 MultiClusterRequestConcurrency *int
24 type deprCUDAFeatures struct {
26 HardwareCapability string
30 type deprInstanceType struct {
31 CUDA *deprCUDAFeatures
34 type deprInstanceTypeMap map[string]deprInstanceType
36 type deprCluster struct {
37 RequestLimits deprRequestLimits
38 NodeProfiles map[string]nodeProfile
40 GoogleClientID *string
41 GoogleClientSecret *string
42 GoogleAlternateEmailAddresses *bool
44 ProviderAppSecret *string
47 SendUserSetupNotificationEmail *bool
48 SupportEmailAddress *string
52 BsubCUDAArguments *[]string
55 InstanceTypes deprInstanceTypeMap
58 type deprecatedConfig struct {
59 Clusters map[string]deprCluster
62 type nodeProfile struct {
63 Controller systemServiceInstance `json:"arvados-controller"`
64 Health systemServiceInstance `json:"arvados-health"`
65 Keepbalance systemServiceInstance `json:"keep-balance"`
66 Keepproxy systemServiceInstance `json:"keepproxy"`
67 Keepstore systemServiceInstance `json:"keepstore"`
68 Keepweb systemServiceInstance `json:"keep-web"`
69 DispatchCloud systemServiceInstance `json:"arvados-dispatch-cloud"`
70 RailsAPI systemServiceInstance `json:"arvados-api-server"`
71 Websocket systemServiceInstance `json:"arvados-ws"`
72 Workbench1 systemServiceInstance `json:"arvados-workbench"`
75 type systemServiceInstance struct {
81 func (ldr *Loader) applyDeprecatedConfig(cfg *arvados.Config) error {
82 var dc deprecatedConfig
83 err := yaml.Unmarshal(ldr.configdata, &dc)
87 hostname, err := os.Hostname()
91 for id, dcluster := range dc.Clusters {
92 cluster, ok := cfg.Clusters[id]
94 return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
96 for name, np := range dcluster.NodeProfiles {
97 if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
99 } else if ldr.Logger != nil {
100 ldr.Logger.Warnf("overriding Clusters.%s.Services using Clusters.%s.NodeProfiles.%s (guessing %q is a hostname)", id, id, name, name)
102 applyDeprecatedNodeProfile(name, np.RailsAPI, &cluster.Services.RailsAPI)
103 applyDeprecatedNodeProfile(name, np.Controller, &cluster.Services.Controller)
104 applyDeprecatedNodeProfile(name, np.DispatchCloud, &cluster.Services.DispatchCloud)
106 if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
109 if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
112 if dst, addr := &cluster.Users.SupportEmailAddress, dcluster.Mail.SupportEmailAddress; addr != nil {
114 ldr.Logger.Warnf("using your old config key Mail.SupportEmailAddress -- but you should rename it to Users.SupportEmailAddress")
116 if dst, b := &cluster.Users.SendUserSetupNotificationEmail, dcluster.Mail.SendUserSetupNotificationEmail; b != nil {
118 ldr.Logger.Warnf("using your old config key Mail.SendUserSetupNotificationEmail -- but you should rename it to Users.SendUserSetupNotificationEmail")
120 if dst, n := &cluster.Containers.LSF.BsubGPUArguments, dcluster.Containers.LSF.BsubCUDAArguments; n != nil {
122 ldr.Logger.Warnf("using your old config key Containers.LSF.BsubCUDAArguments -- but you should rename it to Containers.LSF.BsubGPUArguments")
125 // Google* moved to Google.*
126 if dst, n := &cluster.Login.Google.ClientID, dcluster.Login.GoogleClientID; n != nil && *n != *dst {
129 // In old config, non-empty ClientID meant enable
130 cluster.Login.Google.Enable = true
133 if dst, n := &cluster.Login.Google.ClientSecret, dcluster.Login.GoogleClientSecret; n != nil && *n != *dst {
136 if dst, n := &cluster.Login.Google.AlternateEmailAddresses, dcluster.Login.GoogleAlternateEmailAddresses; n != nil && *n != *dst {
140 for name, instanceType := range dcluster.InstanceTypes {
141 if instanceType.CUDA != nil {
142 updInstanceType := cluster.InstanceTypes[name]
143 updInstanceType.GPU = arvados.GPUFeatures{
145 DriverVersion: instanceType.CUDA.DriverVersion,
146 HardwareTarget: instanceType.CUDA.HardwareCapability,
147 DeviceCount: instanceType.CUDA.DeviceCount,
150 cluster.InstanceTypes[name] = updInstanceType
151 ldr.Logger.Warnf("InstanceType %q has deprecated CUDA section, should be migrated to GPU section", name)
155 cfg.Clusters[id] = cluster
160 func (ldr *Loader) applyDeprecatedVolumeDriverParameters(cfg *arvados.Config) error {
161 for clusterID, cluster := range cfg.Clusters {
162 for volID, vol := range cluster.Volumes {
163 if vol.Driver == "S3" {
165 AccessKey string `json:",omitempty"`
166 SecretKey string `json:",omitempty"`
168 SecretAccessKey string
170 err := json.Unmarshal(vol.DriverParameters, ¶ms)
172 return fmt.Errorf("error loading %s.Volumes.%s.DriverParameters: %w", clusterID, volID, err)
174 if params.AccessKey != "" || params.SecretKey != "" {
175 if params.AccessKeyID != "" || params.SecretAccessKey != "" {
176 return fmt.Errorf("cannot use old keys (AccessKey/SecretKey) and new keys (AccessKeyID/SecretAccessKey) at the same time in %s.Volumes.%s.DriverParameters -- you must remove the old config keys", clusterID, volID)
178 var allparams map[string]interface{}
179 err = json.Unmarshal(vol.DriverParameters, &allparams)
181 return fmt.Errorf("error loading %s.Volumes.%s.DriverParameters: %w", clusterID, volID, err)
183 for k := range allparams {
184 if lk := strings.ToLower(k); lk == "accesskey" || lk == "secretkey" {
188 ldr.Logger.Warnf("using your old config keys %s.Volumes.%s.DriverParameters.AccessKey/SecretKey -- but you should rename them to AccessKeyID/SecretAccessKey", clusterID, volID)
189 allparams["AccessKeyID"] = params.AccessKey
190 allparams["SecretAccessKey"] = params.SecretKey
191 vol.DriverParameters, err = json.Marshal(allparams)
195 cluster.Volumes[volID] = vol
203 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
208 if svc.InternalURLs == nil {
209 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
215 if strings.HasPrefix(host, ":") {
216 host = hostname + host
218 svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host, Path: "/"}] = arvados.ServiceInstance{}
221 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
225 buf, err := ioutil.ReadFile(path)
230 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)
232 err = yaml.Unmarshal(buf, target)
234 return fmt.Errorf("%s: %s", path, err)
239 type oldCrunchDispatchSlurmConfig struct {
240 Client *arvados.Client
242 SbatchArguments *[]string
243 PollPeriod *arvados.Duration
244 PrioritySpread *int64
246 // crunch-run command to invoke. The container UUID will be
247 // appended. If nil, []string{"crunch-run"} will be used.
249 // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
250 CrunchRunCommand *[]string
252 // Extra RAM to reserve (in Bytes) for SLURM job, in addition
253 // to the amount specified in the container's RuntimeConstraints
254 ReserveExtraRAM *int64
256 // Minimum time between two attempts to run the same container
257 MinRetryPeriod *arvados.Duration
259 // Batch size for container queries
263 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
265 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
269 if client.APIHost != "" {
270 cluster.Services.Controller.ExternalURL.Host = client.APIHost
271 cluster.Services.Controller.ExternalURL.Path = "/"
273 if client.Scheme != "" {
274 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
276 cluster.Services.Controller.ExternalURL.Scheme = "https"
278 if client.AuthToken != "" {
279 cluster.SystemRootToken = client.AuthToken
281 cluster.TLS.Insecure = client.Insecure
283 for i, u := range client.KeepServiceURIs {
289 cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
292 // update config using values from an crunch-dispatch-slurm config file.
293 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
294 if ldr.CrunchDispatchSlurmPath == "" {
297 var oc oldCrunchDispatchSlurmConfig
298 err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
299 if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
301 } else if err != nil {
305 cluster, err := cfg.GetCluster("")
310 loadOldClientConfig(cluster, oc.Client)
312 if oc.SbatchArguments != nil {
313 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
315 if oc.PollPeriod != nil {
316 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
318 if oc.PrioritySpread != nil {
319 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
321 if oc.CrunchRunCommand != nil {
322 if len(*oc.CrunchRunCommand) >= 1 {
323 cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
325 if len(*oc.CrunchRunCommand) >= 2 {
326 cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
329 if oc.ReserveExtraRAM != nil {
330 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
332 if oc.MinRetryPeriod != nil {
333 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
335 if oc.BatchSize != nil {
336 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
339 cfg.Clusters[cluster.ClusterID] = *cluster
343 type oldWsConfig struct {
344 Client *arvados.Client
345 Postgres *arvados.PostgreSQLConnection
351 PingTimeout *arvados.Duration
352 ClientEventQueue *int
353 ServerEventQueue *int
355 ManagementToken *string
358 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
360 // update config using values from an crunch-dispatch-slurm config file.
361 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
362 if ldr.WebsocketPath == "" {
366 err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
367 if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
369 } else if err != nil {
373 cluster, err := cfg.GetCluster("")
378 loadOldClientConfig(cluster, oc.Client)
380 if oc.Postgres != nil {
381 cluster.PostgreSQL.Connection = *oc.Postgres
383 if oc.PostgresPool != nil {
384 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
386 if oc.Listen != nil {
387 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
389 if oc.LogLevel != nil {
390 cluster.SystemLogs.LogLevel = *oc.LogLevel
392 if oc.LogFormat != nil {
393 cluster.SystemLogs.Format = *oc.LogFormat
395 if oc.PingTimeout != nil {
396 cluster.API.SendTimeout = *oc.PingTimeout
398 if oc.ClientEventQueue != nil {
399 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
401 if oc.ServerEventQueue != nil {
402 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
404 if oc.ManagementToken != nil {
405 cluster.ManagementToken = *oc.ManagementToken
408 cfg.Clusters[cluster.ClusterID] = *cluster
412 type oldKeepProxyConfig struct {
413 Client *arvados.Client
418 Timeout *arvados.Duration
421 ManagementToken *string
424 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
426 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
427 if ldr.KeepproxyPath == "" {
430 var oc oldKeepProxyConfig
431 err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
432 if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
434 } else if err != nil {
438 cluster, err := cfg.GetCluster("")
443 loadOldClientConfig(cluster, oc.Client)
445 if oc.Listen != nil {
446 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
448 if oc.DefaultReplicas != nil {
449 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
451 if oc.Timeout != nil {
452 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
455 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
456 cluster.SystemLogs.LogLevel = "debug"
457 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
458 cluster.SystemLogs.LogLevel = "info"
461 if oc.ManagementToken != nil {
462 cluster.ManagementToken = *oc.ManagementToken
465 // The following legacy options are no longer supported. If they are set to
466 // true or PIDFile has a value, error out and notify the user
467 unsupportedEntry := func(cfgEntry string) error {
468 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
470 if oc.DisableGet != nil && *oc.DisableGet {
471 return unsupportedEntry("DisableGet")
473 if oc.DisablePut != nil && *oc.DisablePut {
474 return unsupportedEntry("DisablePut")
476 if oc.PIDFile != nil && *oc.PIDFile != "" {
477 return unsupportedEntry("PIDFile")
480 cfg.Clusters[cluster.ClusterID] = *cluster
484 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
486 type oldKeepWebConfig struct {
487 Client *arvados.Client
491 AnonymousTokens *[]string
492 AttachmentOnlyHost *string
493 TrustAllContent *bool
496 TTL *arvados.Duration
497 UUIDTTL *arvados.Duration
498 MaxCollectionEntries *int
499 MaxCollectionBytes *int64
503 // Hack to support old command line flag, which is a bool
504 // meaning "get actual token from environment".
505 deprecatedAllowAnonymous *bool
507 // Authorization token to be included in all health check requests.
508 ManagementToken *string
511 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
512 if ldr.KeepWebPath == "" {
515 var oc oldKeepWebConfig
516 err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
517 if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
519 } else if err != nil {
523 cluster, err := cfg.GetCluster("")
528 loadOldClientConfig(cluster, oc.Client)
530 if oc.Listen != nil {
531 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
532 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
534 if oc.AttachmentOnlyHost != nil {
535 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: *oc.AttachmentOnlyHost, Path: "/"}
537 if oc.ManagementToken != nil {
538 cluster.ManagementToken = *oc.ManagementToken
540 if oc.TrustAllContent != nil {
541 cluster.Collections.TrustAllContent = *oc.TrustAllContent
543 if oc.Cache.TTL != nil {
544 cluster.Collections.WebDAVCache.TTL = *oc.Cache.TTL
546 if oc.Cache.MaxCollectionBytes != nil {
547 cluster.Collections.WebDAVCache.MaxCollectionBytes = arvados.ByteSize(*oc.Cache.MaxCollectionBytes)
549 if oc.AnonymousTokens != nil {
550 if len(*oc.AnonymousTokens) > 0 {
551 cluster.Users.AnonymousUserToken = (*oc.AnonymousTokens)[0]
552 if len(*oc.AnonymousTokens) > 1 {
553 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
558 cfg.Clusters[cluster.ClusterID] = *cluster
562 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
564 type oldKeepBalanceConfig struct {
565 Client *arvados.Client
567 KeepServiceTypes *[]string
568 KeepServiceList *arvados.KeepServiceList
569 RunPeriod *arvados.Duration
570 CollectionBatchSize *int
571 CollectionBuffers *int
572 RequestTimeout *arvados.Duration
573 LostBlocksFile *string
574 ManagementToken *string
577 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
578 if ldr.KeepBalancePath == "" {
581 var oc oldKeepBalanceConfig
582 err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
583 if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
585 } else if err != nil {
589 cluster, err := cfg.GetCluster("")
594 loadOldClientConfig(cluster, oc.Client)
596 if oc.Listen != nil {
597 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
599 if oc.ManagementToken != nil {
600 cluster.ManagementToken = *oc.ManagementToken
602 if oc.RunPeriod != nil {
603 cluster.Collections.BalancePeriod = *oc.RunPeriod
605 if oc.LostBlocksFile != nil {
606 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
608 if oc.CollectionBatchSize != nil {
609 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
611 if oc.CollectionBuffers != nil {
612 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
614 if oc.RequestTimeout != nil {
615 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
618 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."
620 // If the keep service type provided is "disk" silently ignore it, since
621 // this is what ends up being done anyway.
622 if oc.KeepServiceTypes != nil {
623 numTypes := len(*oc.KeepServiceTypes)
624 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
625 return fmt.Errorf(msg, "KeepServiceTypes")
629 if oc.KeepServiceList != nil {
630 return fmt.Errorf(msg, "KeepServiceList")
633 cfg.Clusters[cluster.ClusterID] = *cluster
637 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
638 if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
641 cluster, err := cfg.GetCluster("")
645 if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
646 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
647 cluster.SystemRootToken = tok
649 if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
650 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
651 u, err := url.Parse("https://" + apihost)
653 return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
655 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
656 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
657 cluster.TLS.Insecure = true
660 cfg.Clusters[cluster.ClusterID] = *cluster