1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
13 "git.curoverse.com/arvados.git/sdk/go/arvados"
14 "github.com/ghodss/yaml"
17 type deprRequestLimits struct {
18 MaxItemsPerResponse *int
19 MultiClusterRequestConcurrency *int
22 type deprCluster struct {
23 RequestLimits deprRequestLimits
24 NodeProfiles map[string]nodeProfile
27 type deprecatedConfig struct {
28 Clusters map[string]deprCluster
31 type nodeProfile struct {
32 Controller systemServiceInstance `json:"arvados-controller"`
33 Health systemServiceInstance `json:"arvados-health"`
34 Keepbalance systemServiceInstance `json:"keep-balance"`
35 Keepproxy systemServiceInstance `json:"keepproxy"`
36 Keepstore systemServiceInstance `json:"keepstore"`
37 Keepweb systemServiceInstance `json:"keep-web"`
38 Nodemanager systemServiceInstance `json:"arvados-node-manager"`
39 DispatchCloud systemServiceInstance `json:"arvados-dispatch-cloud"`
40 RailsAPI systemServiceInstance `json:"arvados-api-server"`
41 Websocket systemServiceInstance `json:"arvados-ws"`
42 Workbench1 systemServiceInstance `json:"arvados-workbench"`
45 type systemServiceInstance struct {
51 func (ldr *Loader) applyDeprecatedConfig(cfg *arvados.Config) error {
52 var dc deprecatedConfig
53 err := yaml.Unmarshal(ldr.configdata, &dc)
57 hostname, err := os.Hostname()
61 for id, dcluster := range dc.Clusters {
62 cluster, ok := cfg.Clusters[id]
64 return fmt.Errorf("can't load legacy config %q that is not present in current config", id)
66 for name, np := range dcluster.NodeProfiles {
67 if name == "*" || name == os.Getenv("ARVADOS_NODE_PROFILE") || name == hostname {
69 } else if ldr.Logger != nil {
70 ldr.Logger.Warnf("overriding Clusters.%s.Services using Clusters.%s.NodeProfiles.%s (guessing %q is a hostname)", id, id, name, name)
72 applyDeprecatedNodeProfile(name, np.RailsAPI, &cluster.Services.RailsAPI)
73 applyDeprecatedNodeProfile(name, np.Controller, &cluster.Services.Controller)
74 applyDeprecatedNodeProfile(name, np.DispatchCloud, &cluster.Services.DispatchCloud)
76 if dst, n := &cluster.API.MaxItemsPerResponse, dcluster.RequestLimits.MaxItemsPerResponse; n != nil && *n != *dst {
79 if dst, n := &cluster.API.MaxRequestAmplification, dcluster.RequestLimits.MultiClusterRequestConcurrency; n != nil && *n != *dst {
82 cfg.Clusters[id] = cluster
87 func applyDeprecatedNodeProfile(hostname string, ssi systemServiceInstance, svc *arvados.Service) {
92 if svc.InternalURLs == nil {
93 svc.InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
99 if strings.HasPrefix(host, ":") {
100 host = hostname + host
102 svc.InternalURLs[arvados.URL{Scheme: scheme, Host: host}] = arvados.ServiceInstance{}
105 const defaultKeepstoreConfigPath = "/etc/arvados/keepstore/keepstore.yml"
107 type oldKeepstoreConfig struct {
111 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
115 buf, err := ioutil.ReadFile(path)
120 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)
122 err = yaml.Unmarshal(buf, target)
124 return fmt.Errorf("%s: %s", path, err)
129 // update config using values from an old-style keepstore config file.
130 func (ldr *Loader) loadOldKeepstoreConfig(cfg *arvados.Config) error {
131 if ldr.KeepstorePath == "" {
134 var oc oldKeepstoreConfig
135 err := ldr.loadOldConfigHelper("keepstore", ldr.KeepstorePath, &oc)
136 if os.IsNotExist(err) && (ldr.KeepstorePath == defaultKeepstoreConfigPath) {
138 } else if err != nil {
142 cluster, err := cfg.GetCluster("")
147 if v := oc.Debug; v == nil {
148 } else if *v && cluster.SystemLogs.LogLevel != "debug" {
149 cluster.SystemLogs.LogLevel = "debug"
150 } else if !*v && cluster.SystemLogs.LogLevel != "info" {
151 cluster.SystemLogs.LogLevel = "info"
154 cfg.Clusters[cluster.ClusterID] = *cluster
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
191 if client.Scheme != "" {
192 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
194 cluster.Services.Controller.ExternalURL.Scheme = "https"
196 if client.AuthToken != "" {
197 cluster.SystemRootToken = client.AuthToken
199 cluster.TLS.Insecure = client.Insecure
201 for i, u := range client.KeepServiceURIs {
207 cluster.Containers.SLURM.SbatchEnvironmentVariables = map[string]string{"ARVADOS_KEEP_SERVICES": ks}
210 // update config using values from an crunch-dispatch-slurm config file.
211 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
212 if ldr.CrunchDispatchSlurmPath == "" {
215 var oc oldCrunchDispatchSlurmConfig
216 err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
217 if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
219 } else if err != nil {
223 cluster, err := cfg.GetCluster("")
228 loadOldClientConfig(cluster, oc.Client)
230 if oc.SbatchArguments != nil {
231 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
233 if oc.PollPeriod != nil {
234 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
236 if oc.PrioritySpread != nil {
237 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
239 if oc.CrunchRunCommand != nil {
240 if len(*oc.CrunchRunCommand) >= 1 {
241 cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
243 if len(*oc.CrunchRunCommand) >= 2 {
244 cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
247 if oc.ReserveExtraRAM != nil {
248 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
250 if oc.MinRetryPeriod != nil {
251 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
253 if oc.BatchSize != nil {
254 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
257 cfg.Clusters[cluster.ClusterID] = *cluster
261 type oldWsConfig struct {
262 Client *arvados.Client
263 Postgres *arvados.PostgreSQLConnection
269 PingTimeout *arvados.Duration
270 ClientEventQueue *int
271 ServerEventQueue *int
273 ManagementToken *string
276 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
278 // update config using values from an crunch-dispatch-slurm config file.
279 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
280 if ldr.WebsocketPath == "" {
284 err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
285 if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
287 } else if err != nil {
291 cluster, err := cfg.GetCluster("")
296 loadOldClientConfig(cluster, oc.Client)
298 if oc.Postgres != nil {
299 cluster.PostgreSQL.Connection = *oc.Postgres
301 if oc.PostgresPool != nil {
302 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
304 if oc.Listen != nil {
305 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
307 if oc.LogLevel != nil {
308 cluster.SystemLogs.LogLevel = *oc.LogLevel
310 if oc.LogFormat != nil {
311 cluster.SystemLogs.Format = *oc.LogFormat
313 if oc.PingTimeout != nil {
314 cluster.API.SendTimeout = *oc.PingTimeout
316 if oc.ClientEventQueue != nil {
317 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
319 if oc.ServerEventQueue != nil {
320 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
322 if oc.ManagementToken != nil {
323 cluster.ManagementToken = *oc.ManagementToken
326 cfg.Clusters[cluster.ClusterID] = *cluster
330 const defaultKeepWebConfigPath = "/etc/arvados/keep-web/keep-web.yml"
332 type oldKeepWebConfig struct {
333 Client *arvados.Client
337 AnonymousTokens []string
338 AttachmentOnlyHost string
343 UUIDTTL arvados.Duration
344 MaxCollectionEntries int
345 MaxCollectionBytes int64
346 MaxPermissionEntries int
350 // Hack to support old command line flag, which is a bool
351 // meaning "get actual token from environment".
352 deprecatedAllowAnonymous bool
354 // Authorization token to be included in all health check requests.
355 ManagementToken string
358 func (ldr *Loader) loadOldKeepWebConfig(cfg *arvados.Config) error {
359 if ldr.KeepWebPath == "" {
362 var oc oldKeepWebConfig
363 err := ldr.loadOldConfigHelper("keep-web", ldr.KeepWebPath, &oc)
364 if os.IsNotExist(err) && ldr.KeepWebPath == defaultKeepWebConfigPath {
366 } else if err != nil {
370 cluster, err := cfg.GetCluster("")
375 loadOldClientConfig(cluster, oc.Client)
377 cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: oc.Listen}] = arvados.ServiceInstance{}
378 cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: oc.Listen}] = arvados.ServiceInstance{}
379 cluster.Services.WebDAVDownload.ExternalURL = arvados.URL{Host: oc.AttachmentOnlyHost}
380 cluster.TLS.Insecure = oc.Client.Insecure
381 cluster.ManagementToken = oc.ManagementToken
382 cluster.Collections.TrustAllContent = oc.TrustAllContent
383 cluster.Collections.WebDAVCache.TTL = oc.Cache.TTL
384 cluster.Collections.WebDAVCache.UUIDTTL = oc.Cache.UUIDTTL
385 cluster.Collections.WebDAVCache.MaxCollectionEntries = oc.Cache.MaxCollectionEntries
386 cluster.Collections.WebDAVCache.MaxCollectionBytes = oc.Cache.MaxCollectionBytes
387 cluster.Collections.WebDAVCache.MaxPermissionEntries = oc.Cache.MaxPermissionEntries
388 cluster.Collections.WebDAVCache.MaxUUIDEntries = oc.Cache.MaxUUIDEntries
389 if len(oc.AnonymousTokens) > 0 {
390 cluster.Users.AnonymousUserToken = oc.AnonymousTokens[0]
391 if len(oc.AnonymousTokens) > 1 {
392 ldr.Logger.Warn("More than 1 anonymous tokens configured, using only the first and discarding the rest.")
396 cfg.Clusters[cluster.ClusterID] = *cluster