1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
13 "git.curoverse.com/arvados.git/sdk/go/config"
16 const DefaultConfigFile = "/etc/arvados/config.yml"
19 Clusters map[string]Cluster
22 // GetConfig returns the current system config, loading it from
23 // configFile if needed.
24 func GetConfig(configFile string) (*Config, error) {
26 err := config.LoadFile(&cfg, configFile)
30 // GetCluster returns the cluster ID and config for the given
31 // cluster, or the default/only configured cluster if clusterID is "".
32 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
34 if len(sc.Clusters) == 0 {
35 return nil, fmt.Errorf("no clusters configured")
36 } else if len(sc.Clusters) > 1 {
37 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
39 for id, cc := range sc.Clusters {
45 if cc, ok := sc.Clusters[clusterID]; !ok {
46 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
48 cc.ClusterID = clusterID
54 ClusterID string `json:"-"`
55 ManagementToken string
56 SystemRootToken string
58 InstanceTypes InstanceTypeMap
59 Containers ContainersConfig
60 RemoteClusters map[string]RemoteCluster
64 AsyncPermissionsUpdateInterval Duration
66 MaxIndexDatabaseRead int
67 MaxItemsPerResponse int
68 MaxRequestAmplification int
70 RailsSessionSecretToken string
71 RequestTimeout Duration
76 UnloggedAttributes []string
81 DefaultReplication int
82 BlobSigningTTL Duration
83 DefaultTrashLifetime Duration
84 TrashSweepInterval Duration
85 CollectionVersioning bool
86 PreserveVersionIfIdle Duration
92 ProviderAppSecret string
96 MailchimpAPIKey string
97 MailchimpListID string
98 SendUserSetupNotificationEmail string
99 IssueReporterEmailFrom string
100 IssueReporterEmailTo string
101 SupportEmailAddress string
107 MaxRequestLogParamsSize int
115 AdminNotifierEmailFrom string
116 AutoAdminFirstUser bool
117 AutoAdminUserWithEmail string
118 AutoSetupNewUsers bool
119 AutoSetupNewUsersWithRepository bool
120 AutoSetupNewUsersWithVmUUID string
121 AutoSetupUsernameBlacklist []string
122 EmailSubjectPrefix string
123 NewInactiveUserNotificationRecipients []string
124 NewUserNotificationRecipients []string
125 NewUsersAreActive bool
126 UserNotifierEmailFrom string
127 UserProfileNotificationAddress string
131 type Services struct {
134 DispatchCloud Service
144 WebDAVDownload Service
152 type Service struct {
153 InternalURLs map[URL]ServiceInstance
157 // URL is a url.URL that is also usable as a JSON key/value.
160 // UnmarshalText implements encoding.TextUnmarshaler so URL can be
161 // used as a JSON key/value.
162 func (su *URL) UnmarshalText(text []byte) error {
163 u, err := url.Parse(string(text))
170 func (su URL) MarshalText() ([]byte, error) {
171 return []byte(fmt.Sprintf("%s", (*url.URL)(&su).String())), nil
174 type ServiceInstance struct{}
176 type PostgreSQL struct {
177 Connection PostgreSQLConnection
181 type PostgreSQLConnection map[string]string
183 type RemoteCluster struct {
191 type InstanceType struct {
197 IncludedScratch ByteSize
198 AddedScratch ByteSize
203 type ContainersConfig struct {
204 CloudVMs CloudVMsConfig
205 DefaultKeepCacheRAM ByteSize
206 DispatchPrivateKey string
207 LogReuseDecisions bool
209 MaxDispatchAttempts int
211 StaleLockTimeout Duration
212 SupportedDockerImageFormats []string
213 UsePreemptibleInstances bool
217 GitInternalDir string
218 DefaultDockerImage string
219 CrunchJobWrapper string
221 CrunchRefreshTrigger string
222 ReuseJobIfOutputsDiffer bool
227 LogSecondsBetweenEvents int
228 LogThrottlePeriod Duration
231 LimitLogBytesPerJob int
232 LogPartialLineThrottlePeriod Duration
233 LogUpdatePeriod Duration
234 LogUpdateSize ByteSize
238 DNSServerConfDir string
239 DNSServerConfTemplate string
240 DNSServerReloadCommand string
241 DNSServerUpdateCommand string
242 ComputeNodeDomain string
243 ComputeNodeNameservers []string
244 AssignNodeHostname string
249 type CloudVMsConfig struct {
252 BootProbeCommand string
254 MaxCloudOpsPerSecond int
255 MaxProbesPerSecond int
256 PollInterval Duration
257 ProbeInterval Duration
259 SyncInterval Duration
260 TimeoutBooting Duration
262 TimeoutProbe Duration
263 TimeoutShutdown Duration
264 TimeoutSignal Duration
266 ResourceTags map[string]string
270 DriverParameters json.RawMessage
273 type InstanceTypeMap map[string]InstanceType
275 var errDuplicateInstanceTypeName = errors.New("duplicate instance type name")
277 // UnmarshalJSON handles old config files that provide an array of
278 // instance types instead of a hash.
279 func (it *InstanceTypeMap) UnmarshalJSON(data []byte) error {
280 if len(data) > 0 && data[0] == '[' {
281 var arr []InstanceType
282 err := json.Unmarshal(data, &arr)
290 *it = make(map[string]InstanceType, len(arr))
291 for _, t := range arr {
292 if _, ok := (*it)[t.Name]; ok {
293 return errDuplicateInstanceTypeName
295 if t.ProviderType == "" {
296 t.ProviderType = t.Name
299 t.Scratch = t.IncludedScratch + t.AddedScratch
300 } else if t.AddedScratch == 0 {
301 t.AddedScratch = t.Scratch - t.IncludedScratch
302 } else if t.IncludedScratch == 0 {
303 t.IncludedScratch = t.Scratch - t.AddedScratch
306 if t.Scratch != (t.IncludedScratch + t.AddedScratch) {
307 return fmt.Errorf("%v: Scratch != (IncludedScratch + AddedScratch)", t.Name)
313 var hash map[string]InstanceType
314 err := json.Unmarshal(data, &hash)
318 // Fill in Name field (and ProviderType field, if not
319 // specified) using hash key.
320 *it = InstanceTypeMap(hash)
321 for name, t := range *it {
323 if t.ProviderType == "" {
324 t.ProviderType = name
331 type ServiceName string
334 ServiceNameRailsAPI ServiceName = "arvados-api-server"
335 ServiceNameController ServiceName = "arvados-controller"
336 ServiceNameDispatchCloud ServiceName = "arvados-dispatch-cloud"
337 ServiceNameHealth ServiceName = "arvados-health"
338 ServiceNameNodemanager ServiceName = "arvados-node-manager"
339 ServiceNameWorkbench1 ServiceName = "arvados-workbench1"
340 ServiceNameWorkbench2 ServiceName = "arvados-workbench2"
341 ServiceNameWebsocket ServiceName = "arvados-ws"
342 ServiceNameKeepbalance ServiceName = "keep-balance"
343 ServiceNameKeepweb ServiceName = "keep-web"
344 ServiceNameKeepproxy ServiceName = "keepproxy"
345 ServiceNameKeepstore ServiceName = "keepstore"
348 // Map returns all services as a map, suitable for iterating over all
349 // services or looking up a service by name.
350 func (svcs Services) Map() map[ServiceName]Service {
351 return map[ServiceName]Service{
352 ServiceNameRailsAPI: svcs.RailsAPI,
353 ServiceNameController: svcs.Controller,
354 ServiceNameDispatchCloud: svcs.DispatchCloud,
355 ServiceNameHealth: svcs.Health,
356 ServiceNameNodemanager: svcs.Nodemanager,
357 ServiceNameWorkbench1: svcs.Workbench1,
358 ServiceNameWorkbench2: svcs.Workbench2,
359 ServiceNameWebsocket: svcs.Websocket,
360 ServiceNameKeepbalance: svcs.Keepbalance,
361 ServiceNameKeepweb: svcs.WebDAV,
362 ServiceNameKeepproxy: svcs.Keepproxy,
363 ServiceNameKeepstore: svcs.Keepstore,