Revert "Add SetConfig to Daemon, though it will always error right now"

This reverts commit 2ec28cde61.
This commit is contained in:
Brian Picciano 2024-11-10 22:49:36 +01:00
parent f0cb29b553
commit 72bca72b29
5 changed files with 31 additions and 76 deletions

View File

@ -19,12 +19,6 @@ import (
var _ RPC = (*Daemon)(nil)
type joinedNetwork struct {
network.Network
userConfig bool
}
// Daemon implements all methods of the Daemon interface, plus others used
// to manage this particular implementation.
//
@ -47,7 +41,7 @@ type Daemon struct {
daemonConfig daecommon.Config
l sync.RWMutex
networks map[string]joinedNetwork
networks map[string]network.Network
}
// New initializes and returns a Daemon.
@ -63,7 +57,7 @@ func New(
logger: logger,
networkLoader: networkLoader,
daemonConfig: daemonConfig,
networks: map[string]joinedNetwork{},
networks: map[string]network.Network{},
}
loadableNetworks, err := networkLoader.Loadable(ctx)
@ -79,7 +73,7 @@ func New(
networkConfig, _ = pickNetworkConfig(daemonConfig, creationParams)
)
network, err := networkLoader.Load(
d.networks[id], err = networkLoader.Load(
ctx,
logger.WithNamespace("network"),
networkConfig,
@ -89,11 +83,6 @@ func New(
if err != nil {
return nil, fmt.Errorf("loading network %q: %w", id, err)
}
d.networks[id] = joinedNetwork{
Network: network,
userConfig: true,
}
}
return d, nil
@ -114,9 +103,7 @@ func New(
// - network.ErrInvalidConfig
func (d *Daemon) CreateNetwork(
ctx context.Context,
name, domain string,
ipNet nebula.IPNet,
hostName nebula.HostName,
name, domain string, ipNet nebula.IPNet, hostName nebula.HostName,
) error {
creationParams := bootstrap.NewCreationParams(name, domain)
ctx = mctx.WithAnnotator(ctx, creationParams)
@ -150,11 +137,7 @@ func (d *Daemon) CreateNetwork(
}
d.logger.Info(ctx, "Network created successfully")
d.networks[creationParams.ID] = joinedNetwork{
Network: n,
userConfig: true,
}
d.networks[creationParams.ID] = n
return nil
}
@ -198,10 +181,7 @@ func (d *Daemon) JoinNetwork(
}
d.logger.Info(ctx, "Network joined successfully")
d.networks[networkID] = joinedNetwork{
Network: n,
userConfig: true,
}
d.networks[networkID] = n
return nil
}
@ -253,35 +233,6 @@ func (d *Daemon) GetNetworks(
return res, nil
}
// SetConfig applies a new NetworkConfig to a joined network. It uses the same
// mechanism as the rest of the [network.RPC] methods on the Daemon to choose a
// network.
//
// Besides the errors related to network choosing which are returned by all
// other [network.RPC] methods, this may also return ErrUserManagedNetworkConfig
// if the network's configuration is not managed by the Daemon, but is instead
// provided via the config by the user.
func (d *Daemon) SetConfig(
ctx context.Context, config daecommon.NetworkConfig,
) error {
d.l.RLock()
defer d.l.RUnlock()
// TODO needs to check that public addresses aren't being shared
// across networks, and whatever else happens in Config.Validate.
network, err := pickNetwork(ctx, d.networkLoader, d.networks)
if err != nil {
return err
}
if network.userConfig {
return ErrUserManagedNetworkConfig
}
return network.SetConfig(ctx, config)
}
// GetHost implements the method for the network.RPC interface.
func (d *Daemon) GetHosts(ctx context.Context) ([]bootstrap.Host, error) {
return withNetwork(
@ -408,6 +359,21 @@ func (d *Daemon) GetConfig(
)
}
func (d *Daemon) SetConfig(
ctx context.Context, config daecommon.NetworkConfig,
) error {
_, err := withNetwork(
ctx,
d,
func(ctx context.Context, n network.Network) (struct{}, error) {
// TODO needs to check that public addresses aren't being shared
// across networks, and whatever else happens in Config.Validate.
return struct{}{}, n.SetConfig(ctx, config)
},
)
return err
}
// Shutdown blocks until all resources held or created by the daemon,
// including child processes it has started, have been cleaned up.
//

View File

@ -10,7 +10,6 @@ const (
errCodeAlreadyJoined
errCodeNoMatchingNetworks
errCodeMultipleMatchingNetworks
errCodeUserManagedNetworkConfig
)
var (
@ -34,11 +33,4 @@ var (
errCodeMultipleMatchingNetworks,
"Multiple networks matched the search string",
)
// ErrUserManagedNetworkConfig is returned when attempting to modify a
// network config which is managed by the user.
ErrUserManagedNetworkConfig = jsonrpc2.NewError(
errCodeUserManagedNetworkConfig,
"Network configuration is managed by the user",
)
)

View File

@ -10,17 +10,17 @@ import (
func pickNetwork(
ctx context.Context,
networkLoader network.Loader,
networks map[string]joinedNetwork,
networks map[string]network.Network,
) (
joinedNetwork, error,
network.Network, error,
) {
if len(networks) == 0 {
return joinedNetwork{}, ErrNoNetwork
return nil, ErrNoNetwork
}
creationParams, err := networkLoader.Loadable(ctx)
if err != nil {
return joinedNetwork{}, fmt.Errorf("getting loadable networks: %w", err)
return nil, fmt.Errorf("getting loadable networks: %w", err)
}
var (
@ -35,9 +35,9 @@ func pickNetwork(
}
if len(matchingNetworkIDs) == 0 {
return joinedNetwork{}, ErrNoMatchingNetworks
return nil, ErrNoMatchingNetworks
} else if len(matchingNetworkIDs) > 1 {
return joinedNetwork{}, ErrMultipleMatchingNetworks
return nil, ErrMultipleMatchingNetworks
}
return networks[matchingNetworkIDs[0]], nil
@ -45,7 +45,7 @@ func pickNetwork(
func alreadyJoined(
ctx context.Context,
networks map[string]joinedNetwork,
networks map[string]network.Network,
creationParams bootstrap.CreationParams,
) (
bool, error,

View File

@ -224,9 +224,9 @@ func LoadCreationParams(
bootstrap.CreationParams, error,
) {
var (
// TODO store/load the creation params separately from the rest of
// the bootstrap, since the bootstrap contains potentially the
// entire host list of a network, which could be pretty bulky.
// TODO store/load the creation params separately from the rest of the
// bootstrap, since the bootstrap contains potentially the entire host
// list of a network, which could be pretty bulky.
bootstrapFilePath = bootstrap.StateDirPath(stateDir.Path)
bs bootstrap.Bootstrap
)

View File

@ -3,7 +3,6 @@ package daemon
import (
"context"
"isle/bootstrap"
"isle/daemon/daecommon"
"isle/daemon/jsonrpc2"
"isle/daemon/network"
"isle/nebula"
@ -26,8 +25,6 @@ type RPC interface {
GetNetworks(context.Context) ([]bootstrap.CreationParams, error)
SetConfig(context.Context, daecommon.NetworkConfig) error
// All network.RPC methods are automatically implemented by Daemon using the
// currently joined network. If no network is joined then any call to these
// methods will return ErrNoNetwork.