Compare commits

..

No commits in common. "b4bd2199fb877eeafda03c6e49c47285440a98ef" and "335867644bb6b24130e601b163ff27b15fc7f2a3" have entirely different histories.

5 changed files with 22 additions and 67 deletions

View File

@ -41,12 +41,6 @@ func (o *Opts) withDefaults() *Opts {
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.
//
@ -73,7 +67,7 @@ type Daemon struct {
networksRuntimeDir toolkit.Dir
l sync.RWMutex
networks map[string]joinedNetwork
networks map[string]network.Network
}
// New initializes and returns a Daemon.
@ -103,7 +97,7 @@ func New(
daemonConfig: daemonConfig,
envBinDirPath: envBinDirPath,
opts: opts,
networks: map[string]joinedNetwork{},
networks: map[string]network.Network{},
}
{
@ -141,7 +135,7 @@ func New(
networkConfig, _ := pickNetworkConfig(daemonConfig, creationParams)
network, err := network.Load(
d.networks[id], err = network.Load(
ctx,
logger.WithNamespace("network"),
networkConfig,
@ -155,11 +149,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
@ -180,9 +169,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)
@ -234,11 +221,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
}
@ -296,10 +279,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
}
@ -316,7 +296,7 @@ func withNetwork[Res any](
network, err := pickNetwork(ctx, d.networks, d.networksStateDir)
if err != nil {
var zero Res
return zero, err
return zero, nil
}
return fn(ctx, network)
@ -351,24 +331,6 @@ func (d *Daemon) GetNetworks(
return res, nil
}
func (d *Daemon) SetConfig(
ctx context.Context, config daecommon.NetworkConfig,
) error {
d.l.RLock()
defer d.l.RUnlock()
network, err := pickNetwork(ctx, d.networks, d.networksStateDir)
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(

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

@ -75,18 +75,18 @@ func loadableNetworks(
func pickNetwork(
ctx context.Context,
networks map[string]joinedNetwork,
networks map[string]network.Network,
networksStateDir toolkit.Dir,
) (
joinedNetwork, error,
network.Network, error,
) {
if len(networks) == 0 {
return joinedNetwork{}, ErrNoNetwork
return nil, ErrNoNetwork
}
creationParams, err := loadableNetworks(networksStateDir)
if err != nil {
return joinedNetwork{}, fmt.Errorf("getting loadable networks: %w", err)
return nil, fmt.Errorf("getting loadable networks: %w", err)
}
var (
@ -101,9 +101,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
@ -111,7 +111,7 @@ func pickNetwork(
func alreadyJoined(
ctx context.Context,
networks map[string]joinedNetwork,
networks map[string]network.Network,
creationParams bootstrap.CreationParams,
) (
bool, error,

View File

@ -225,10 +225,14 @@ func TestNetwork_SetConfig(t *testing.T) {
})
networkConfig = secondus.getConfig(t)
prevHost = secondus.getHostsByName(t)[secondus.hostName]
removedRole = allocsToRoles(
prevHost = secondus.getHostsByName(t)[secondus.hostName]
removedAlloc = networkConfig.Storage.Allocations[0]
removedRole = allocsToRoles(
secondus.hostName, prevHost.Garage.Instances,
)[0]
removedGarageInst = daecommon.BootstrapGarageHostForAlloc(
prevHost, removedAlloc,
)
primusGarageAdminClient = primus.garageAdminClient(t)
)
@ -242,7 +246,8 @@ func TestNetwork_SetConfig(t *testing.T) {
assert.True(t, ok)
allocs := newHost.HostConfigured.Garage.Instances
assert.Empty(t, allocs)
assert.Len(t, allocs, 3)
assert.NotContains(t, allocs, removedGarageInst)
t.Log("Checking that garage layout still contains the old allocation")
layout, err := primusGarageAdminClient.GetLayout(h.ctx)

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.
@ -37,7 +34,6 @@ type RPC interface {
// these errors, in addition to those documented on the individual methods:
//
// Errors:
// - ErrNoNetwork
// - ErrNoMatchingNetworks
// - ErrMultipleMatchingNetworks
network.RPC