Revert "Add SetConfig to Daemon, though it will always error right now"
This reverts commit 2ec28cde61
.
This commit is contained in:
parent
f0cb29b553
commit
72bca72b29
@ -19,12 +19,6 @@ import (
|
|||||||
|
|
||||||
var _ RPC = (*Daemon)(nil)
|
var _ RPC = (*Daemon)(nil)
|
||||||
|
|
||||||
type joinedNetwork struct {
|
|
||||||
network.Network
|
|
||||||
|
|
||||||
userConfig bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Daemon implements all methods of the Daemon interface, plus others used
|
// Daemon implements all methods of the Daemon interface, plus others used
|
||||||
// to manage this particular implementation.
|
// to manage this particular implementation.
|
||||||
//
|
//
|
||||||
@ -47,7 +41,7 @@ type Daemon struct {
|
|||||||
daemonConfig daecommon.Config
|
daemonConfig daecommon.Config
|
||||||
|
|
||||||
l sync.RWMutex
|
l sync.RWMutex
|
||||||
networks map[string]joinedNetwork
|
networks map[string]network.Network
|
||||||
}
|
}
|
||||||
|
|
||||||
// New initializes and returns a Daemon.
|
// New initializes and returns a Daemon.
|
||||||
@ -63,7 +57,7 @@ func New(
|
|||||||
logger: logger,
|
logger: logger,
|
||||||
networkLoader: networkLoader,
|
networkLoader: networkLoader,
|
||||||
daemonConfig: daemonConfig,
|
daemonConfig: daemonConfig,
|
||||||
networks: map[string]joinedNetwork{},
|
networks: map[string]network.Network{},
|
||||||
}
|
}
|
||||||
|
|
||||||
loadableNetworks, err := networkLoader.Loadable(ctx)
|
loadableNetworks, err := networkLoader.Loadable(ctx)
|
||||||
@ -79,7 +73,7 @@ func New(
|
|||||||
networkConfig, _ = pickNetworkConfig(daemonConfig, creationParams)
|
networkConfig, _ = pickNetworkConfig(daemonConfig, creationParams)
|
||||||
)
|
)
|
||||||
|
|
||||||
network, err := networkLoader.Load(
|
d.networks[id], err = networkLoader.Load(
|
||||||
ctx,
|
ctx,
|
||||||
logger.WithNamespace("network"),
|
logger.WithNamespace("network"),
|
||||||
networkConfig,
|
networkConfig,
|
||||||
@ -89,11 +83,6 @@ func New(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("loading network %q: %w", id, err)
|
return nil, fmt.Errorf("loading network %q: %w", id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.networks[id] = joinedNetwork{
|
|
||||||
Network: network,
|
|
||||||
userConfig: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return d, nil
|
return d, nil
|
||||||
@ -114,9 +103,7 @@ func New(
|
|||||||
// - network.ErrInvalidConfig
|
// - network.ErrInvalidConfig
|
||||||
func (d *Daemon) CreateNetwork(
|
func (d *Daemon) CreateNetwork(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
name, domain string,
|
name, domain string, ipNet nebula.IPNet, hostName nebula.HostName,
|
||||||
ipNet nebula.IPNet,
|
|
||||||
hostName nebula.HostName,
|
|
||||||
) error {
|
) error {
|
||||||
creationParams := bootstrap.NewCreationParams(name, domain)
|
creationParams := bootstrap.NewCreationParams(name, domain)
|
||||||
ctx = mctx.WithAnnotator(ctx, creationParams)
|
ctx = mctx.WithAnnotator(ctx, creationParams)
|
||||||
@ -150,11 +137,7 @@ func (d *Daemon) CreateNetwork(
|
|||||||
}
|
}
|
||||||
|
|
||||||
d.logger.Info(ctx, "Network created successfully")
|
d.logger.Info(ctx, "Network created successfully")
|
||||||
d.networks[creationParams.ID] = joinedNetwork{
|
d.networks[creationParams.ID] = n
|
||||||
Network: n,
|
|
||||||
userConfig: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,10 +181,7 @@ func (d *Daemon) JoinNetwork(
|
|||||||
}
|
}
|
||||||
|
|
||||||
d.logger.Info(ctx, "Network joined successfully")
|
d.logger.Info(ctx, "Network joined successfully")
|
||||||
d.networks[networkID] = joinedNetwork{
|
d.networks[networkID] = n
|
||||||
Network: n,
|
|
||||||
userConfig: true,
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,35 +233,6 @@ func (d *Daemon) GetNetworks(
|
|||||||
return res, nil
|
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.
|
// GetHost implements the method for the network.RPC interface.
|
||||||
func (d *Daemon) GetHosts(ctx context.Context) ([]bootstrap.Host, error) {
|
func (d *Daemon) GetHosts(ctx context.Context) ([]bootstrap.Host, error) {
|
||||||
return withNetwork(
|
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,
|
// Shutdown blocks until all resources held or created by the daemon,
|
||||||
// including child processes it has started, have been cleaned up.
|
// including child processes it has started, have been cleaned up.
|
||||||
//
|
//
|
||||||
|
@ -10,7 +10,6 @@ const (
|
|||||||
errCodeAlreadyJoined
|
errCodeAlreadyJoined
|
||||||
errCodeNoMatchingNetworks
|
errCodeNoMatchingNetworks
|
||||||
errCodeMultipleMatchingNetworks
|
errCodeMultipleMatchingNetworks
|
||||||
errCodeUserManagedNetworkConfig
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -34,11 +33,4 @@ var (
|
|||||||
errCodeMultipleMatchingNetworks,
|
errCodeMultipleMatchingNetworks,
|
||||||
"Multiple networks matched the search string",
|
"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",
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
@ -10,17 +10,17 @@ import (
|
|||||||
func pickNetwork(
|
func pickNetwork(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
networkLoader network.Loader,
|
networkLoader network.Loader,
|
||||||
networks map[string]joinedNetwork,
|
networks map[string]network.Network,
|
||||||
) (
|
) (
|
||||||
joinedNetwork, error,
|
network.Network, error,
|
||||||
) {
|
) {
|
||||||
if len(networks) == 0 {
|
if len(networks) == 0 {
|
||||||
return joinedNetwork{}, ErrNoNetwork
|
return nil, ErrNoNetwork
|
||||||
}
|
}
|
||||||
|
|
||||||
creationParams, err := networkLoader.Loadable(ctx)
|
creationParams, err := networkLoader.Loadable(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return joinedNetwork{}, fmt.Errorf("getting loadable networks: %w", err)
|
return nil, fmt.Errorf("getting loadable networks: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -35,9 +35,9 @@ func pickNetwork(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(matchingNetworkIDs) == 0 {
|
if len(matchingNetworkIDs) == 0 {
|
||||||
return joinedNetwork{}, ErrNoMatchingNetworks
|
return nil, ErrNoMatchingNetworks
|
||||||
} else if len(matchingNetworkIDs) > 1 {
|
} else if len(matchingNetworkIDs) > 1 {
|
||||||
return joinedNetwork{}, ErrMultipleMatchingNetworks
|
return nil, ErrMultipleMatchingNetworks
|
||||||
}
|
}
|
||||||
|
|
||||||
return networks[matchingNetworkIDs[0]], nil
|
return networks[matchingNetworkIDs[0]], nil
|
||||||
@ -45,7 +45,7 @@ func pickNetwork(
|
|||||||
|
|
||||||
func alreadyJoined(
|
func alreadyJoined(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
networks map[string]joinedNetwork,
|
networks map[string]network.Network,
|
||||||
creationParams bootstrap.CreationParams,
|
creationParams bootstrap.CreationParams,
|
||||||
) (
|
) (
|
||||||
bool, error,
|
bool, error,
|
||||||
|
@ -224,9 +224,9 @@ func LoadCreationParams(
|
|||||||
bootstrap.CreationParams, error,
|
bootstrap.CreationParams, error,
|
||||||
) {
|
) {
|
||||||
var (
|
var (
|
||||||
// TODO store/load the creation params separately from the rest of
|
// TODO store/load the creation params separately from the rest of the
|
||||||
// the bootstrap, since the bootstrap contains potentially the
|
// bootstrap, since the bootstrap contains potentially the entire host
|
||||||
// entire host list of a network, which could be pretty bulky.
|
// list of a network, which could be pretty bulky.
|
||||||
bootstrapFilePath = bootstrap.StateDirPath(stateDir.Path)
|
bootstrapFilePath = bootstrap.StateDirPath(stateDir.Path)
|
||||||
bs bootstrap.Bootstrap
|
bs bootstrap.Bootstrap
|
||||||
)
|
)
|
||||||
|
@ -3,7 +3,6 @@ package daemon
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"isle/bootstrap"
|
"isle/bootstrap"
|
||||||
"isle/daemon/daecommon"
|
|
||||||
"isle/daemon/jsonrpc2"
|
"isle/daemon/jsonrpc2"
|
||||||
"isle/daemon/network"
|
"isle/daemon/network"
|
||||||
"isle/nebula"
|
"isle/nebula"
|
||||||
@ -26,8 +25,6 @@ type RPC interface {
|
|||||||
|
|
||||||
GetNetworks(context.Context) ([]bootstrap.CreationParams, error)
|
GetNetworks(context.Context) ([]bootstrap.CreationParams, error)
|
||||||
|
|
||||||
SetConfig(context.Context, daecommon.NetworkConfig) error
|
|
||||||
|
|
||||||
// All network.RPC methods are automatically implemented by Daemon using the
|
// All network.RPC methods are automatically implemented by Daemon using the
|
||||||
// currently joined network. If no network is joined then any call to these
|
// currently joined network. If no network is joined then any call to these
|
||||||
// methods will return ErrNoNetwork.
|
// methods will return ErrNoNetwork.
|
||||||
|
Loading…
Reference in New Issue
Block a user