diff --git a/go/daemon/network/network.go b/go/daemon/network/network.go index 90d0fdb..05b12d1 100644 --- a/go/daemon/network/network.go +++ b/go/daemon/network/network.go @@ -601,29 +601,6 @@ func (n *network) postChildrenInit( return nil } -func (n *network) reloadHosts(ctx context.Context) error { - n.l.RLock() - currBootstrap := n.currBootstrap - n.l.RUnlock() - - n.logger.Info(ctx, "Checking for bootstrap changes") - newHosts, err := getGarageBootstrapHosts( - ctx, n.logger, n.secretsStore, currBootstrap, - ) - if err != nil { - return fmt.Errorf("getting hosts from garage: %w", err) - } - - newBootstrap := currBootstrap - newBootstrap.Hosts = newHosts - - if _, err = n.reload(ctx, nil, &newBootstrap); err != nil { - return fmt.Errorf("reloading with new host data: %w", err) - } - - return nil -} - // returns the bootstrap prior to the reload being applied. func (n *network) reload( ctx context.Context, @@ -673,6 +650,41 @@ func (n *network) reload( return prevBootstrap, nil } +func (n *network) reloadHosts(ctx context.Context) error { + n.l.RLock() + currBootstrap := n.currBootstrap + n.l.RUnlock() + + n.logger.Info(ctx, "Checking for bootstrap changes") + newHosts, err := getGarageBootstrapHosts( + ctx, n.logger, n.secretsStore, currBootstrap, + ) + if err != nil { + return fmt.Errorf("getting hosts from garage: %w", err) + } + + n.l.Lock() + defer n.l.Unlock() + + n.currBootstrap.Hosts = newHosts + + n.logger.Info(ctx, "Writing updated bootstrap to state dir") + err = writeBootstrapToStateDir(n.stateDir.Path, n.currBootstrap) + if err != nil { + return fmt.Errorf("writing bootstrap to state dir: %w", err) + } + + n.logger.Info(ctx, "Reloading child processes") + err = n.children.Reload(ctx, n.networkConfig, n.currBootstrap) + if err != nil { + return fmt.Errorf( + "reloading child processes: %w", err, + ) + } + + return nil +} + func withCurrBootstrap[Res any]( n *network, fn func(bootstrap.Bootstrap) (Res, error), ) (Res, error) {