2022-10-20 19:59:46 +00:00
|
|
|
package main
|
2022-10-16 18:33:31 +00:00
|
|
|
|
|
|
|
import (
|
2024-06-10 20:31:29 +00:00
|
|
|
"fmt"
|
2023-08-05 21:53:17 +00:00
|
|
|
"isle/bootstrap"
|
|
|
|
"isle/daemon"
|
2024-06-12 08:18:33 +00:00
|
|
|
"isle/garage/garagesrv"
|
2022-10-16 18:33:31 +00:00
|
|
|
)
|
|
|
|
|
2023-01-17 19:31:22 +00:00
|
|
|
func coalesceDaemonConfigAndBootstrap(
|
2022-10-26 22:23:39 +00:00
|
|
|
hostBootstrap bootstrap.Bootstrap,
|
|
|
|
daemonConfig daemon.Config,
|
2022-10-26 21:21:31 +00:00
|
|
|
) (
|
2024-06-17 18:51:02 +00:00
|
|
|
bootstrap.Bootstrap, error,
|
2022-10-26 21:21:31 +00:00
|
|
|
) {
|
2022-10-16 18:33:31 +00:00
|
|
|
|
2022-11-05 14:50:04 +00:00
|
|
|
host := bootstrap.Host{
|
2024-06-10 20:31:29 +00:00
|
|
|
HostAssigned: hostBootstrap.HostAssigned,
|
|
|
|
HostConfigured: bootstrap.HostConfigured{
|
|
|
|
Nebula: bootstrap.NebulaHost{
|
|
|
|
PublicAddr: daemonConfig.VPN.PublicAddr,
|
|
|
|
},
|
2022-11-05 14:50:04 +00:00
|
|
|
},
|
|
|
|
}
|
2022-10-16 18:33:31 +00:00
|
|
|
|
2022-10-26 21:21:31 +00:00
|
|
|
if allocs := daemonConfig.Storage.Allocations; len(allocs) > 0 {
|
2022-10-16 18:33:31 +00:00
|
|
|
|
2023-01-17 19:31:22 +00:00
|
|
|
for i, alloc := range allocs {
|
2022-10-28 22:09:18 +00:00
|
|
|
|
2024-06-12 08:18:33 +00:00
|
|
|
id, rpcPort, err := garagesrv.InitAlloc(alloc.MetaPath, alloc.RPCPort)
|
2022-10-28 22:09:18 +00:00
|
|
|
if err != nil {
|
2024-06-17 18:51:02 +00:00
|
|
|
return bootstrap.Bootstrap{}, fmt.Errorf("initializing alloc at %q: %w", alloc.MetaPath, err)
|
2022-10-28 22:09:18 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 18:33:31 +00:00
|
|
|
host.Garage.Instances = append(host.Garage.Instances, bootstrap.GarageHostInstance{
|
2022-10-28 22:09:18 +00:00
|
|
|
ID: id,
|
2023-01-17 19:31:22 +00:00
|
|
|
RPCPort: rpcPort,
|
2022-10-16 18:33:31 +00:00
|
|
|
S3APIPort: alloc.S3APIPort,
|
|
|
|
})
|
2023-01-17 19:31:22 +00:00
|
|
|
|
|
|
|
allocs[i].RPCPort = rpcPort
|
2022-10-16 18:33:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 22:23:39 +00:00
|
|
|
hostBootstrap.Hosts[host.Name] = host
|
2022-10-16 18:33:31 +00:00
|
|
|
|
2022-10-26 22:37:03 +00:00
|
|
|
if err := writeBootstrapToDataDir(hostBootstrap); err != nil {
|
2024-06-17 18:51:02 +00:00
|
|
|
return bootstrap.Bootstrap{}, fmt.Errorf("writing bootstrap file: %w", err)
|
2022-10-16 18:33:31 +00:00
|
|
|
}
|
|
|
|
|
2024-06-17 18:51:02 +00:00
|
|
|
return hostBootstrap, nil
|
2022-10-16 18:33:31 +00:00
|
|
|
}
|