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"].InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
208 p, err := url.Parse(r)
209 cluster.Containers.SLURM.KeepServices["00000-bi6l4-000000000000000"].InternalURLs[arvados.URL(p)] = struct{}{}
213 // update config using values from an crunch-dispatch-slurm config file.
214 func (ldr *Loader) loadOldCrunchDispatchSlurmConfig(cfg *arvados.Config) error {
215 if ldr.CrunchDispatchSlurmPath == "" {
218 var oc oldCrunchDispatchSlurmConfig
219 err := ldr.loadOldConfigHelper("crunch-dispatch-slurm", ldr.CrunchDispatchSlurmPath, &oc)
220 if os.IsNotExist(err) && (ldr.CrunchDispatchSlurmPath == defaultCrunchDispatchSlurmConfigPath) {
222 } else if err != nil {
226 cluster, err := cfg.GetCluster("")
231 loadOldClientConfig(cluster, oc.Client)
233 if oc.SbatchArguments != nil {
234 cluster.Containers.SLURM.SbatchArgumentsList = *oc.SbatchArguments
236 if oc.PollPeriod != nil {
237 cluster.Containers.CloudVMs.PollInterval = *oc.PollPeriod
239 if oc.PrioritySpread != nil {
240 cluster.Containers.SLURM.PrioritySpread = *oc.PrioritySpread
242 if oc.CrunchRunCommand != nil {
243 if len(*oc.CrunchRunCommand) >= 1 {
244 cluster.Containers.CrunchRunCommand = (*oc.CrunchRunCommand)[0]
246 if len(*oc.CrunchRunCommand) >= 2 {
247 cluster.Containers.CrunchRunArgumentsList = (*oc.CrunchRunCommand)[1:]
250 if oc.ReserveExtraRAM != nil {
251 cluster.Containers.ReserveExtraRAM = arvados.ByteSize(*oc.ReserveExtraRAM)
253 if oc.MinRetryPeriod != nil {
254 cluster.Containers.MinRetryPeriod = *oc.MinRetryPeriod
256 if oc.BatchSize != nil {
257 cluster.API.MaxItemsPerResponse = int(*oc.BatchSize)
260 cfg.Clusters[cluster.ClusterID] = *cluster
264 type oldWsConfig struct {
265 Client *arvados.Client
266 Postgres *arvados.PostgreSQLConnection
272 PingTimeout *arvados.Duration
273 ClientEventQueue *int
274 ServerEventQueue *int
276 ManagementToken *string
279 const defaultWebsocketConfigPath = "/etc/arvados/ws/ws.yml"
281 // update config using values from an crunch-dispatch-slurm config file.
282 func (ldr *Loader) loadOldWebsocketConfig(cfg *arvados.Config) error {
283 if ldr.WebsocketPath == "" {
287 err := ldr.loadOldConfigHelper("arvados-ws", ldr.WebsocketPath, &oc)
288 if os.IsNotExist(err) && ldr.WebsocketPath == defaultWebsocketConfigPath {
290 } else if err != nil {
294 cluster, err := cfg.GetCluster("")
299 loadOldClientConfig(cluster, oc.Client)
301 if oc.Postgres != nil {
302 cluster.PostgreSQL.Connection = *oc.Postgres
304 if oc.PostgresPool != nil {
305 cluster.PostgreSQL.ConnectionPool = *oc.PostgresPool
307 if oc.Listen != nil {
308 cluster.Services.Websocket.InternalURLs[arvados.URL{Host: *oc.Listen}] = arvados.ServiceInstance{}
310 if oc.LogLevel != nil {
311 cluster.SystemLogs.LogLevel = *oc.LogLevel
313 if oc.LogFormat != nil {
314 cluster.SystemLogs.Format = *oc.LogFormat
316 if oc.PingTimeout != nil {
317 cluster.API.SendTimeout = *oc.PingTimeout
319 if oc.ClientEventQueue != nil {
320 cluster.API.WebsocketClientEventQueue = *oc.ClientEventQueue
322 if oc.ServerEventQueue != nil {
323 cluster.API.WebsocketServerEventQueue = *oc.ServerEventQueue
325 if oc.ManagementToken != nil {
326 cluster.ManagementToken = *oc.ManagementToken
329 cfg.Clusters[cluster.ClusterID] = *cluster