Implement network.Loader, will be helpful for testing Daemon
This commit is contained in:
parent
bfa0dc457f
commit
f0cb29b553
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"isle/daemon"
|
"isle/daemon"
|
||||||
"isle/daemon/daecommon"
|
"isle/daemon/daecommon"
|
||||||
|
"isle/daemon/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO it would be good to have an `isle daemon config-check` kind of command,
|
// TODO it would be good to have an `isle daemon config-check` kind of command,
|
||||||
@ -49,9 +50,17 @@ var subCmdDaemon = subCmd{
|
|||||||
return fmt.Errorf("loading daemon config: %w", err)
|
return fmt.Errorf("loading daemon config: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
daemonInst, err := daemon.New(
|
networkLoader, err := network.NewLoader(
|
||||||
ctx, logger, daemonConfig, envBinDirPath, nil,
|
ctx,
|
||||||
|
logger.WithNamespace("loader"),
|
||||||
|
envBinDirPath,
|
||||||
|
nil,
|
||||||
)
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("instantiating network loader: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
daemonInst, err := daemon.New(ctx, logger, networkLoader, daemonConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("starting daemon: %w", err)
|
return fmt.Errorf("starting daemon: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -17,18 +17,6 @@ import (
|
|||||||
"isle/toolkit"
|
"isle/toolkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Opts are optional parameters which can be passed in when initializing a new
|
|
||||||
// Children instance. A nil Opts is equivalent to a zero value.
|
|
||||||
type Opts struct{}
|
|
||||||
|
|
||||||
func (o *Opts) withDefaults() *Opts {
|
|
||||||
if o == nil {
|
|
||||||
o = new(Opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
// Children manages all child processes of a network. Child processes are
|
// Children manages all child processes of a network. Child processes are
|
||||||
// comprised of:
|
// comprised of:
|
||||||
// - nebula
|
// - nebula
|
||||||
@ -39,7 +27,6 @@ type Children struct {
|
|||||||
binDirPath string
|
binDirPath string
|
||||||
runtimeDir toolkit.Dir
|
runtimeDir toolkit.Dir
|
||||||
garageAdminToken string
|
garageAdminToken string
|
||||||
opts Opts
|
|
||||||
|
|
||||||
garageRPCSecret string
|
garageRPCSecret string
|
||||||
|
|
||||||
@ -59,12 +46,9 @@ func New(
|
|||||||
runtimeDir toolkit.Dir,
|
runtimeDir toolkit.Dir,
|
||||||
garageAdminToken string,
|
garageAdminToken string,
|
||||||
hostBootstrap bootstrap.Bootstrap,
|
hostBootstrap bootstrap.Bootstrap,
|
||||||
opts *Opts,
|
|
||||||
) (
|
) (
|
||||||
*Children, error,
|
*Children, error,
|
||||||
) {
|
) {
|
||||||
opts = opts.withDefaults()
|
|
||||||
|
|
||||||
logger.Info(ctx, "Loading secrets")
|
logger.Info(ctx, "Loading secrets")
|
||||||
garageRPCSecret, err := daecommon.GetGarageRPCSecret(ctx, secretsStore)
|
garageRPCSecret, err := daecommon.GetGarageRPCSecret(ctx, secretsStore)
|
||||||
if err != nil && !errors.Is(err, secrets.ErrNotFound) {
|
if err != nil && !errors.Is(err, secrets.ErrNotFound) {
|
||||||
@ -76,7 +60,6 @@ func New(
|
|||||||
binDirPath: binDirPath,
|
binDirPath: binDirPath,
|
||||||
runtimeDir: runtimeDir,
|
runtimeDir: runtimeDir,
|
||||||
garageAdminToken: garageAdminToken,
|
garageAdminToken: garageAdminToken,
|
||||||
opts: *opts,
|
|
||||||
garageRPCSecret: garageRPCSecret,
|
garageRPCSecret: garageRPCSecret,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,11 +7,9 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"isle/bootstrap"
|
"isle/bootstrap"
|
||||||
"isle/daemon/children"
|
|
||||||
"isle/daemon/daecommon"
|
"isle/daemon/daecommon"
|
||||||
"isle/daemon/network"
|
"isle/daemon/network"
|
||||||
"isle/nebula"
|
"isle/nebula"
|
||||||
"isle/toolkit"
|
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -19,26 +17,6 @@ import (
|
|||||||
"dev.mediocregopher.com/mediocre-go-lib.git/mlog"
|
"dev.mediocregopher.com/mediocre-go-lib.git/mlog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Opts are optional parameters which can be passed in when initializing a new
|
|
||||||
// Daemon instance. A nil Opts is equivalent to a zero value.
|
|
||||||
type Opts struct {
|
|
||||||
ChildrenOpts *children.Opts
|
|
||||||
// Defaults to that returned by daecommon.GetEnvVars.
|
|
||||||
EnvVars daecommon.EnvVars
|
|
||||||
}
|
|
||||||
|
|
||||||
func (o *Opts) withDefaults() *Opts {
|
|
||||||
if o == nil {
|
|
||||||
o = new(Opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
if o.EnvVars == (daecommon.EnvVars{}) {
|
|
||||||
o.EnvVars = daecommon.GetEnvVars()
|
|
||||||
}
|
|
||||||
|
|
||||||
return o
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ RPC = (*Daemon)(nil)
|
var _ RPC = (*Daemon)(nil)
|
||||||
|
|
||||||
type joinedNetwork struct {
|
type joinedNetwork struct {
|
||||||
@ -65,12 +43,8 @@ type joinedNetwork struct {
|
|||||||
// canceled.
|
// canceled.
|
||||||
type Daemon struct {
|
type Daemon struct {
|
||||||
logger *mlog.Logger
|
logger *mlog.Logger
|
||||||
|
networkLoader network.Loader
|
||||||
daemonConfig daecommon.Config
|
daemonConfig daecommon.Config
|
||||||
envBinDirPath string
|
|
||||||
opts *Opts
|
|
||||||
|
|
||||||
networksStateDir toolkit.Dir
|
|
||||||
networksRuntimeDir toolkit.Dir
|
|
||||||
|
|
||||||
l sync.RWMutex
|
l sync.RWMutex
|
||||||
networks map[string]joinedNetwork
|
networks map[string]joinedNetwork
|
||||||
@ -80,77 +54,37 @@ type Daemon struct {
|
|||||||
func New(
|
func New(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
logger *mlog.Logger,
|
logger *mlog.Logger,
|
||||||
|
networkLoader network.Loader,
|
||||||
daemonConfig daecommon.Config,
|
daemonConfig daecommon.Config,
|
||||||
envBinDirPath string,
|
|
||||||
opts *Opts,
|
|
||||||
) (
|
) (
|
||||||
*Daemon, error,
|
*Daemon, error,
|
||||||
) {
|
) {
|
||||||
opts = opts.withDefaults()
|
|
||||||
|
|
||||||
if err := migrateToMultiNetworkStateDirectory(
|
|
||||||
ctx,
|
|
||||||
logger.WithNamespace("migration-multi-network-state-dir"),
|
|
||||||
opts.EnvVars,
|
|
||||||
); err != nil {
|
|
||||||
return nil, fmt.Errorf(
|
|
||||||
"migrating to multi-network state directory: %w", err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
d := &Daemon{
|
d := &Daemon{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
networkLoader: networkLoader,
|
||||||
daemonConfig: daemonConfig,
|
daemonConfig: daemonConfig,
|
||||||
envBinDirPath: envBinDirPath,
|
|
||||||
opts: opts,
|
|
||||||
networks: map[string]joinedNetwork{},
|
networks: map[string]joinedNetwork{},
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
loadableNetworks, err := networkLoader.Loadable(ctx)
|
||||||
h := new(toolkit.MkDirHelper)
|
|
||||||
d.networksStateDir, _ = h.Maybe(
|
|
||||||
d.opts.EnvVars.StateDir.MkChildDir("networks", true),
|
|
||||||
)
|
|
||||||
|
|
||||||
d.networksRuntimeDir, _ = h.Maybe(
|
|
||||||
d.opts.EnvVars.RuntimeDir.MkChildDir("networks", true),
|
|
||||||
)
|
|
||||||
|
|
||||||
if err := h.Err(); err != nil {
|
|
||||||
return nil, fmt.Errorf("creating networks sub-directories: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loadableNetworks, err := loadableNetworks(d.networksStateDir)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("listing loadable networks: %w", err)
|
return nil, fmt.Errorf("listing loadable networks: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, creationParams := range loadableNetworks {
|
for _, creationParams := range loadableNetworks {
|
||||||
id := creationParams.ID
|
|
||||||
ctx = mctx.WithAnnotator(ctx, creationParams)
|
ctx = mctx.WithAnnotator(ctx, creationParams)
|
||||||
|
|
||||||
networkStateDir, networkRuntimeDir, err := networkDirs(
|
var (
|
||||||
d.networksStateDir, d.networksRuntimeDir, id, true,
|
id = creationParams.ID
|
||||||
|
networkConfig, _ = pickNetworkConfig(daemonConfig, creationParams)
|
||||||
)
|
)
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf(
|
|
||||||
"creating sub-directories for network %q: %w", id, err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
networkConfig, _ := pickNetworkConfig(daemonConfig, creationParams)
|
network, err := networkLoader.Load(
|
||||||
|
|
||||||
network, err := network.Load(
|
|
||||||
ctx,
|
ctx,
|
||||||
logger.WithNamespace("network"),
|
logger.WithNamespace("network"),
|
||||||
networkConfig,
|
networkConfig,
|
||||||
d.envBinDirPath,
|
creationParams,
|
||||||
networkStateDir,
|
nil,
|
||||||
networkRuntimeDir,
|
|
||||||
&network.Opts{
|
|
||||||
ChildrenOpts: d.opts.ChildrenOpts,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("loading network %q: %w", id, err)
|
return nil, fmt.Errorf("loading network %q: %w", id, err)
|
||||||
@ -187,9 +121,7 @@ func (d *Daemon) CreateNetwork(
|
|||||||
creationParams := bootstrap.NewCreationParams(name, domain)
|
creationParams := bootstrap.NewCreationParams(name, domain)
|
||||||
ctx = mctx.WithAnnotator(ctx, creationParams)
|
ctx = mctx.WithAnnotator(ctx, creationParams)
|
||||||
|
|
||||||
networkConfig, ok := pickNetworkConfig(
|
networkConfig, ok := pickNetworkConfig(d.daemonConfig, creationParams)
|
||||||
d.daemonConfig, creationParams,
|
|
||||||
)
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("couldn't find network config for network being created")
|
return errors.New("couldn't find network config for network being created")
|
||||||
}
|
}
|
||||||
@ -203,31 +135,15 @@ func (d *Daemon) CreateNetwork(
|
|||||||
return ErrAlreadyJoined
|
return ErrAlreadyJoined
|
||||||
}
|
}
|
||||||
|
|
||||||
networkStateDir, networkRuntimeDir, err := networkDirs(
|
|
||||||
d.networksStateDir, d.networksRuntimeDir, creationParams.ID, false,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"creating sub-directories for network %q: %w",
|
|
||||||
creationParams.ID,
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
d.logger.Info(ctx, "Creating network")
|
d.logger.Info(ctx, "Creating network")
|
||||||
n, err := network.Create(
|
n, err := d.networkLoader.Create(
|
||||||
ctx,
|
ctx,
|
||||||
d.logger.WithNamespace("network"),
|
d.logger.WithNamespace("network"),
|
||||||
networkConfig,
|
networkConfig,
|
||||||
d.envBinDirPath,
|
|
||||||
networkStateDir,
|
|
||||||
networkRuntimeDir,
|
|
||||||
creationParams,
|
creationParams,
|
||||||
ipNet,
|
ipNet,
|
||||||
hostName,
|
hostName,
|
||||||
&network.Opts{
|
nil,
|
||||||
ChildrenOpts: d.opts.ChildrenOpts,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("creating network: %w", err)
|
return fmt.Errorf("creating network: %w", err)
|
||||||
@ -267,27 +183,13 @@ func (d *Daemon) JoinNetwork(
|
|||||||
return ErrAlreadyJoined
|
return ErrAlreadyJoined
|
||||||
}
|
}
|
||||||
|
|
||||||
networkStateDir, networkRuntimeDir, err := networkDirs(
|
|
||||||
d.networksStateDir, d.networksRuntimeDir, networkID, false,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"creating sub-directories for network %q: %w", networkID, err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
d.logger.Info(ctx, "Joining network")
|
d.logger.Info(ctx, "Joining network")
|
||||||
n, err := network.Join(
|
n, err := d.networkLoader.Join(
|
||||||
ctx,
|
ctx,
|
||||||
d.logger.WithNamespace("network"),
|
d.logger.WithNamespace("network"),
|
||||||
networkConfig,
|
networkConfig,
|
||||||
newBootstrap,
|
newBootstrap,
|
||||||
d.envBinDirPath,
|
nil,
|
||||||
networkStateDir,
|
|
||||||
networkRuntimeDir,
|
|
||||||
&network.Opts{
|
|
||||||
ChildrenOpts: d.opts.ChildrenOpts,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf(
|
return fmt.Errorf(
|
||||||
@ -313,7 +215,7 @@ func withNetwork[Res any](
|
|||||||
d.l.RLock()
|
d.l.RLock()
|
||||||
defer d.l.RUnlock()
|
defer d.l.RUnlock()
|
||||||
|
|
||||||
network, err := pickNetwork(ctx, d.networks, d.networksStateDir)
|
network, err := pickNetwork(ctx, d.networkLoader, d.networks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var zero Res
|
var zero Res
|
||||||
return zero, err
|
return zero, err
|
||||||
@ -368,7 +270,7 @@ func (d *Daemon) SetConfig(
|
|||||||
// TODO needs to check that public addresses aren't being shared
|
// TODO needs to check that public addresses aren't being shared
|
||||||
// across networks, and whatever else happens in Config.Validate.
|
// across networks, and whatever else happens in Config.Validate.
|
||||||
|
|
||||||
network, err := pickNetwork(ctx, d.networks, d.networksStateDir)
|
network, err := pickNetwork(ctx, d.networkLoader, d.networks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -5,78 +5,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"isle/bootstrap"
|
"isle/bootstrap"
|
||||||
"isle/daemon/network"
|
"isle/daemon/network"
|
||||||
"isle/toolkit"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func networkStateDir(
|
|
||||||
networksStateDir toolkit.Dir, networkID string, mayExist bool,
|
|
||||||
) (
|
|
||||||
toolkit.Dir, error,
|
|
||||||
) {
|
|
||||||
return networksStateDir.MkChildDir(networkID, mayExist)
|
|
||||||
}
|
|
||||||
|
|
||||||
func networkRuntimeDir(
|
|
||||||
networksRuntimeDir toolkit.Dir, networkID string, mayExist bool,
|
|
||||||
) (
|
|
||||||
toolkit.Dir, error,
|
|
||||||
) {
|
|
||||||
return networksRuntimeDir.MkChildDir(networkID, mayExist)
|
|
||||||
}
|
|
||||||
|
|
||||||
func networkDirs(
|
|
||||||
networksStateDir, networksRuntimeDir toolkit.Dir,
|
|
||||||
networkID string,
|
|
||||||
mayExist bool,
|
|
||||||
) (
|
|
||||||
stateDir, runtimeDir toolkit.Dir, err error,
|
|
||||||
) {
|
|
||||||
h := new(toolkit.MkDirHelper)
|
|
||||||
stateDir, _ = h.Maybe(
|
|
||||||
networkStateDir(networksStateDir, networkID, mayExist),
|
|
||||||
)
|
|
||||||
runtimeDir, _ = h.Maybe(
|
|
||||||
networkRuntimeDir(networksRuntimeDir, networkID, mayExist),
|
|
||||||
)
|
|
||||||
err = h.Err()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// loadableNetworks returns the CreationParams for each Network which is able to
|
|
||||||
// be loaded.
|
|
||||||
func loadableNetworks(
|
|
||||||
networksStateDir toolkit.Dir,
|
|
||||||
) (
|
|
||||||
[]bootstrap.CreationParams, error,
|
|
||||||
) {
|
|
||||||
networkStateDirs, err := networksStateDir.ChildDirs()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf(
|
|
||||||
"listing children of %q: %w", networksStateDir.Path, err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
creationParams := make([]bootstrap.CreationParams, 0, len(networkStateDirs))
|
|
||||||
|
|
||||||
for _, networkStateDir := range networkStateDirs {
|
|
||||||
thisCreationParams, err := network.LoadCreationParams(networkStateDir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf(
|
|
||||||
"loading creation params from %q: %w",
|
|
||||||
networkStateDir.Path,
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
creationParams = append(creationParams, thisCreationParams)
|
|
||||||
}
|
|
||||||
|
|
||||||
return creationParams, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func pickNetwork(
|
func pickNetwork(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
|
networkLoader network.Loader,
|
||||||
networks map[string]joinedNetwork,
|
networks map[string]joinedNetwork,
|
||||||
networksStateDir toolkit.Dir,
|
|
||||||
) (
|
) (
|
||||||
joinedNetwork, error,
|
joinedNetwork, error,
|
||||||
) {
|
) {
|
||||||
@ -84,7 +18,7 @@ func pickNetwork(
|
|||||||
return joinedNetwork{}, ErrNoNetwork
|
return joinedNetwork{}, ErrNoNetwork
|
||||||
}
|
}
|
||||||
|
|
||||||
creationParams, err := loadableNetworks(networksStateDir)
|
creationParams, err := networkLoader.Loadable(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return joinedNetwork{}, fmt.Errorf("getting loadable networks: %w", err)
|
return joinedNetwork{}, fmt.Errorf("getting loadable networks: %w", err)
|
||||||
}
|
}
|
||||||
|
305
go/daemon/network/loader.go
Normal file
305
go/daemon/network/loader.go
Normal file
@ -0,0 +1,305 @@
|
|||||||
|
//go:generate mockery --name Loader --inpackage --filename loader_mock.go
|
||||||
|
|
||||||
|
package network
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"isle/bootstrap"
|
||||||
|
"isle/daemon/daecommon"
|
||||||
|
"isle/nebula"
|
||||||
|
"isle/toolkit"
|
||||||
|
|
||||||
|
"dev.mediocregopher.com/mediocre-go-lib.git/mlog"
|
||||||
|
)
|
||||||
|
|
||||||
|
func networkStateDir(
|
||||||
|
networksStateDir toolkit.Dir, networkID string, mayExist bool,
|
||||||
|
) (
|
||||||
|
toolkit.Dir, error,
|
||||||
|
) {
|
||||||
|
return networksStateDir.MkChildDir(networkID, mayExist)
|
||||||
|
}
|
||||||
|
|
||||||
|
func networkRuntimeDir(
|
||||||
|
networksRuntimeDir toolkit.Dir, networkID string, mayExist bool,
|
||||||
|
) (
|
||||||
|
toolkit.Dir, error,
|
||||||
|
) {
|
||||||
|
return networksRuntimeDir.MkChildDir(networkID, mayExist)
|
||||||
|
}
|
||||||
|
|
||||||
|
func networkDirs(
|
||||||
|
networksStateDir, networksRuntimeDir toolkit.Dir,
|
||||||
|
networkID string,
|
||||||
|
mayExist bool,
|
||||||
|
) (
|
||||||
|
stateDir, runtimeDir toolkit.Dir, err error,
|
||||||
|
) {
|
||||||
|
h := new(toolkit.MkDirHelper)
|
||||||
|
stateDir, _ = h.Maybe(
|
||||||
|
networkStateDir(networksStateDir, networkID, mayExist),
|
||||||
|
)
|
||||||
|
runtimeDir, _ = h.Maybe(
|
||||||
|
networkRuntimeDir(networksRuntimeDir, networkID, mayExist),
|
||||||
|
)
|
||||||
|
err = h.Err()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loader is responsible for joining/creating Networks and making them loadable
|
||||||
|
// later.
|
||||||
|
type Loader interface {
|
||||||
|
|
||||||
|
// Loadable returns the CreationParams for all Networks which can be Loaded.
|
||||||
|
Loadable(context.Context) ([]bootstrap.CreationParams, error)
|
||||||
|
|
||||||
|
// Load initializes and returns a Network instance for a network which was
|
||||||
|
// previously joined or created, and which has the given CreationParams.
|
||||||
|
Load(
|
||||||
|
context.Context,
|
||||||
|
*mlog.Logger,
|
||||||
|
daecommon.NetworkConfig,
|
||||||
|
bootstrap.CreationParams,
|
||||||
|
*Opts,
|
||||||
|
) (
|
||||||
|
Network, error,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Join initializes and returns a Network instance for an existing network
|
||||||
|
// which was not previously joined to on this host. Once Join has been
|
||||||
|
// called for a particular network it will error on subsequent calls for
|
||||||
|
// that same network, Load should be used instead.
|
||||||
|
Join(
|
||||||
|
context.Context,
|
||||||
|
*mlog.Logger,
|
||||||
|
daecommon.NetworkConfig,
|
||||||
|
JoiningBootstrap,
|
||||||
|
*Opts,
|
||||||
|
) (
|
||||||
|
Network, error,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Create initializes and returns a Network for a brand new network which
|
||||||
|
// uses the given creation parameters.
|
||||||
|
//
|
||||||
|
// - name: Human-readable name of the network.
|
||||||
|
// - domain: Primary domain name that network services are served under.
|
||||||
|
// - ipNet: An IP subnet, in CIDR form, which will be the overall range of
|
||||||
|
// possible IPs in the network. The first IP in this network range will
|
||||||
|
// become this first host's IP.
|
||||||
|
// - hostName: The name of this first host in the network.
|
||||||
|
//
|
||||||
|
// Errors:
|
||||||
|
// - ErrInvalidConfig - if daemonConfig doesn't have 3 storage allocations
|
||||||
|
// configured.
|
||||||
|
Create(
|
||||||
|
context.Context,
|
||||||
|
*mlog.Logger,
|
||||||
|
daecommon.NetworkConfig,
|
||||||
|
bootstrap.CreationParams,
|
||||||
|
nebula.IPNet,
|
||||||
|
nebula.HostName,
|
||||||
|
*Opts,
|
||||||
|
) (
|
||||||
|
Network, error,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoaderOpts are optional parameters which can be passed in when initializing a
|
||||||
|
// new Loader instance. A nil LoaderOpts is equivalent to a zero value.
|
||||||
|
type LoaderOpts struct {
|
||||||
|
// Defaults to that returned by daecommon.GetEnvVars.
|
||||||
|
EnvVars daecommon.EnvVars
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *LoaderOpts) withDefaults() *LoaderOpts {
|
||||||
|
if o == nil {
|
||||||
|
o = new(LoaderOpts)
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.EnvVars == (daecommon.EnvVars{}) {
|
||||||
|
o.EnvVars = daecommon.GetEnvVars()
|
||||||
|
}
|
||||||
|
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
type loader struct {
|
||||||
|
envBinDirPath string
|
||||||
|
networksStateDir toolkit.Dir
|
||||||
|
networksRuntimeDir toolkit.Dir
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewLoader returns a new Loader which will use the given directories to load
|
||||||
|
// and create Network instances.
|
||||||
|
func NewLoader(
|
||||||
|
ctx context.Context,
|
||||||
|
logger *mlog.Logger,
|
||||||
|
envBinDirPath string,
|
||||||
|
opts *LoaderOpts,
|
||||||
|
) (
|
||||||
|
Loader, error,
|
||||||
|
) {
|
||||||
|
opts = opts.withDefaults()
|
||||||
|
|
||||||
|
if err := migrateToMultiNetworkStateDirectory(
|
||||||
|
ctx,
|
||||||
|
logger.WithNamespace("migration-multi-network-state-dir"),
|
||||||
|
opts.EnvVars.StateDir,
|
||||||
|
); err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"migrating to multi-network state directory: %w", err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
h := new(toolkit.MkDirHelper)
|
||||||
|
networksStateDir, _ := h.Maybe(
|
||||||
|
opts.EnvVars.StateDir.MkChildDir("networks", true),
|
||||||
|
)
|
||||||
|
|
||||||
|
networksRuntimeDir, _ := h.Maybe(
|
||||||
|
opts.EnvVars.RuntimeDir.MkChildDir("networks", true),
|
||||||
|
)
|
||||||
|
|
||||||
|
if err := h.Err(); err != nil {
|
||||||
|
return nil, fmt.Errorf("creating networks sub-directories: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &loader{
|
||||||
|
envBinDirPath,
|
||||||
|
networksStateDir,
|
||||||
|
networksRuntimeDir,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *loader) Loadable(
|
||||||
|
ctx context.Context,
|
||||||
|
) (
|
||||||
|
[]bootstrap.CreationParams, error,
|
||||||
|
) {
|
||||||
|
networkStateDirs, err := l.networksStateDir.ChildDirs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"listing children of %q: %w", l.networksStateDir.Path, err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
creationParams := make([]bootstrap.CreationParams, 0, len(networkStateDirs))
|
||||||
|
|
||||||
|
for _, networkStateDir := range networkStateDirs {
|
||||||
|
thisCreationParams, err := LoadCreationParams(networkStateDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"loading creation params from %q: %w",
|
||||||
|
networkStateDir.Path,
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
creationParams = append(creationParams, thisCreationParams)
|
||||||
|
}
|
||||||
|
|
||||||
|
return creationParams, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *loader) Load(
|
||||||
|
ctx context.Context,
|
||||||
|
logger *mlog.Logger,
|
||||||
|
networkConfig daecommon.NetworkConfig,
|
||||||
|
creationParams bootstrap.CreationParams,
|
||||||
|
opts *Opts,
|
||||||
|
) (
|
||||||
|
Network, error,
|
||||||
|
) {
|
||||||
|
networkID := creationParams.ID
|
||||||
|
|
||||||
|
networkStateDir, networkRuntimeDir, err := networkDirs(
|
||||||
|
l.networksStateDir, l.networksRuntimeDir, networkID, true,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"creating sub-directories for network %q: %w", networkID, err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return load(
|
||||||
|
ctx,
|
||||||
|
logger.WithNamespace("network"),
|
||||||
|
l.envBinDirPath,
|
||||||
|
networkConfig,
|
||||||
|
networkStateDir,
|
||||||
|
networkRuntimeDir,
|
||||||
|
opts,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *loader) Join(
|
||||||
|
ctx context.Context,
|
||||||
|
logger *mlog.Logger,
|
||||||
|
networkConfig daecommon.NetworkConfig,
|
||||||
|
joiningBootstrap JoiningBootstrap,
|
||||||
|
opts *Opts,
|
||||||
|
) (
|
||||||
|
Network, error,
|
||||||
|
) {
|
||||||
|
var (
|
||||||
|
creationParams = joiningBootstrap.Bootstrap.NetworkCreationParams
|
||||||
|
networkID = creationParams.ID
|
||||||
|
)
|
||||||
|
|
||||||
|
networkStateDir, networkRuntimeDir, err := networkDirs(
|
||||||
|
l.networksStateDir, l.networksRuntimeDir, networkID, false,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"creating sub-directories for network %q: %w", networkID, err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return join(
|
||||||
|
ctx,
|
||||||
|
logger.WithNamespace("network"),
|
||||||
|
l.envBinDirPath,
|
||||||
|
networkConfig,
|
||||||
|
joiningBootstrap,
|
||||||
|
networkStateDir,
|
||||||
|
networkRuntimeDir,
|
||||||
|
opts,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *loader) Create(
|
||||||
|
ctx context.Context,
|
||||||
|
logger *mlog.Logger,
|
||||||
|
networkConfig daecommon.NetworkConfig,
|
||||||
|
creationParams bootstrap.CreationParams,
|
||||||
|
ipNet nebula.IPNet,
|
||||||
|
hostName nebula.HostName,
|
||||||
|
opts *Opts,
|
||||||
|
) (
|
||||||
|
Network, error,
|
||||||
|
) {
|
||||||
|
networkID := creationParams.ID
|
||||||
|
|
||||||
|
networkStateDir, networkRuntimeDir, err := networkDirs(
|
||||||
|
l.networksStateDir, l.networksRuntimeDir, networkID, false,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"creating sub-directories for network %q: %w", networkID, err,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return create(
|
||||||
|
ctx,
|
||||||
|
logger.WithNamespace("network"),
|
||||||
|
l.envBinDirPath,
|
||||||
|
networkConfig,
|
||||||
|
networkStateDir,
|
||||||
|
networkRuntimeDir,
|
||||||
|
creationParams,
|
||||||
|
ipNet,
|
||||||
|
hostName,
|
||||||
|
opts,
|
||||||
|
)
|
||||||
|
}
|
155
go/daemon/network/loader_mock.go
Normal file
155
go/daemon/network/loader_mock.go
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
// Code generated by mockery v2.43.1. DO NOT EDIT.
|
||||||
|
|
||||||
|
package network
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "context"
|
||||||
|
bootstrap "isle/bootstrap"
|
||||||
|
|
||||||
|
daecommon "isle/daemon/daecommon"
|
||||||
|
|
||||||
|
mlog "dev.mediocregopher.com/mediocre-go-lib.git/mlog"
|
||||||
|
|
||||||
|
mock "github.com/stretchr/testify/mock"
|
||||||
|
|
||||||
|
nebula "isle/nebula"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MockLoader is an autogenerated mock type for the Loader type
|
||||||
|
type MockLoader struct {
|
||||||
|
mock.Mock
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create provides a mock function with given fields: _a0, _a1, _a2, _a3, _a4, _a5, _a6
|
||||||
|
func (_m *MockLoader) Create(_a0 context.Context, _a1 *mlog.Logger, _a2 daecommon.NetworkConfig, _a3 bootstrap.CreationParams, _a4 nebula.IPNet, _a5 nebula.HostName, _a6 *Opts) (Network, error) {
|
||||||
|
ret := _m.Called(_a0, _a1, _a2, _a3, _a4, _a5, _a6)
|
||||||
|
|
||||||
|
if len(ret) == 0 {
|
||||||
|
panic("no return value specified for Create")
|
||||||
|
}
|
||||||
|
|
||||||
|
var r0 Network
|
||||||
|
var r1 error
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, *mlog.Logger, daecommon.NetworkConfig, bootstrap.CreationParams, nebula.IPNet, nebula.HostName, *Opts) (Network, error)); ok {
|
||||||
|
return rf(_a0, _a1, _a2, _a3, _a4, _a5, _a6)
|
||||||
|
}
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, *mlog.Logger, daecommon.NetworkConfig, bootstrap.CreationParams, nebula.IPNet, nebula.HostName, *Opts) Network); ok {
|
||||||
|
r0 = rf(_a0, _a1, _a2, _a3, _a4, _a5, _a6)
|
||||||
|
} else {
|
||||||
|
if ret.Get(0) != nil {
|
||||||
|
r0 = ret.Get(0).(Network)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rf, ok := ret.Get(1).(func(context.Context, *mlog.Logger, daecommon.NetworkConfig, bootstrap.CreationParams, nebula.IPNet, nebula.HostName, *Opts) error); ok {
|
||||||
|
r1 = rf(_a0, _a1, _a2, _a3, _a4, _a5, _a6)
|
||||||
|
} else {
|
||||||
|
r1 = ret.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Join provides a mock function with given fields: _a0, _a1, _a2, _a3, _a4
|
||||||
|
func (_m *MockLoader) Join(_a0 context.Context, _a1 *mlog.Logger, _a2 daecommon.NetworkConfig, _a3 JoiningBootstrap, _a4 *Opts) (Network, error) {
|
||||||
|
ret := _m.Called(_a0, _a1, _a2, _a3, _a4)
|
||||||
|
|
||||||
|
if len(ret) == 0 {
|
||||||
|
panic("no return value specified for Join")
|
||||||
|
}
|
||||||
|
|
||||||
|
var r0 Network
|
||||||
|
var r1 error
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, *mlog.Logger, daecommon.NetworkConfig, JoiningBootstrap, *Opts) (Network, error)); ok {
|
||||||
|
return rf(_a0, _a1, _a2, _a3, _a4)
|
||||||
|
}
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, *mlog.Logger, daecommon.NetworkConfig, JoiningBootstrap, *Opts) Network); ok {
|
||||||
|
r0 = rf(_a0, _a1, _a2, _a3, _a4)
|
||||||
|
} else {
|
||||||
|
if ret.Get(0) != nil {
|
||||||
|
r0 = ret.Get(0).(Network)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rf, ok := ret.Get(1).(func(context.Context, *mlog.Logger, daecommon.NetworkConfig, JoiningBootstrap, *Opts) error); ok {
|
||||||
|
r1 = rf(_a0, _a1, _a2, _a3, _a4)
|
||||||
|
} else {
|
||||||
|
r1 = ret.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load provides a mock function with given fields: _a0, _a1, _a2, _a3, _a4
|
||||||
|
func (_m *MockLoader) Load(_a0 context.Context, _a1 *mlog.Logger, _a2 daecommon.NetworkConfig, _a3 bootstrap.CreationParams, _a4 *Opts) (Network, error) {
|
||||||
|
ret := _m.Called(_a0, _a1, _a2, _a3, _a4)
|
||||||
|
|
||||||
|
if len(ret) == 0 {
|
||||||
|
panic("no return value specified for Load")
|
||||||
|
}
|
||||||
|
|
||||||
|
var r0 Network
|
||||||
|
var r1 error
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, *mlog.Logger, daecommon.NetworkConfig, bootstrap.CreationParams, *Opts) (Network, error)); ok {
|
||||||
|
return rf(_a0, _a1, _a2, _a3, _a4)
|
||||||
|
}
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context, *mlog.Logger, daecommon.NetworkConfig, bootstrap.CreationParams, *Opts) Network); ok {
|
||||||
|
r0 = rf(_a0, _a1, _a2, _a3, _a4)
|
||||||
|
} else {
|
||||||
|
if ret.Get(0) != nil {
|
||||||
|
r0 = ret.Get(0).(Network)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rf, ok := ret.Get(1).(func(context.Context, *mlog.Logger, daecommon.NetworkConfig, bootstrap.CreationParams, *Opts) error); ok {
|
||||||
|
r1 = rf(_a0, _a1, _a2, _a3, _a4)
|
||||||
|
} else {
|
||||||
|
r1 = ret.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loadable provides a mock function with given fields: _a0
|
||||||
|
func (_m *MockLoader) Loadable(_a0 context.Context) ([]bootstrap.CreationParams, error) {
|
||||||
|
ret := _m.Called(_a0)
|
||||||
|
|
||||||
|
if len(ret) == 0 {
|
||||||
|
panic("no return value specified for Loadable")
|
||||||
|
}
|
||||||
|
|
||||||
|
var r0 []bootstrap.CreationParams
|
||||||
|
var r1 error
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context) ([]bootstrap.CreationParams, error)); ok {
|
||||||
|
return rf(_a0)
|
||||||
|
}
|
||||||
|
if rf, ok := ret.Get(0).(func(context.Context) []bootstrap.CreationParams); ok {
|
||||||
|
r0 = rf(_a0)
|
||||||
|
} else {
|
||||||
|
if ret.Get(0) != nil {
|
||||||
|
r0 = ret.Get(0).([]bootstrap.CreationParams)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if rf, ok := ret.Get(1).(func(context.Context) error); ok {
|
||||||
|
r1 = rf(_a0)
|
||||||
|
} else {
|
||||||
|
r1 = ret.Error(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r0, r1
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMockLoader creates a new instance of MockLoader. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||||
|
// The first argument is typically a *testing.T value.
|
||||||
|
func NewMockLoader(t interface {
|
||||||
|
mock.TestingT
|
||||||
|
Cleanup(func())
|
||||||
|
}) *MockLoader {
|
||||||
|
mock := &MockLoader{}
|
||||||
|
mock.Mock.Test(t)
|
||||||
|
|
||||||
|
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||||
|
|
||||||
|
return mock
|
||||||
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package daemon
|
package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"isle/daemon/daecommon"
|
|
||||||
"isle/jsonutil"
|
"isle/jsonutil"
|
||||||
|
"isle/toolkit"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -16,13 +16,13 @@ import (
|
|||||||
|
|
||||||
// DEPRECATED
|
// DEPRECATED
|
||||||
func migrateToMultiNetworkStateDirectory(
|
func migrateToMultiNetworkStateDirectory(
|
||||||
ctx context.Context, logger *mlog.Logger, envVars daecommon.EnvVars,
|
ctx context.Context,
|
||||||
|
logger *mlog.Logger,
|
||||||
|
stateDir toolkit.Dir,
|
||||||
) error {
|
) error {
|
||||||
var (
|
var (
|
||||||
legacyBootstrapPath = filepath.Join(
|
legacyBootstrapPath = filepath.Join(stateDir.Path, "bootstrap.json")
|
||||||
envVars.StateDir.Path, "bootstrap.json",
|
legacySecretsPath = filepath.Join(stateDir.Path, "secrets")
|
||||||
)
|
|
||||||
legacySecretsPath = filepath.Join(envVars.StateDir.Path, "secrets")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if _, err := os.Stat(legacyBootstrapPath); errors.Is(err, fs.ErrNotExist) {
|
if _, err := os.Stat(legacyBootstrapPath); errors.Is(err, fs.ErrNotExist) {
|
||||||
@ -47,9 +47,7 @@ func migrateToMultiNetworkStateDirectory(
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
networkStateDirPath = filepath.Join(
|
networkStateDirPath = filepath.Join(
|
||||||
envVars.StateDir.Path,
|
stateDir.Path, "networks", bootstrapBody.NetworkCreationParams.ID,
|
||||||
"networks",
|
|
||||||
bootstrapBody.NetworkCreationParams.ID,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
newBootstrapPath = filepath.Join(networkStateDirPath, "bootstrap.json")
|
newBootstrapPath = filepath.Join(networkStateDirPath, "bootstrap.json")
|
@ -153,8 +153,6 @@ type Network interface {
|
|||||||
// Opts are optional parameters which can be passed in when initializing a new
|
// Opts are optional parameters which can be passed in when initializing a new
|
||||||
// Network instance. A nil Opts is equivalent to a zero value.
|
// Network instance. A nil Opts is equivalent to a zero value.
|
||||||
type Opts struct {
|
type Opts struct {
|
||||||
ChildrenOpts *children.Opts
|
|
||||||
|
|
||||||
GarageAdminToken string // Will be randomly generated if left unset.
|
GarageAdminToken string // Will be randomly generated if left unset.
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,6 +216,8 @@ func instatiateNetwork(
|
|||||||
|
|
||||||
// LoadCreationParams returns the CreationParams of a Network which was
|
// LoadCreationParams returns the CreationParams of a Network which was
|
||||||
// Created/Joined with the given state directory.
|
// Created/Joined with the given state directory.
|
||||||
|
//
|
||||||
|
// TODO probably can be private
|
||||||
func LoadCreationParams(
|
func LoadCreationParams(
|
||||||
stateDir toolkit.Dir,
|
stateDir toolkit.Dir,
|
||||||
) (
|
) (
|
||||||
@ -240,13 +240,11 @@ func LoadCreationParams(
|
|||||||
return bs.NetworkCreationParams, nil
|
return bs.NetworkCreationParams, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load initializes and returns a Network instance for a network which was
|
func load(
|
||||||
// previously joined or created, and which has the given ID.
|
|
||||||
func Load(
|
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
logger *mlog.Logger,
|
logger *mlog.Logger,
|
||||||
networkConfig daecommon.NetworkConfig,
|
|
||||||
envBinDirPath string,
|
envBinDirPath string,
|
||||||
|
networkConfig daecommon.NetworkConfig,
|
||||||
stateDir toolkit.Dir,
|
stateDir toolkit.Dir,
|
||||||
runtimeDir toolkit.Dir,
|
runtimeDir toolkit.Dir,
|
||||||
opts *Opts,
|
opts *Opts,
|
||||||
@ -283,16 +281,12 @@ func Load(
|
|||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join initializes and returns a Network instance for an existing network which
|
func join(
|
||||||
// was not previously joined to on this host. Once Join has been called for a
|
|
||||||
// particular network it will error on subsequent calls for that same network,
|
|
||||||
// Load should be used instead.
|
|
||||||
func Join(
|
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
logger *mlog.Logger,
|
logger *mlog.Logger,
|
||||||
|
envBinDirPath string,
|
||||||
networkConfig daecommon.NetworkConfig,
|
networkConfig daecommon.NetworkConfig,
|
||||||
joiningBootstrap JoiningBootstrap,
|
joiningBootstrap JoiningBootstrap,
|
||||||
envBinDirPath string,
|
|
||||||
stateDir toolkit.Dir,
|
stateDir toolkit.Dir,
|
||||||
runtimeDir toolkit.Dir,
|
runtimeDir toolkit.Dir,
|
||||||
opts *Opts,
|
opts *Opts,
|
||||||
@ -326,24 +320,11 @@ func Join(
|
|||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create initializes and returns a Network for a brand new network which uses
|
func create(
|
||||||
// the given creation parameters.
|
|
||||||
//
|
|
||||||
// - name: Human-readable name of the network.
|
|
||||||
// - domain: Primary domain name that network services are served under.
|
|
||||||
// - ipNet: An IP subnet, in CIDR form, which will be the overall range of
|
|
||||||
// possible IPs in the network. The first IP in this network range will
|
|
||||||
// become this first host's IP.
|
|
||||||
// - hostName: The name of this first host in the network.
|
|
||||||
//
|
|
||||||
// Errors:
|
|
||||||
// - ErrInvalidConfig - if daemonConfig doesn't have 3 storage allocations
|
|
||||||
// configured.
|
|
||||||
func Create(
|
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
logger *mlog.Logger,
|
logger *mlog.Logger,
|
||||||
networkConfig daecommon.NetworkConfig,
|
|
||||||
envBinDirPath string,
|
envBinDirPath string,
|
||||||
|
networkConfig daecommon.NetworkConfig,
|
||||||
stateDir toolkit.Dir,
|
stateDir toolkit.Dir,
|
||||||
runtimeDir toolkit.Dir,
|
runtimeDir toolkit.Dir,
|
||||||
creationParams bootstrap.CreationParams,
|
creationParams bootstrap.CreationParams,
|
||||||
@ -488,7 +469,6 @@ func (n *network) initialize(
|
|||||||
n.runtimeDir,
|
n.runtimeDir,
|
||||||
n.opts.GarageAdminToken,
|
n.opts.GarageAdminToken,
|
||||||
n.currBootstrap,
|
n.currBootstrap,
|
||||||
n.opts.ChildrenOpts,
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("creating child processes: %w", err)
|
return fmt.Errorf("creating child processes: %w", err)
|
||||||
|
@ -36,11 +36,11 @@ func TestLoad(t *testing.T) {
|
|||||||
assert.NoError(t, network.Shutdown())
|
assert.NoError(t, network.Shutdown())
|
||||||
|
|
||||||
t.Log("Calling Load")
|
t.Log("Calling Load")
|
||||||
loadedNetwork, err := Load(
|
loadedNetwork, err := load(
|
||||||
h.ctx,
|
h.ctx,
|
||||||
h.logger.WithNamespace("loadedNetwork"),
|
h.logger.WithNamespace("loadedNetwork"),
|
||||||
network.getConfig(t),
|
|
||||||
getEnvBinDirPath(),
|
getEnvBinDirPath(),
|
||||||
|
network.getConfig(t),
|
||||||
network.stateDir,
|
network.stateDir,
|
||||||
h.mkDir(t, "runtime"),
|
h.mkDir(t, "runtime"),
|
||||||
network.opts,
|
network.opts,
|
||||||
|
@ -225,11 +225,11 @@ func (h *integrationHarness) createNetwork(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
network, err := Create(
|
network, err := create(
|
||||||
h.ctx,
|
h.ctx,
|
||||||
logger,
|
logger,
|
||||||
networkConfig,
|
|
||||||
getEnvBinDirPath(),
|
getEnvBinDirPath(),
|
||||||
|
networkConfig,
|
||||||
stateDir,
|
stateDir,
|
||||||
runtimeDir,
|
runtimeDir,
|
||||||
opts.creationParams,
|
opts.creationParams,
|
||||||
@ -305,12 +305,12 @@ func (h *integrationHarness) joinNetwork(
|
|||||||
)
|
)
|
||||||
|
|
||||||
t.Logf("Joining as %q", hostNameStr)
|
t.Logf("Joining as %q", hostNameStr)
|
||||||
joinedNetwork, err := Join(
|
joinedNetwork, err := join(
|
||||||
h.ctx,
|
h.ctx,
|
||||||
logger,
|
logger,
|
||||||
|
getEnvBinDirPath(),
|
||||||
networkConfig,
|
networkConfig,
|
||||||
joiningBootstrap,
|
joiningBootstrap,
|
||||||
getEnvBinDirPath(),
|
|
||||||
stateDir,
|
stateDir,
|
||||||
runtimeDir,
|
runtimeDir,
|
||||||
networkOpts,
|
networkOpts,
|
||||||
|
Loading…
Reference in New Issue
Block a user