From 9848394ffcfcc6bee7903a966847f59973f699e3 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sun, 5 Jan 2025 12:25:02 +0100 Subject: [PATCH] Pass bootstrap into newNetwork, will simplify future changes --- go/daemon/network/network.go | 49 ++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/go/daemon/network/network.go b/go/daemon/network/network.go index 031204b..90d0fdb 100644 --- a/go/daemon/network/network.go +++ b/go/daemon/network/network.go @@ -210,6 +210,7 @@ func newNetwork( stateDir toolkit.Dir, runtimeDir toolkit.Dir, dirsMayExist bool, + currBootstrap bootstrap.Bootstrap, opts *Opts, ) ( *network, error, @@ -224,6 +225,7 @@ func newNetwork( stateDir: stateDir, runtimeDir: runtimeDir, opts: opts.withDefaults(), + currBootstrap: currBootstrap, workerCtx: ctx, workerCancel: cancel, } @@ -277,6 +279,11 @@ func (constructorsImpl) load( ) ( Network, error, ) { + currBootstrap, err := loadBootstrapFromStateDir(stateDir.Path) + if err != nil { + return nil, fmt.Errorf("loading bootstrap from state dir: %w", err) + } + n, err := newNetwork( ctx, logger, @@ -285,18 +292,14 @@ func (constructorsImpl) load( stateDir, runtimeDir, true, + currBootstrap, opts, ) if err != nil { return nil, fmt.Errorf("instantiating Network: %w", err) } - currBootstrap, err := loadBootstrapFromStateDir(n.stateDir.Path) - if err != nil { - return nil, fmt.Errorf("loading bootstrap from state dir: %w", err) - } - - if err := n.initialize(ctx, currBootstrap, false); err != nil { + if err := n.initialize(ctx, false); err != nil { return nil, fmt.Errorf("initializing with bootstrap: %w", err) } @@ -323,6 +326,7 @@ func (constructorsImpl) join( stateDir, runtimeDir, false, + joiningBootstrap.Bootstrap, opts, ) if err != nil { @@ -335,7 +339,7 @@ func (constructorsImpl) join( 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) } @@ -363,6 +367,17 @@ func (constructorsImpl) create( 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( ctx, logger, @@ -371,6 +386,7 @@ func (constructorsImpl) create( stateDir, runtimeDir, false, + hostBootstrap, opts, ) if err != nil { @@ -395,18 +411,7 @@ func (constructorsImpl) create( return nil, fmt.Errorf("setting nebula CA signing key secret: %w", err) } - 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) - } - - if err := n.initialize(ctx, hostBootstrap, true); err != nil { + if err := n.initialize(ctx, true); err != nil { return nil, fmt.Errorf("initializing with bootstrap: %w", err) } @@ -447,10 +452,12 @@ func (n *network) periodically( func (n *network) initialize( ctx context.Context, - prevBootstrap bootstrap.Bootstrap, isCreate bool, ) error { - prevThisHost := prevBootstrap.ThisHost() + var ( + prevBootstrap = n.currBootstrap + prevThisHost = prevBootstrap.ThisHost() + ) // 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