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 const defaultKeepstoreConfigPath = "/etc/arvados/keepstore/keepstore.yml"
108 type oldKeepstoreConfig struct {
112 func (ldr *Loader) loadOldConfigHelper(component, path string, target interface{}) error {
116 buf, err := ioutil.ReadFile(path)
121 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)
123 err = yaml.Unmarshal(buf, target)
125 return fmt.Errorf("%s: %s", path, err)
130 // update config using values from an old-style keepstore config file.
131 func (ldr *Loader) loadOldKeepstoreConfig(cfg *arvados.Config) error {
132 if ldr.KeepstorePath == "" {
135 var oc oldKeepstoreConfig
136 err := ldr.loadOldConfigHelper("keepstore", ldr.KeepstorePath, &oc)
137 if os.IsNotExist(err) && (ldr.KeepstorePath == defaultKeepstoreConfigPath) {
139 } else if err != nil {
143 cluster, err := cfg.GetCluster("")
148 if v := oc.Debug; v == nil {
149 } else if *v && cluster.SystemLogs.LogLevel != "debug" {
150 cluster.SystemLogs.LogLevel = "debug"
151 } else if !*v && cluster.SystemLogs.LogLevel != "info" {
152 cluster.SystemLogs.LogLevel = "info"
155 cfg.Clusters[cluster.ClusterID] = *cluster
159 type oldCrunchDispatchSlurmConfig struct {
160 Client *arvados.Client
162 SbatchArguments *[]string
163 PollPeriod *arvados.Duration
164 PrioritySpread *int64
166 // crunch-run command to invoke. The container UUID will be
167 // appended. If nil, []string{"crunch-run"} will be used.
169 // Example: []string{"crunch-run", "--cgroup-parent-subsystem=memory"}
170 CrunchRunCommand *[]string
172 // Extra RAM to reserve (in Bytes) for SLURM job, in addition
173 // to the amount specified in the container's RuntimeConstraints
174 ReserveExtraRAM *int64
176 // Minimum time between two attempts to run the same container
177 MinRetryPeriod *arvados.Duration
179 // Batch size for container queries
183 const defaultCrunchDispatchSlurmConfigPath = "/etc/arvados/crunch-dispatch-slurm/crunch-dispatch-slurm.yml"
185 func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
189 if client.APIHost != "" {
190 cluster.Services.Controller.ExternalURL.Host = client.APIHost
192 if client.Scheme != "" {
193 cluster.Services.Controller.ExternalURL.Scheme = client.Scheme
195 cluster.Services.Controller.ExternalURL.Scheme = "https"
197 if client.AuthToken != "" {
198 cluster.SystemRootToken = client.AuthToken
200 cluster.TLS.Insecure = client.Insecure
201 for _, r := range client.KeepServiceURIs {
202 if cluster.Containers.SLURM.KeepServices == nil {
203 cluster.Containers.SLURM.KeepServices = make(map[string]arvados.Service)
205 if cluster.Containers.SLURM.KeepServices["00000-bi6l4-000000000000000"].InternalURLs == nil {
206 cluster.Containers.SLURM.KeepServices["00000-bi6l4-000000000000000"] = arvados.Service{InternalURLs: make(map[arvados.URL]arvados.ServiceInstance)}
208 p, err := url.Parse(r)
210 cluster.Containers.SLURM.KeepServices["00000-bi6l4-000000000000000"].InternalURLs[arvados.URL(*p)] = struct{}{}
215 // update config using values from an crunch-dispatch-slurm config file.
216 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
217 if ldr.CrunchDispatchSlurmPath == "" {
220 var oc oldCrunchDispatchSlurmConfig
221 err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
222 if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
224 } else if err != nil {
228 cluster, err := cfg.GetCluster("")
233 loadOldClientConfig(cluster, oc.Client)
235 if oc.SbatchArguments != nil {
236 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
238 if oc.PollPeriod != nil {
239 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
241 if oc.PrioritySpread != nil {
242 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
244 if oc.CrunchRunCommand != nil {
245 if len(*oc.CrunchRunCommand) >= 1 {
246 cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
248 if len(*oc.CrunchRunCommand) >= 2 {
249 cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
252 if oc.ReserveExtraRAM != nil {
253 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
255 if oc.MinRetryPeriod != nil {
256 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
258 if oc.BatchSize != nil {
259 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
262 cfg.Clusters[cluster.ClusterID] = *cluster
266 type oldWsConfig struct {
267 Client *arvados.Client
268 Postgres *arvados.PostgreSQLConnection
274 PingTimeout *arvados.Duration
275 ClientEventQueue *int
276 ServerEventQueue *int
278 ManagementToken *string
281 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
283 // update config using values from an crunch-dispatch-slurm config file.
284 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
285 if ldr.WebsocketPath == "" {
289 err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
290 if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
292 } else if err != nil {
296 cluster, err := cfg.GetCluster("")
301 loadOldClientConfig(cluster, oc.Client)
303 if oc.Postgres != nil {
304 cluster.PostgreSQL.Connection = *oc.Postgres
306 if oc.PostgresPool != nil {
307 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
309 if oc.Listen != nil {
310 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
312 if oc.LogLevel != nil {
313 cluster.SystemLogs.LogLevel = *oc.LogLevel
315 if oc.LogFormat != nil {
316 cluster.SystemLogs.Format = *oc.LogFormat
318 if oc.PingTimeout != nil {
319 cluster.API.SendTimeout = *oc.PingTimeout
321 if oc.ClientEventQueue != nil {
322 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
324 if oc.ServerEventQueue != nil {
325 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
327 if oc.ManagementToken != nil {
328 cluster.ManagementToken = *oc.ManagementToken
331 cfg.Clusters[cluster.ClusterID] = *cluster