2022-10-20 19:59:46 +00:00
|
|
|
package main
|
2022-10-16 18:33:31 +00:00
|
|
|
|
|
|
|
import (
|
2022-10-19 14:20:26 +00:00
|
|
|
"context"
|
2023-08-05 21:53:17 +00:00
|
|
|
"isle/bootstrap"
|
|
|
|
"isle/daemon"
|
|
|
|
"isle/garage"
|
2022-10-16 18:33:31 +00:00
|
|
|
"fmt"
|
2022-10-20 19:59:46 +00:00
|
|
|
"time"
|
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
|
|
|
) (
|
2023-01-17 19:31:22 +00:00
|
|
|
bootstrap.Bootstrap, daemon.Config, 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{
|
|
|
|
Name: hostBootstrap.HostName,
|
|
|
|
Nebula: bootstrap.NebulaHost{
|
|
|
|
SignedPublicCredentials: hostBootstrap.Nebula.SignedPublicCredentials,
|
|
|
|
PublicAddr: daemonConfig.VPN.PublicAddr,
|
|
|
|
},
|
|
|
|
}
|
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
|
|
|
|
2023-01-17 19:31:22 +00:00
|
|
|
id, rpcPort, err := garage.InitAlloc(alloc.MetaPath, alloc.RPCPort)
|
2022-10-28 22:09:18 +00:00
|
|
|
if err != nil {
|
2023-01-17 19:31:22 +00:00
|
|
|
return bootstrap.Bootstrap{}, daemon.Config{}, 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 {
|
2023-01-17 19:31:22 +00:00
|
|
|
return bootstrap.Bootstrap{}, daemon.Config{}, fmt.Errorf("writing bootstrap file: %w", err)
|
2022-10-16 18:33:31 +00:00
|
|
|
}
|
|
|
|
|
2023-01-17 19:31:22 +00:00
|
|
|
return hostBootstrap, daemonConfig, nil
|
2022-10-19 14:20:26 +00:00
|
|
|
}
|
2022-10-16 18:33:31 +00:00
|
|
|
|
2022-10-19 14:20:26 +00:00
|
|
|
func doOnce(ctx context.Context, fn func(context.Context) error) error {
|
|
|
|
for {
|
|
|
|
if err := fn(ctx); err == nil {
|
|
|
|
return nil
|
|
|
|
} else if ctxErr := ctx.Err(); ctxErr != nil {
|
|
|
|
return ctxErr
|
|
|
|
}
|
2022-10-16 18:33:31 +00:00
|
|
|
|
2022-11-13 13:55:25 +00:00
|
|
|
time.Sleep(1 * time.Second)
|
2022-10-16 18:33:31 +00:00
|
|
|
}
|
|
|
|
}
|