You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
isle/entrypoint/src/cmd/entrypoint/daemon_util.go

65 lines
1.5 KiB

package main
import (
"context"
"isle/bootstrap"
"isle/daemon"
"isle/garage"
"fmt"
"time"
)
func coalesceDaemonConfigAndBootstrap(
hostBootstrap bootstrap.Bootstrap,
daemonConfig daemon.Config,
) (
bootstrap.Bootstrap, daemon.Config, error,
) {
host := bootstrap.Host{
Name: hostBootstrap.HostName,
Nebula: bootstrap.NebulaHost{
SignedPublicCredentials: hostBootstrap.Nebula.SignedPublicCredentials,
PublicAddr: daemonConfig.VPN.PublicAddr,
},
}
if allocs := daemonConfig.Storage.Allocations; len(allocs) > 0 {
for i, alloc := range allocs {
id, rpcPort, err := garage.InitAlloc(alloc.MetaPath, alloc.RPCPort)
if err != nil {
return bootstrap.Bootstrap{}, daemon.Config{}, fmt.Errorf("initializing alloc at %q: %w", alloc.MetaPath, err)
}
host.Garage.Instances = append(host.Garage.Instances, bootstrap.GarageHostInstance{
ID: id,
RPCPort: rpcPort,
S3APIPort: alloc.S3APIPort,
})
allocs[i].RPCPort = rpcPort
}
}
hostBootstrap.Hosts[host.Name] = host
if err := writeBootstrapToDataDir(hostBootstrap); err != nil {
return bootstrap.Bootstrap{}, daemon.Config{}, fmt.Errorf("writing bootstrap file: %w", err)
}
return hostBootstrap, daemonConfig, nil
}
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
}
time.Sleep(1 * time.Second)
}
}