Pass bootstrap into newNetwork, will simplify future changes
This commit is contained in:
parent
4bce0e3fa0
commit
9848394ffc
@ -210,6 +210,7 @@ func newNetwork(
|
|||||||
stateDir toolkit.Dir,
|
stateDir toolkit.Dir,
|
||||||
runtimeDir toolkit.Dir,
|
runtimeDir toolkit.Dir,
|
||||||
dirsMayExist bool,
|
dirsMayExist bool,
|
||||||
|
currBootstrap bootstrap.Bootstrap,
|
||||||
opts *Opts,
|
opts *Opts,
|
||||||
) (
|
) (
|
||||||
*network, error,
|
*network, error,
|
||||||
@ -224,6 +225,7 @@ func newNetwork(
|
|||||||
stateDir: stateDir,
|
stateDir: stateDir,
|
||||||
runtimeDir: runtimeDir,
|
runtimeDir: runtimeDir,
|
||||||
opts: opts.withDefaults(),
|
opts: opts.withDefaults(),
|
||||||
|
currBootstrap: currBootstrap,
|
||||||
workerCtx: ctx,
|
workerCtx: ctx,
|
||||||
workerCancel: cancel,
|
workerCancel: cancel,
|
||||||
}
|
}
|
||||||
@ -277,6 +279,11 @@ func (constructorsImpl) load(
|
|||||||
) (
|
) (
|
||||||
Network, error,
|
Network, error,
|
||||||
) {
|
) {
|
||||||
|
currBootstrap, err := loadBootstrapFromStateDir(stateDir.Path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("loading bootstrap from state dir: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
n, err := newNetwork(
|
n, err := newNetwork(
|
||||||
ctx,
|
ctx,
|
||||||
logger,
|
logger,
|
||||||
@ -285,18 +292,14 @@ func (constructorsImpl) load(
|
|||||||
stateDir,
|
stateDir,
|
||||||
runtimeDir,
|
runtimeDir,
|
||||||
true,
|
true,
|
||||||
|
currBootstrap,
|
||||||
opts,
|
opts,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("instantiating Network: %w", err)
|
return nil, fmt.Errorf("instantiating Network: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
currBootstrap, err := loadBootstrapFromStateDir(n.stateDir.Path)
|
if err := n.initialize(ctx, false); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("loading bootstrap from state dir: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := n.initialize(ctx, currBootstrap, false); err != nil {
|
|
||||||
return nil, fmt.Errorf("initializing with bootstrap: %w", err)
|
return nil, fmt.Errorf("initializing with bootstrap: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,6 +326,7 @@ func (constructorsImpl) join(
|
|||||||
stateDir,
|
stateDir,
|
||||||
runtimeDir,
|
runtimeDir,
|
||||||
false,
|
false,
|
||||||
|
joiningBootstrap.Bootstrap,
|
||||||
opts,
|
opts,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -335,7 +339,7 @@ func (constructorsImpl) join(
|
|||||||
return nil, fmt.Errorf("importing secrets: %w", err)
|
return nil, fmt.Errorf("importing secrets: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := n.initialize(ctx, joiningBootstrap.Bootstrap, false); err != nil {
|
if err := n.initialize(ctx, false); err != nil {
|
||||||
return nil, fmt.Errorf("initializing with bootstrap: %w", err)
|
return nil, fmt.Errorf("initializing with bootstrap: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,6 +367,17 @@ func (constructorsImpl) create(
|
|||||||
|
|
||||||
garageRPCSecret := toolkit.RandStr(32)
|
garageRPCSecret := toolkit.RandStr(32)
|
||||||
|
|
||||||
|
hostBootstrap, err := bootstrap.New(
|
||||||
|
nebulaCACreds,
|
||||||
|
creationParams,
|
||||||
|
map[nebula.HostName]bootstrap.Host{},
|
||||||
|
hostName,
|
||||||
|
ipNet.FirstAddr(),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("initializing bootstrap data: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
n, err := newNetwork(
|
n, err := newNetwork(
|
||||||
ctx,
|
ctx,
|
||||||
logger,
|
logger,
|
||||||
@ -371,6 +386,7 @@ func (constructorsImpl) create(
|
|||||||
stateDir,
|
stateDir,
|
||||||
runtimeDir,
|
runtimeDir,
|
||||||
false,
|
false,
|
||||||
|
hostBootstrap,
|
||||||
opts,
|
opts,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -395,18 +411,7 @@ func (constructorsImpl) create(
|
|||||||
return nil, fmt.Errorf("setting nebula CA signing key secret: %w", err)
|
return nil, fmt.Errorf("setting nebula CA signing key secret: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
hostBootstrap, err := bootstrap.New(
|
if err := n.initialize(ctx, true); err != nil {
|
||||||
nebulaCACreds,
|
|
||||||
creationParams,
|
|
||||||
map[nebula.HostName]bootstrap.Host{},
|
|
||||||
hostName,
|
|
||||||
ipNet.FirstAddr(),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("initializing bootstrap data: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := n.initialize(ctx, hostBootstrap, true); err != nil {
|
|
||||||
return nil, fmt.Errorf("initializing with bootstrap: %w", err)
|
return nil, fmt.Errorf("initializing with bootstrap: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,10 +452,12 @@ func (n *network) periodically(
|
|||||||
|
|
||||||
func (n *network) initialize(
|
func (n *network) initialize(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
prevBootstrap bootstrap.Bootstrap,
|
|
||||||
isCreate bool,
|
isCreate bool,
|
||||||
) error {
|
) error {
|
||||||
prevThisHost := prevBootstrap.ThisHost()
|
var (
|
||||||
|
prevBootstrap = n.currBootstrap
|
||||||
|
prevThisHost = prevBootstrap.ThisHost()
|
||||||
|
)
|
||||||
|
|
||||||
// we update this Host's data using whatever configuration has been provided
|
// we update this Host's data using whatever configuration has been provided
|
||||||
// by the daemon config. This way the network has the most up-to-date
|
// by the daemon config. This way the network has the most up-to-date
|
||||||
|
Loading…
Reference in New Issue
Block a user