Use Children's Reload method as part of SetConfig
This commit is contained in:
parent
7274815cfd
commit
8dab458291
@ -54,11 +54,14 @@ func coalesceNetworkConfigAndBootstrap(
|
||||
)
|
||||
}
|
||||
|
||||
host.Garage.Instances = append(host.Garage.Instances, bootstrap.GarageHostInstance{
|
||||
host.Garage.Instances = append(
|
||||
host.Garage.Instances,
|
||||
bootstrap.GarageHostInstance{
|
||||
ID: id,
|
||||
RPCPort: rpcPort,
|
||||
S3APIPort: alloc.S3APIPort,
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
allocs[i].RPCPort = rpcPort
|
||||
}
|
||||
|
@ -421,6 +421,7 @@ func (n *network) initialize(
|
||||
return fmt.Errorf("combining configuration into bootstrap: %w", err)
|
||||
}
|
||||
|
||||
n.logger.Info(ctx, "Writing updated bootstrap to state dir")
|
||||
err = writeBootstrapToStateDir(n.stateDir.Path, currBootstrap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("writing bootstrap to state dir: %w", err)
|
||||
@ -533,7 +534,6 @@ func (n *network) postInit(ctx context.Context) error {
|
||||
|
||||
func (n *network) reloadHosts(ctx context.Context) error {
|
||||
n.l.RLock()
|
||||
networkConfig := n.networkConfig
|
||||
currBootstrap := n.currBootstrap
|
||||
n.l.RUnlock()
|
||||
|
||||
@ -553,7 +553,13 @@ func (n *network) reloadHosts(ctx context.Context) error {
|
||||
newBootstrap := currBootstrap
|
||||
newBootstrap.Hosts = newHosts
|
||||
|
||||
err = n.reload(ctx, networkConfig, newBootstrap)
|
||||
// the daemon's view of this host's bootstrap info takes precedence over
|
||||
// whatever is in garage. The garage version lacks the private credentials
|
||||
// which must be stored locally.
|
||||
thisHost := currBootstrap.ThisHost()
|
||||
newBootstrap.Hosts[thisHost.Name] = thisHost
|
||||
|
||||
err = n.reload(ctx, nil, &newBootstrap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reloading with new host data: %w", err)
|
||||
}
|
||||
@ -580,34 +586,37 @@ func (n *network) reloadLoop(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// reload will check the existing hosts data from currBootstrap against
|
||||
// a potentially updated set of hosts data, and if there are any differences
|
||||
// will perform whatever changes are necessary.
|
||||
func (n *network) reload(
|
||||
ctx context.Context,
|
||||
newNetworkConfig daecommon.NetworkConfig,
|
||||
newBootstrap bootstrap.Bootstrap,
|
||||
newNetworkConfig *daecommon.NetworkConfig,
|
||||
newBootstrap *bootstrap.Bootstrap,
|
||||
) error {
|
||||
n.l.Lock()
|
||||
defer n.l.Unlock()
|
||||
|
||||
// the daemon's view of this host's bootstrap info takes precedence over
|
||||
// whatever is in garage. The garage version lacks the private credentials
|
||||
// which must be stored locally.
|
||||
thisHost := n.currBootstrap.ThisHost()
|
||||
newBootstrap.Hosts[thisHost.Name] = thisHost
|
||||
if newBootstrap != nil {
|
||||
n.currBootstrap = *newBootstrap
|
||||
}
|
||||
|
||||
if newNetworkConfig != nil {
|
||||
n.networkConfig = *newNetworkConfig
|
||||
}
|
||||
|
||||
var err error
|
||||
if n.currBootstrap, err = coalesceNetworkConfigAndBootstrap(
|
||||
n.networkConfig, n.currBootstrap,
|
||||
); err != nil {
|
||||
return fmt.Errorf("combining configuration into bootstrap: %w", err)
|
||||
}
|
||||
|
||||
n.logger.Info(ctx, "Writing updated bootstrap to state dir")
|
||||
err := writeBootstrapToStateDir(n.stateDir.Path, newBootstrap)
|
||||
err = writeBootstrapToStateDir(n.stateDir.Path, n.currBootstrap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("writing bootstrap to state dir: %w", err)
|
||||
}
|
||||
|
||||
n.networkConfig = newNetworkConfig
|
||||
n.currBootstrap = newBootstrap
|
||||
|
||||
n.logger.Info(ctx, "Reloading child processes")
|
||||
err = n.children.Reload(ctx, newNetworkConfig, newBootstrap)
|
||||
err = n.children.Reload(ctx, n.networkConfig, n.currBootstrap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("reloading child processes: %w", err)
|
||||
}
|
||||
@ -800,7 +809,6 @@ func (n *network) CreateHost(
|
||||
JoiningBootstrap, error,
|
||||
) {
|
||||
n.l.RLock()
|
||||
networkConfig := n.networkConfig
|
||||
currBootstrap := n.currBootstrap
|
||||
n.l.RUnlock()
|
||||
|
||||
@ -865,7 +873,7 @@ func (n *network) CreateHost(
|
||||
newBootstrap.Hosts = joiningBootstrap.Bootstrap.Hosts
|
||||
|
||||
n.logger.Info(ctx, "Reloading local state with new host")
|
||||
err = n.reload(ctx, networkConfig, newBootstrap)
|
||||
err = n.reload(ctx, nil, &newBootstrap)
|
||||
if err != nil {
|
||||
return JoiningBootstrap{}, fmt.Errorf("reloading child processes: %w", err)
|
||||
}
|
||||
@ -913,45 +921,10 @@ func (n *network) GetConfig(context.Context) (daecommon.NetworkConfig, error) {
|
||||
func (n *network) SetConfig(
|
||||
ctx context.Context, config daecommon.NetworkConfig,
|
||||
) error {
|
||||
newBootstrap, err := coalesceNetworkConfigAndBootstrap(
|
||||
config, n.currBootstrap,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("combining configuration into bootstrap: %w", err)
|
||||
if err := n.reload(ctx, &config, nil); err != nil {
|
||||
return fmt.Errorf("reloading config: %w", err)
|
||||
}
|
||||
|
||||
n.l.Lock()
|
||||
defer n.l.Unlock()
|
||||
|
||||
n.logger.Info(ctx, "Shutting down children")
|
||||
n.children.Shutdown()
|
||||
|
||||
err = writeBootstrapToStateDir(n.stateDir.Path, newBootstrap)
|
||||
if err != nil {
|
||||
return fmt.Errorf("writing bootstrap to state dir: %w", err)
|
||||
}
|
||||
|
||||
n.networkConfig = config
|
||||
n.currBootstrap = newBootstrap
|
||||
|
||||
n.logger.Info(ctx, "Creating child processes")
|
||||
n.children, err = children.New(
|
||||
ctx,
|
||||
n.logger.WithNamespace("children"),
|
||||
n.envBinDirPath,
|
||||
n.secretsStore,
|
||||
n.networkConfig,
|
||||
n.runtimeDir,
|
||||
n.opts.GarageAdminToken,
|
||||
n.currBootstrap,
|
||||
n.opts.ChildrenOpts,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("creating child processes: %w", err)
|
||||
}
|
||||
|
||||
n.logger.Info(ctx, "Child processes re-created")
|
||||
|
||||
if err := n.postInit(ctx); err != nil {
|
||||
return fmt.Errorf("performing post-initialization: %w", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user