17590: Fix spelling of S3 driver name.
[arvados.git] / lib / config / deprecated.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package config
6
7 import (
8         "encoding/json"
9         "fmt"
10         "io/ioutil"
11         "net/url"
12         "os"
13         "strings"
14
15         "git.arvados.org/arvados.git/sdk/go/arvados"
16         "github.com/ghodss/yaml"
17 )
18
19 type deprRequestLimits struct {
20         MaxItemsPerResponse            *int
21         MultiClusterRequestConcurrency *int
22 }
23
24 type deprCluster struct {
25         RequestLimits deprRequestLimits
26         NodeProfiles  map[string]nodeProfile
27         Login         struct {
28                 GoogleClientID                *string
29                 GoogleClientSecret            *string
30                 GoogleAlternateEmailAddresses *bool
31                 ProviderAppID                 *string
32                 ProviderAppSecret             *string
33         }
34 }
35
36 type deprecatedConfig struct {
37         Clusters map[string]deprCluster
38 }
39
40 type nodeProfile struct {
41         Controller    systemServiceInstance `json:"arvados-controller"`
42         Health        systemServiceInstance `json:"arvados-health"`
43         Keepbalance   systemServiceInstance `json:"keep-balance"`
44         Keepproxy     systemServiceInstance `json:"keepproxy"`
45         Keepstore     systemServiceInstance `json:"keepstore"`
46         Keepweb       systemServiceInstance `json:"keep-web"`
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"`
51 }
52
53 type systemServiceInstance struct {
54         Listen   string
55         TLS      bool
56         Insecure bool
57 }
58
59 func (ldr *Loader) applyDeprecatedConfig(cfg *arvados.Config) error {
60         var dc deprecatedConfig
61         err := yaml.Unmarshal(ldr.configdata, &dc)
62         if err != nil {
63                 return err
64         }
65         hostname, err := os.Hostname()
66         if err != nil {
67                 return err
68         }
69         for id, dcluster := range dc.Clusters {
70                 cluster, ok := cfg.Clusters[id]
71                 if !ok {
72                         return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
73                 }
74                 for name, np := range dcluster.NodeProfiles {
75                         if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
76                                 name = "localhost"
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)
79                         }
80                         applyDeprecatedNodeProfile(name, np.RailsAPI, &cluster.Services.RailsAPI)
81                         applyDeprecatedNodeProfile(name, np.Controller, &cluster.Services.Controller)
82                         applyDeprecatedNodeProfile(name, np.DispatchCloud, &cluster.Services.DispatchCloud)
83                 }
84                 if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
85                         *dst = *n
86                 }
87                 if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
88                         *dst = *n
89                 }
90
91                 // Google* moved to Google.*
92                 if dst, n := &cluster.Login.Google.ClientID, dcluster.Login.GoogleClientID; n != nil && *n != *dst {
93                         *dst = *n
94                         if *n != "" {
95                                 // In old config, non-empty ClientID meant enable
96                                 cluster.Login.Google.Enable = true
97                         }
98                 }
99                 if dst, n := &cluster.Login.Google.ClientSecret, dcluster.Login.GoogleClientSecret; n != nil && *n != *dst {
100                         *dst = *n
101                 }
102                 if dst, n := &cluster.Login.Google.AlternateEmailAddresses, dcluster.Login.GoogleAlternateEmailAddresses; n != nil && *n != *dst {
103                         *dst = *n
104                 }
105
106                 // Provider* moved to SSO.Provider*
107                 if dst, n := &cluster.Login.SSO.ProviderAppID, dcluster.Login.ProviderAppID; n != nil && *n != *dst {
108                         *dst = *n
109                         if *n != "" {
110                                 // In old config, non-empty ID meant enable
111                                 cluster.Login.SSO.Enable = true
112                         }
113                 }
114                 if dst, n := &cluster.Login.SSO.ProviderAppSecret, dcluster.Login.ProviderAppSecret; n != nil && *n != *dst {
115                         *dst = *n
116                 }
117
118                 cfg.Clusters[id] = cluster
119         }
120         return nil
121 }
122
123 func (ldr *Loader) applyDeprecatedVolumeDriverParameters(cfg *arvados.Config) error {
124         for clusterID, cluster := range cfg.Clusters {
125                 for volID, vol := range cluster.Volumes {
126                         if vol.Driver == "S3" {
127                                 var params struct {
128                                         AccessKey       string `json:",omitempty"`
129                                         SecretKey       string `json:",omitempty"`
130                                         AccessKeyID     string
131                                         SecretAccessKey string
132                                 }
133                                 err := json.Unmarshal(vol.DriverParameters, &params)
134                                 if err != nil {
135                                         return fmt.Errorf("error loading %s.Volumes.%s.DriverParameters: %w", clusterID, volID, err)
136                                 }
137                                 if params.AccessKey != "" || params.SecretKey != "" {
138                                         if params.AccessKeyID != "" || params.SecretAccessKey != "" {
139                                                 ldr.Logger.Warnf("ignoring old config keys %s.Volumes.%s.DriverParameters.AccessKey/SecretKey because new keys AccessKeyID/SecretAccessKey are also present", clusterID, volID)
140                                                 continue
141                                         }
142                                         var allparams map[string]interface{}
143                                         err = json.Unmarshal(vol.DriverParameters, &allparams)
144                                         if err != nil {
145                                                 return fmt.Errorf("error loading %s.Volumes.%s.DriverParameters: %w", clusterID, volID, err)
146                                         }
147                                         for k := range allparams {
148                                                 if lk := strings.ToLower(k); lk == "accesskey" || lk == "secretkey" {
149                                                         delete(allparams, k)
150                                                 }
151                                         }
152                                         ldr.Logger.Warnf("using your old config keys %s.Volumes.%s.DriverParameters.AccessKey/SecretKey -- but you should rename them to AccessKeyID/SecretAccessKey", clusterID, volID)
153                                         allparams["AccessKeyID"] = params.AccessKey
154                                         allparams["SecretAccessKey"] = params.SecretKey
155                                         vol.DriverParameters, err = json.Marshal(allparams)
156                                         if err != nil {
157                                                 return err
158                                         }
159                                         cluster.Volumes[volID] = vol
160                                 }
161                         }
162                 }
163         }
164         return nil
165 }
166
167 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
168         scheme := "https"
169         if !ssi.TLS {
170                 scheme = "http"
171         }
172         if svc.InternalURLs == nil {
173                 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
174         }
175         host := ssi.Listen
176         if host == "" {
177                 return
178         }
179         if strings.HasPrefix(host, ":") {
180                 host = hostname + host
181         }
182         svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host, Path: "/"}] = arvados.ServiceInstance{}
183 }
184
185 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
186         if path == "" {
187                 return nil
188         }
189         buf, err := ioutil.ReadFile(path)
190         if err != nil {
191                 return err
192         }
193
194         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)
195
196         err = yaml.Unmarshal(buf, target)
197         if err != nil {
198                 return fmt.Errorf("%s: %s", path, err)
199         }
200         return nil
201 }
202
203 type oldCrunchDispatchSlurmConfig struct {
204         Client *arvados.Client
205
206         SbatchArguments *[]string
207         PollPeriod      *arvados.Duration
208         PrioritySpread  *int64
209
210         // crunch-run command to invoke. The container UUID will be
211         // appended. If nil, []string{"crunch-run"} will be used.
212         //
213         // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
214         CrunchRunCommand *[]string
215
216         // Extra RAM to reserve (in Bytes) for SLURM job, in addition
217         // to the amount specified in the container's RuntimeConstraints
218         ReserveExtraRAM *int64
219
220         // Minimum time between two attempts to run the same container
221         MinRetryPeriod *arvados.Duration
222
223         // Batch size for container queries
224         BatchSize *int64
225 }
226
227 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
228
229 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
230         if client == nil {
231                 return
232         }
233         if client.APIHost != "" {
234                 cluster.Services.Controller.ExternalURL.Host = client.APIHost
235                 cluster.Services.Controller.ExternalURL.Path = "/"
236         }
237         if client.Scheme != "" {
238                 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
239         } else {
240                 cluster.Services.Controller.ExternalURL.Scheme = "https"
241         }
242         if client.AuthToken != "" {
243                 cluster.SystemRootToken = client.AuthToken
244         }
245         cluster.TLS.Insecure = client.Insecure
246         ks := ""
247         for i, u := range client.KeepServiceURIs {
248                 if i > 0 {
249                         ks += " "
250                 }
251                 ks += u
252         }
253         cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
254 }
255
256 // update config using values from an crunch-dispatch-slurm config file.
257 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
258         if ldr.CrunchDispatchSlurmPath == "" {
259                 return nil
260         }
261         var oc oldCrunchDispatchSlurmConfig
262         err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
263         if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
264                 return nil
265         } else if err != nil {
266                 return err
267         }
268
269         cluster, err := cfg.GetCluster("")
270         if err != nil {
271                 return err
272         }
273
274         loadOldClientConfig(cluster, oc.Client)
275
276         if oc.SbatchArguments != nil {
277                 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
278         }
279         if oc.PollPeriod != nil {
280                 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
281         }
282         if oc.PrioritySpread != nil {
283                 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
284         }
285         if oc.CrunchRunCommand != nil {
286                 if len(*oc.CrunchRunCommand) >= 1 {
287                         cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
288                 }
289                 if len(*oc.CrunchRunCommand) >= 2 {
290                         cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
291                 }
292         }
293         if oc.ReserveExtraRAM != nil {
294                 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
295         }
296         if oc.MinRetryPeriod != nil {
297                 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
298         }
299         if oc.BatchSize != nil {
300                 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
301         }
302
303         cfg.Clusters[cluster.ClusterID] = *cluster
304         return nil
305 }
306
307 type oldWsConfig struct {
308         Client       *arvados.Client
309         Postgres     *arvados.PostgreSQLConnection
310         PostgresPool *int
311         Listen       *string
312         LogLevel     *string
313         LogFormat    *string
314
315         PingTimeout      *arvados.Duration
316         ClientEventQueue *int
317         ServerEventQueue *int
318
319         ManagementToken *string
320 }
321
322 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
323
324 // update config using values from an crunch-dispatch-slurm config file.
325 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
326         if ldr.WebsocketPath == "" {
327                 return nil
328         }
329         var oc oldWsConfig
330         err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
331         if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
332                 return nil
333         } else if err != nil {
334                 return err
335         }
336
337         cluster, err := cfg.GetCluster("")
338         if err != nil {
339                 return err
340         }
341
342         loadOldClientConfig(cluster, oc.Client)
343
344         if oc.Postgres != nil {
345                 cluster.PostgreSQL.Connection = *oc.Postgres
346         }
347         if oc.PostgresPool != nil {
348                 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
349         }
350         if oc.Listen != nil {
351                 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
352         }
353         if oc.LogLevel != nil {
354                 cluster.SystemLogs.LogLevel = *oc.LogLevel
355         }
356         if oc.LogFormat != nil {
357                 cluster.SystemLogs.Format = *oc.LogFormat
358         }
359         if oc.PingTimeout != nil {
360                 cluster.API.SendTimeout = *oc.PingTimeout
361         }
362         if oc.ClientEventQueue != nil {
363                 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
364         }
365         if oc.ServerEventQueue != nil {
366                 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
367         }
368         if oc.ManagementToken != nil {
369                 cluster.ManagementToken = *oc.ManagementToken
370         }
371
372         cfg.Clusters[cluster.ClusterID] = *cluster
373         return nil
374 }
375
376 type oldKeepProxyConfig struct {
377         Client          *arvados.Client
378         Listen          *string
379         DisableGet      *bool
380         DisablePut      *bool
381         DefaultReplicas *int
382         Timeout         *arvados.Duration
383         PIDFile         *string
384         Debug           *bool
385         ManagementToken *string
386 }
387
388 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
389
390 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
391         if ldr.KeepproxyPath == "" {
392                 return nil
393         }
394         var oc oldKeepProxyConfig
395         err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
396         if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
397                 return nil
398         } else if err != nil {
399                 return err
400         }
401
402         cluster, err := cfg.GetCluster("")
403         if err != nil {
404                 return err
405         }
406
407         loadOldClientConfig(cluster, oc.Client)
408
409         if oc.Listen != nil {
410                 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
411         }
412         if oc.DefaultReplicas != nil {
413                 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
414         }
415         if oc.Timeout != nil {
416                 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
417         }
418         if oc.Debug != nil {
419                 if *oc.Debug && cluster.SystemLogs.LogLevel != "debug" {
420                         cluster.SystemLogs.LogLevel = "debug"
421                 } else if !*oc.Debug && cluster.SystemLogs.LogLevel != "info" {
422                         cluster.SystemLogs.LogLevel = "info"
423                 }
424         }
425         if oc.ManagementToken != nil {
426                 cluster.ManagementToken = *oc.ManagementToken
427         }
428
429         // The following legacy options are no longer supported. If they are set to
430         // true or PIDFile has a value, error out and notify the user
431         unsupportedEntry := func(cfgEntry string) error {
432                 return fmt.Errorf("the keepproxy %s configuration option is no longer supported, please remove it from your configuration file", cfgEntry)
433         }
434         if oc.DisableGet != nil && *oc.DisableGet {
435                 return unsupportedEntry("DisableGet")
436         }
437         if oc.DisablePut != nil && *oc.DisablePut {
438                 return unsupportedEntry("DisablePut")
439         }
440         if oc.PIDFile != nil && *oc.PIDFile != "" {
441                 return unsupportedEntry("PIDFile")
442         }
443
444         cfg.Clusters[cluster.ClusterID] = *cluster
445         return nil
446 }
447
448 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
449
450 type oldKeepWebConfig struct {
451         Client *arvados.Client
452
453         Listen *string
454
455         AnonymousTokens    *[]string
456         AttachmentOnlyHost *string
457         TrustAllContent    *bool
458
459         Cache struct {
460                 TTL                  *arvados.Duration
461                 UUIDTTL              *arvados.Duration
462                 MaxCollectionEntries *int
463                 MaxCollectionBytes   *int64
464                 MaxPermissionEntries *int
465                 MaxUUIDEntries       *int
466         }
467
468         // Hack to support old command line flag, which is a bool
469         // meaning "get actual token from environment".
470         deprecatedAllowAnonymous *bool
471
472         // Authorization token to be included in all health check requests.
473         ManagementToken *string
474 }
475
476 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
477         if ldr.KeepWebPath == "" {
478                 return nil
479         }
480         var oc oldKeepWebConfig
481         err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
482         if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
483                 return nil
484         } else if err != nil {
485                 return err
486         }
487
488         cluster, err := cfg.GetCluster("")
489         if err != nil {
490                 return err
491         }
492
493         loadOldClientConfig(cluster, oc.Client)
494
495         if oc.Listen != nil {
496                 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
497                 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
498         }
499         if oc.AttachmentOnlyHost != nil {
500                 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: *oc.AttachmentOnlyHost, Path: "/"}
501         }
502         if oc.ManagementToken != nil {
503                 cluster.ManagementToken = *oc.ManagementToken
504         }
505         if oc.TrustAllContent != nil {
506                 cluster.Collections.TrustAllContent = *oc.TrustAllContent
507         }
508         if oc.Cache.TTL != nil {
509                 cluster.Collections.WebDAVCache.TTL = *oc.Cache.TTL
510         }
511         if oc.Cache.UUIDTTL != nil {
512                 cluster.Collections.WebDAVCache.UUIDTTL = *oc.Cache.UUIDTTL
513         }
514         if oc.Cache.MaxCollectionEntries != nil {
515                 cluster.Collections.WebDAVCache.MaxCollectionEntries = *oc.Cache.MaxCollectionEntries
516         }
517         if oc.Cache.MaxCollectionBytes != nil {
518                 cluster.Collections.WebDAVCache.MaxCollectionBytes = *oc.Cache.MaxCollectionBytes
519         }
520         if oc.Cache.MaxPermissionEntries != nil {
521                 cluster.Collections.WebDAVCache.MaxPermissionEntries = *oc.Cache.MaxPermissionEntries
522         }
523         if oc.Cache.MaxUUIDEntries != nil {
524                 cluster.Collections.WebDAVCache.MaxUUIDEntries = *oc.Cache.MaxUUIDEntries
525         }
526         if oc.AnonymousTokens != nil {
527                 if len(*oc.AnonymousTokens) > 0 {
528                         cluster.Users.AnonymousUserToken = (*oc.AnonymousTokens)[0]
529                         if len(*oc.AnonymousTokens) > 1 {
530                                 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
531                         }
532                 }
533         }
534
535         cfg.Clusters[cluster.ClusterID] = *cluster
536         return nil
537 }
538
539 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
540
541 type oldGitHttpdConfig struct {
542         Client          *arvados.Client
543         Listen          *string
544         GitCommand      *string
545         GitoliteHome    *string
546         RepoRoot        *string
547         ManagementToken *string
548 }
549
550 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
551         if ldr.GitHttpdPath == "" {
552                 return nil
553         }
554         var oc oldGitHttpdConfig
555         err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
556         if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
557                 return nil
558         } else if err != nil {
559                 return err
560         }
561
562         cluster, err := cfg.GetCluster("")
563         if err != nil {
564                 return err
565         }
566
567         loadOldClientConfig(cluster, oc.Client)
568
569         if oc.Listen != nil {
570                 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
571         }
572         if oc.ManagementToken != nil {
573                 cluster.ManagementToken = *oc.ManagementToken
574         }
575         if oc.GitCommand != nil {
576                 cluster.Git.GitCommand = *oc.GitCommand
577         }
578         if oc.GitoliteHome != nil {
579                 cluster.Git.GitoliteHome = *oc.GitoliteHome
580         }
581         if oc.RepoRoot != nil {
582                 cluster.Git.Repositories = *oc.RepoRoot
583         }
584
585         cfg.Clusters[cluster.ClusterID] = *cluster
586         return nil
587 }
588
589 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
590
591 type oldKeepBalanceConfig struct {
592         Client              *arvados.Client
593         Listen              *string
594         KeepServiceTypes    *[]string
595         KeepServiceList     *arvados.KeepServiceList
596         RunPeriod           *arvados.Duration
597         CollectionBatchSize *int
598         CollectionBuffers   *int
599         RequestTimeout      *arvados.Duration
600         LostBlocksFile      *string
601         ManagementToken     *string
602 }
603
604 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
605         if ldr.KeepBalancePath == "" {
606                 return nil
607         }
608         var oc oldKeepBalanceConfig
609         err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
610         if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
611                 return nil
612         } else if err != nil {
613                 return err
614         }
615
616         cluster, err := cfg.GetCluster("")
617         if err != nil {
618                 return err
619         }
620
621         loadOldClientConfig(cluster, oc.Client)
622
623         if oc.Listen != nil {
624                 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
625         }
626         if oc.ManagementToken != nil {
627                 cluster.ManagementToken = *oc.ManagementToken
628         }
629         if oc.RunPeriod != nil {
630                 cluster.Collections.BalancePeriod = *oc.RunPeriod
631         }
632         if oc.LostBlocksFile != nil {
633                 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
634         }
635         if oc.CollectionBatchSize != nil {
636                 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
637         }
638         if oc.CollectionBuffers != nil {
639                 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
640         }
641         if oc.RequestTimeout != nil {
642                 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
643         }
644
645         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."
646
647         // If the keep service type provided is "disk" silently ignore it, since
648         // this is what ends up being done anyway.
649         if oc.KeepServiceTypes != nil {
650                 numTypes := len(*oc.KeepServiceTypes)
651                 if numTypes != 0 && !(numTypes == 1 && (*oc.KeepServiceTypes)[0] == "disk") {
652                         return fmt.Errorf(msg, "KeepServiceTypes")
653                 }
654         }
655
656         if oc.KeepServiceList != nil {
657                 return fmt.Errorf(msg, "KeepServiceList")
658         }
659
660         cfg.Clusters[cluster.ClusterID] = *cluster
661         return nil
662 }
663
664 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
665         if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
666                 return nil
667         }
668         cluster, err := cfg.GetCluster("")
669         if err != nil {
670                 return err
671         }
672         if tok := os.Getenv("ARVADOS_API_TOKEN"); tok != "" && cluster.SystemRootToken == "" {
673                 ldr.Logger.Warn("SystemRootToken missing from cluster config, falling back to ARVADOS_API_TOKEN environment variable")
674                 cluster.SystemRootToken = tok
675         }
676         if apihost := os.Getenv("ARVADOS_API_HOST"); apihost != "" && cluster.Services.Controller.ExternalURL.Host == "" {
677                 ldr.Logger.Warn("Services.Controller.ExternalURL missing from cluster config, falling back to ARVADOS_API_HOST(_INSECURE) environment variables")
678                 u, err := url.Parse("https://" + apihost)
679                 if err != nil {
680                         return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
681                 }
682                 cluster.Services.Controller.ExternalURL = arvados.URL(*u)
683                 if i := os.Getenv("ARVADOS_API_HOST_INSECURE"); i != "" && i != "0" {
684                         cluster.TLS.Insecure = true
685                 }
686         }
687         cfg.Clusters[cluster.ClusterID] = *cluster
688         return nil
689 }