1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
11 "git.curoverse.com/arvados.git/sdk/go/config"
14 const DefaultConfigFile = "/etc/arvados/config.yml"
17 Clusters map[string]Cluster
20 // GetConfig returns the current system config, loading it from
21 // configFile if needed.
22 func GetConfig(configFile string) (*Config, error) {
24 err := config.LoadFile(&cfg, configFile)
28 // GetCluster returns the cluster ID and config for the given
29 // cluster, or the default/only configured cluster if clusterID is "".
30 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
32 if len(sc.Clusters) == 0 {
33 return nil, fmt.Errorf("no clusters configured")
34 } else if len(sc.Clusters) > 1 {
35 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
37 for id, cc := range sc.Clusters {
43 if cc, ok := sc.Clusters[clusterID]; !ok {
44 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
46 cc.ClusterID = clusterID
52 ClusterID string `json:"-"`
53 ManagementToken string
54 NodeProfiles map[string]NodeProfile
55 InstanceTypes []InstanceType
56 HTTPRequestTimeout Duration
57 RemoteClusters map[string]RemoteCluster
61 type PostgreSQL struct {
62 Connection PostgreSQLConnection
65 type PostgreSQLConnection map[string]string
67 type RemoteCluster struct {
68 // API endpoint host or host:port; default is {id}.arvadosapi.com
70 // Perform a proxy request when a local client requests an
71 // object belonging to this remote.
73 // Scheme, default "https". Can be set to "http" for testing.
75 // Disable TLS verify. Can be set to true for testing.
79 type InstanceType struct {
89 // GetNodeProfile returns a NodeProfile for the given hostname. An
90 // error is returned if the appropriate configuration can't be
91 // determined (e.g., this does not appear to be a system node). If
92 // node is empty, use the OS-reported hostname.
93 func (cc *Cluster) GetNodeProfile(node string) (*NodeProfile, error) {
95 hostname, err := os.Hostname()
101 if cfg, ok := cc.NodeProfiles[node]; ok {
104 // If node is not listed, but "*" gives a default system node
105 // config, use the default config.
106 if cfg, ok := cc.NodeProfiles["*"]; ok {
109 return nil, fmt.Errorf("config does not provision host %q as a system node", node)
112 type NodeProfile struct {
113 Controller SystemServiceInstance `json:"arvados-controller"`
114 Health SystemServiceInstance `json:"arvados-health"`
115 Keepproxy SystemServiceInstance `json:"keepproxy"`
116 Keepstore SystemServiceInstance `json:"keepstore"`
117 Keepweb SystemServiceInstance `json:"keep-web"`
118 Nodemanager SystemServiceInstance `json:"arvados-node-manager"`
119 RailsAPI SystemServiceInstance `json:"arvados-api-server"`
120 Websocket SystemServiceInstance `json:"arvados-ws"`
121 Workbench SystemServiceInstance `json:"arvados-workbench"`
124 type ServiceName string
127 ServiceNameRailsAPI ServiceName = "arvados-api-server"
128 ServiceNameController ServiceName = "arvados-controller"
129 ServiceNameNodemanager ServiceName = "arvados-node-manager"
130 ServiceNameWorkbench ServiceName = "arvados-workbench"
131 ServiceNameWebsocket ServiceName = "arvados-ws"
132 ServiceNameKeepweb ServiceName = "keep-web"
133 ServiceNameKeepproxy ServiceName = "keepproxy"
134 ServiceNameKeepstore ServiceName = "keepstore"
137 // ServicePorts returns the configured listening address (or "" if
138 // disabled) for each service on the node.
139 func (np *NodeProfile) ServicePorts() map[ServiceName]string {
140 return map[ServiceName]string{
141 ServiceNameRailsAPI: np.RailsAPI.Listen,
142 ServiceNameController: np.Controller.Listen,
143 ServiceNameNodemanager: np.Nodemanager.Listen,
144 ServiceNameWorkbench: np.Workbench.Listen,
145 ServiceNameWebsocket: np.Websocket.Listen,
146 ServiceNameKeepweb: np.Keepweb.Listen,
147 ServiceNameKeepproxy: np.Keepproxy.Listen,
148 ServiceNameKeepstore: np.Keepstore.Listen,
152 type SystemServiceInstance struct {