16306: Merge branch 'master'
[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         "fmt"
9         "io/ioutil"
10         "net/url"
11         "os"
12         "strings"
13
14         "git.arvados.org/arvados.git/sdk/go/arvados"
15         "github.com/ghodss/yaml"
16 )
17
18 type deprRequestLimits struct {
19         MaxItemsPerResponse            *int
20         MultiClusterRequestConcurrency *int
21 }
22
23 type deprCluster struct {
24         RequestLimits deprRequestLimits
25         NodeProfiles  map[string]nodeProfile
26         Login         struct {
27                 GoogleClientID                *string
28                 GoogleClientSecret            *string
29                 GoogleAlternateEmailAddresses *bool
30                 ProviderAppID                 *string
31                 ProviderAppSecret             *string
32         }
33 }
34
35 type deprecatedConfig struct {
36         Clusters map[string]deprCluster
37 }
38
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"`
50 }
51
52 type systemServiceInstance struct {
53         Listen   string
54         TLS      bool
55         Insecure bool
56 }
57
58 func (ldr *Loader) applyDeprecatedConfig(cfg *arvados.Config) error {
59         var dc deprecatedConfig
60         err := yaml.Unmarshal(ldr.configdata, &dc)
61         if err != nil {
62                 return err
63         }
64         hostname, err := os.Hostname()
65         if err != nil {
66                 return err
67         }
68         for id, dcluster := range dc.Clusters {
69                 cluster, ok := cfg.Clusters[id]
70                 if !ok {
71                         return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
72                 }
73                 for name, np := range dcluster.NodeProfiles {
74                         if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
75                                 name = "localhost"
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)
78                         }
79                         applyDeprecatedNodeProfile(name, np.RailsAPI, &cluster.Services.RailsAPI)
80                         applyDeprecatedNodeProfile(name, np.Controller, &cluster.Services.Controller)
81                         applyDeprecatedNodeProfile(name, np.DispatchCloud, &cluster.Services.DispatchCloud)
82                 }
83                 if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
84                         *dst = *n
85                 }
86                 if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
87                         *dst = *n
88                 }
89
90                 // Google* moved to Google.*
91                 if dst, n := &cluster.Login.Google.ClientID, dcluster.Login.GoogleClientID; n != nil && *n != *dst {
92                         *dst = *n
93                         if *n != "" {
94                                 // In old config, non-empty ClientID meant enable
95                                 cluster.Login.Google.Enable = true
96                         }
97                 }
98                 if dst, n := &cluster.Login.Google.ClientSecret, dcluster.Login.GoogleClientSecret; n != nil && *n != *dst {
99                         *dst = *n
100                 }
101                 if dst, n := &cluster.Login.Google.AlternateEmailAddresses, dcluster.Login.GoogleAlternateEmailAddresses; n != nil && *n != *dst {
102                         *dst = *n
103                 }
104
105                 // Provider* moved to SSO.Provider*
106                 if dst, n := &cluster.Login.SSO.ProviderAppID, dcluster.Login.ProviderAppID; n != nil && *n != *dst {
107                         *dst = *n
108                         if *n != "" {
109                                 // In old config, non-empty ID meant enable
110                                 cluster.Login.SSO.Enable = true
111                         }
112                 }
113                 if dst, n := &cluster.Login.SSO.ProviderAppSecret, dcluster.Login.ProviderAppSecret; n != nil && *n != *dst {
114                         *dst = *n
115                 }
116
117                 cfg.Clusters[id] = cluster
118         }
119         return nil
120 }
121
122 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
123         scheme := "https"
124         if !ssi.TLS {
125                 scheme = "http"
126         }
127         if svc.InternalURLs == nil {
128                 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
129         }
130         host := ssi.Listen
131         if host == "" {
132                 return
133         }
134         if strings.HasPrefix(host, ":") {
135                 host = hostname + host
136         }
137         svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host, Path: "/"}] = arvados.ServiceInstance{}
138 }
139
140 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
141         if path == "" {
142                 return nil
143         }
144         buf, err := ioutil.ReadFile(path)
145         if err != nil {
146                 return err
147         }
148
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)
150
151         err = yaml.Unmarshal(buf, target)
152         if err != nil {
153                 return fmt.Errorf("%s: %s", path, err)
154         }
155         return nil
156 }
157
158 type oldCrunchDispatchSlurmConfig struct {
159         Client *arvados.Client
160
161         SbatchArguments *[]string
162         PollPeriod      *arvados.Duration
163         PrioritySpread  *int64
164
165         // crunch-run command to invoke. The container UUID will be
166         // appended. If nil, []string{"crunch-run"} will be used.
167         //
168         // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
169         CrunchRunCommand *[]string
170
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
174
175         // Minimum time between two attempts to run the same container
176         MinRetryPeriod *arvados.Duration
177
178         // Batch size for container queries
179         BatchSize *int64
180 }
181
182 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
183
184 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
185         if client == nil {
186                 return
187         }
188         if client.APIHost != "" {
189                 cluster.Services.Controller.ExternalURL.Host = client.APIHost
190                 cluster.Services.Controller.ExternalURL.Path = "/"
191         }
192         if client.Scheme != "" {
193                 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
194         } else {
195                 cluster.Services.Controller.ExternalURL.Scheme = "https"
196         }
197         if client.AuthToken != "" {
198                 cluster.SystemRootToken = client.AuthToken
199         }
200         cluster.TLS.Insecure = client.Insecure
201         ks := ""
202         for i, u := range client.KeepServiceURIs {
203                 if i > 0 {
204                         ks += " "
205                 }
206                 ks += u
207         }
208         cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
209 }
210
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 == "" {
214                 return nil
215         }
216         var oc oldCrunchDispatchSlurmConfig
217         err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
218         if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
219                 return nil
220         } else if err != nil {
221                 return err
222         }
223
224         cluster, err := cfg.GetCluster("")
225         if err != nil {
226                 return err
227         }
228
229         loadOldClientConfig(cluster, oc.Client)
230
231         if oc.SbatchArguments != nil {
232                 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
233         }
234         if oc.PollPeriod != nil {
235                 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
236         }
237         if oc.PrioritySpread != nil {
238                 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
239         }
240         if oc.CrunchRunCommand != nil {
241                 if len(*oc.CrunchRunCommand) >= 1 {
242                         cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
243                 }
244                 if len(*oc.CrunchRunCommand) >= 2 {
245                         cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
246                 }
247         }
248         if oc.ReserveExtraRAM != nil {
249                 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
250         }
251         if oc.MinRetryPeriod != nil {
252                 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
253         }
254         if oc.BatchSize != nil {
255                 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
256         }
257
258         cfg.Clusters[cluster.ClusterID] = *cluster
259         return nil
260 }
261
262 type oldWsConfig struct {
263         Client       *arvados.Client
264         Postgres     *arvados.PostgreSQLConnection
265         PostgresPool *int
266         Listen       *string
267         LogLevel     *string
268         LogFormat    *string
269
270         PingTimeout      *arvados.Duration
271         ClientEventQueue *int
272         ServerEventQueue *int
273
274         ManagementToken *string
275 }
276
277 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
278
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 == "" {
282                 return nil
283         }
284         var oc oldWsConfig
285         err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
286         if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
287                 return nil
288         } else if err != nil {
289                 return err
290         }
291
292         cluster, err := cfg.GetCluster("")
293         if err != nil {
294                 return err
295         }
296
297         loadOldClientConfig(cluster, oc.Client)
298
299         if oc.Postgres != nil {
300                 cluster.PostgreSQL.Connection = *oc.Postgres
301         }
302         if oc.PostgresPool != nil {
303                 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
304         }
305         if oc.Listen != nil {
306                 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
307         }
308         if oc.LogLevel != nil {
309                 cluster.SystemLogs.LogLevel = *oc.LogLevel
310         }
311         if oc.LogFormat != nil {
312                 cluster.SystemLogs.Format = *oc.LogFormat
313         }
314         if oc.PingTimeout != nil {
315                 cluster.API.SendTimeout = *oc.PingTimeout
316         }
317         if oc.ClientEventQueue != nil {
318                 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
319         }
320         if oc.ServerEventQueue != nil {
321                 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
322         }
323         if oc.ManagementToken != nil {
324                 cluster.ManagementToken = *oc.ManagementToken
325         }
326
327         cfg.Clusters[cluster.ClusterID] = *cluster
328         return nil
329 }
330
331 type oldKeepProxyConfig struct {
332         Client          *arvados.Client
333         Listen          *string
334         DisableGet      *bool
335         DisablePut      *bool
336         DefaultReplicas *int
337         Timeout         *arvados.Duration
338         PIDFile         *string
339         Debug           *bool
340         ManagementToken *string
341 }
342
343 const defaultKeepproxyConfigPath = "/etc/arvados/keepproxy/keepproxy.yml"
344
345 func (ldr *Loader) loadOldKeepproxyConfig(cfg *arvados.Config) error {
346         if ldr.KeepproxyPath == "" {
347                 return nil
348         }
349         var oc oldKeepProxyConfig
350         err := ldr.loadOldConfigHelper("keepproxy", ldr.KeepproxyPath, &oc)
351         if os.IsNotExist(err) && ldr.KeepproxyPath == defaultKeepproxyConfigPath {
352                 return nil
353         } else if err != nil {
354                 return err
355         }
356
357         cluster, err := cfg.GetCluster("")
358         if err != nil {
359                 return err
360         }
361
362         loadOldClientConfig(cluster, oc.Client)
363
364         if oc.Listen != nil {
365                 cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: *oc.Listen, Path: "/"}] = arvados.ServiceInstance{}
366         }
367         if oc.DefaultReplicas != nil {
368                 cluster.Collections.DefaultReplication = *oc.DefaultReplicas
369         }
370         if oc.Timeout != nil {
371                 cluster.API.KeepServiceRequestTimeout = *oc.Timeout
372         }
373         if oc.Debug != nil {
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"
378                 }
379         }
380         if oc.ManagementToken != nil {
381                 cluster.ManagementToken = *oc.ManagementToken
382         }
383
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)
388         }
389         if oc.DisableGet != nil && *oc.DisableGet {
390                 return unsupportedEntry("DisableGet")
391         }
392         if oc.DisablePut != nil && *oc.DisablePut {
393                 return unsupportedEntry("DisablePut")
394         }
395         if oc.PIDFile != nil && *oc.PIDFile != "" {
396                 return unsupportedEntry("PIDFile")
397         }
398
399         cfg.Clusters[cluster.ClusterID] = *cluster
400         return nil
401 }
402
403 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
404
405 type oldKeepWebConfig struct {
406         Client *arvados.Client
407
408         Listen *string
409
410         AnonymousTokens    *[]string
411         AttachmentOnlyHost *string
412         TrustAllContent    *bool
413
414         Cache struct {
415                 TTL                  *arvados.Duration
416                 UUIDTTL              *arvados.Duration
417                 MaxCollectionEntries *int
418                 MaxCollectionBytes   *int64
419                 MaxPermissionEntries *int
420                 MaxUUIDEntries       *int
421         }
422
423         // Hack to support old command line flag, which is a bool
424         // meaning "get actual token from environment".
425         deprecatedAllowAnonymous *bool
426
427         // Authorization token to be included in all health check requests.
428         ManagementToken *string
429 }
430
431 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
432         if ldr.KeepWebPath == "" {
433                 return nil
434         }
435         var oc oldKeepWebConfig
436         err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
437         if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
438                 return nil
439         } else if err != nil {
440                 return err
441         }
442
443         cluster, err := cfg.GetCluster("")
444         if err != nil {
445                 return err
446         }
447
448         loadOldClientConfig(cluster, oc.Client)
449
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{}
453         }
454         if oc.AttachmentOnlyHost != nil {
455                 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: *oc.AttachmentOnlyHost, Path: "/"}
456         }
457         if oc.ManagementToken != nil {
458                 cluster.ManagementToken = *oc.ManagementToken
459         }
460         if oc.TrustAllContent != nil {
461                 cluster.Collections.TrustAllContent = *oc.TrustAllContent
462         }
463         if oc.Cache.TTL != nil {
464                 cluster.Collections.WebDAVCache.TTL = *oc.Cache.TTL
465         }
466         if oc.Cache.UUIDTTL != nil {
467                 cluster.Collections.WebDAVCache.UUIDTTL = *oc.Cache.UUIDTTL
468         }
469         if oc.Cache.MaxCollectionEntries != nil {
470                 cluster.Collections.WebDAVCache.MaxCollectionEntries = *oc.Cache.MaxCollectionEntries
471         }
472         if oc.Cache.MaxCollectionBytes != nil {
473                 cluster.Collections.WebDAVCache.MaxCollectionBytes = *oc.Cache.MaxCollectionBytes
474         }
475         if oc.Cache.MaxPermissionEntries != nil {
476                 cluster.Collections.WebDAVCache.MaxPermissionEntries = *oc.Cache.MaxPermissionEntries
477         }
478         if oc.Cache.MaxUUIDEntries != nil {
479                 cluster.Collections.WebDAVCache.MaxUUIDEntries = *oc.Cache.MaxUUIDEntries
480         }
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.")
486                         }
487                 }
488         }
489
490         cfg.Clusters[cluster.ClusterID] = *cluster
491         return nil
492 }
493
494 const defaultGitHttpdConfigPath = "/etc/arvados/git-httpd/git-httpd.yml"
495
496 type oldGitHttpdConfig struct {
497         Client          *arvados.Client
498         Listen          *string
499         GitCommand      *string
500         GitoliteHome    *string
501         RepoRoot        *string
502         ManagementToken *string
503 }
504
505 func (ldr *Loader) loadOldGitHttpdConfig(cfg *arvados.Config) error {
506         if ldr.GitHttpdPath == "" {
507                 return nil
508         }
509         var oc oldGitHttpdConfig
510         err := ldr.loadOldConfigHelper("arv-git-httpd", ldr.GitHttpdPath, &oc)
511         if os.IsNotExist(err) && ldr.GitHttpdPath == defaultGitHttpdConfigPath {
512                 return nil
513         } else if err != nil {
514                 return err
515         }
516
517         cluster, err := cfg.GetCluster("")
518         if err != nil {
519                 return err
520         }
521
522         loadOldClientConfig(cluster, oc.Client)
523
524         if oc.Listen != nil {
525                 cluster.Services.GitHTTP.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
526         }
527         if oc.ManagementToken != nil {
528                 cluster.ManagementToken = *oc.ManagementToken
529         }
530         if oc.GitCommand != nil {
531                 cluster.Git.GitCommand = *oc.GitCommand
532         }
533         if oc.GitoliteHome != nil {
534                 cluster.Git.GitoliteHome = *oc.GitoliteHome
535         }
536         if oc.RepoRoot != nil {
537                 cluster.Git.Repositories = *oc.RepoRoot
538         }
539
540         cfg.Clusters[cluster.ClusterID] = *cluster
541         return nil
542 }
543
544 const defaultKeepBalanceConfigPath = "/etc/arvados/keep-balance/keep-balance.yml"
545
546 type oldKeepBalanceConfig struct {
547         Client              *arvados.Client
548         Listen              *string
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
557 }
558
559 func (ldr *Loader) loadOldKeepBalanceConfig(cfg *arvados.Config) error {
560         if ldr.KeepBalancePath == "" {
561                 return nil
562         }
563         var oc oldKeepBalanceConfig
564         err := ldr.loadOldConfigHelper("keep-balance", ldr.KeepBalancePath, &oc)
565         if os.IsNotExist(err) && ldr.KeepBalancePath == defaultKeepBalanceConfigPath {
566                 return nil
567         } else if err != nil {
568                 return err
569         }
570
571         cluster, err := cfg.GetCluster("")
572         if err != nil {
573                 return err
574         }
575
576         loadOldClientConfig(cluster, oc.Client)
577
578         if oc.Listen != nil {
579                 cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
580         }
581         if oc.ManagementToken != nil {
582                 cluster.ManagementToken = *oc.ManagementToken
583         }
584         if oc.RunPeriod != nil {
585                 cluster.Collections.BalancePeriod = *oc.RunPeriod
586         }
587         if oc.LostBlocksFile != nil {
588                 cluster.Collections.BlobMissingReport = *oc.LostBlocksFile
589         }
590         if oc.CollectionBatchSize != nil {
591                 cluster.Collections.BalanceCollectionBatch = *oc.CollectionBatchSize
592         }
593         if oc.CollectionBuffers != nil {
594                 cluster.Collections.BalanceCollectionBuffers = *oc.CollectionBuffers
595         }
596         if oc.RequestTimeout != nil {
597                 cluster.API.KeepServiceRequestTimeout = *oc.RequestTimeout
598         }
599
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."
601
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")
608                 }
609         }
610
611         if oc.KeepServiceList != nil {
612                 return fmt.Errorf(msg, "KeepServiceList")
613         }
614
615         cfg.Clusters[cluster.ClusterID] = *cluster
616         return nil
617 }
618
619 func (ldr *Loader) loadOldEnvironmentVariables(cfg *arvados.Config) error {
620         if os.Getenv("ARVADOS_API_TOKEN") == "" && os.Getenv("ARVADOS_API_HOST") == "" {
621                 return nil
622         }
623         cluster, err := cfg.GetCluster("")
624         if err != nil {
625                 return err
626         }
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
630         }
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)
634                 if err != nil {
635                         return fmt.Errorf("cannot parse ARVADOS_API_HOST: %s", err)
636                 }
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
640                 }
641         }
642         cfg.Clusters[cluster.ClusterID] = *cluster
643         return nil
644 }