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) 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.
// //
@ -73,7 +67,7 @@ type Daemon struct {
networksRuntimeDir toolkit.Dir networksRuntimeDir toolkit.Dir
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.
@ -103,7 +97,7 @@ func New(
daemonConfig: daemonConfig, daemonConfig: daemonConfig,
envBinDirPath: envBinDirPath, envBinDirPath: envBinDirPath,
opts: opts, opts: opts,
networks: map[string]joinedNetwork{}, networks: map[string]network.Network{},
} }
{ {
@ -141,7 +135,7 @@ func New(
networkConfig, _ := pickNetworkConfig(daemonConfig, creationParams) networkConfig, _ := pickNetworkConfig(daemonConfig, creationParams)
network, err := network.Load( d.networks[id], err = network.Load(
ctx, ctx,
logger.WithNamespace("network"), logger.WithNamespace("network"),
networkConfig, networkConfig,
@ -155,11 +149,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
@ -180,9 +169,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)
@ -234,11 +221,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
} }
@ -296,10 +279,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
} }
@ -316,7 +296,7 @@ func withNetwork[Res any](
network, err := pickNetwork(ctx, d.networks, d.networksStateDir) network, err := pickNetwork(ctx, d.networks, d.networksStateDir)
if err != nil { if err != nil {
var zero Res var zero Res
return zero, err return zero, nil
} }
return fn(ctx, network) return fn(ctx, network)
@ -351,24 +331,6 @@ func (d *Daemon) GetNetworks(
return res, nil 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. // 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(

View File

@ -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",
)
) )

View File

@ -75,18 +75,18 @@ func loadableNetworks(
func pickNetwork( func pickNetwork(
ctx context.Context, ctx context.Context,
networks map[string]joinedNetwork, networks map[string]network.Network,
networksStateDir toolkit.Dir, networksStateDir toolkit.Dir,
) ( ) (
joinedNetwork, error, network.Network, error,
) { ) {
if len(networks) == 0 { if len(networks) == 0 {
return joinedNetwork{}, ErrNoNetwork return nil, ErrNoNetwork
} }
creationParams, err := loadableNetworks(networksStateDir) creationParams, err := loadableNetworks(networksStateDir)
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 (
@ -101,9 +101,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
@ -111,7 +111,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,

View File

@ -226,9 +226,13 @@ func TestNetwork_SetConfig(t *testing.T) {
networkConfig = secondus.getConfig(t) networkConfig = secondus.getConfig(t)
prevHost = secondus.getHostsByName(t)[secondus.hostName] prevHost = secondus.getHostsByName(t)[secondus.hostName]
removedAlloc = networkConfig.Storage.Allocations[0]
removedRole = allocsToRoles( removedRole = allocsToRoles(
secondus.hostName, prevHost.Garage.Instances, secondus.hostName, prevHost.Garage.Instances,
)[0] )[0]
removedGarageInst = daecommon.BootstrapGarageHostForAlloc(
prevHost, removedAlloc,
)
primusGarageAdminClient = primus.garageAdminClient(t) primusGarageAdminClient = primus.garageAdminClient(t)
) )
@ -242,7 +246,8 @@ func TestNetwork_SetConfig(t *testing.T) {
assert.True(t, ok) assert.True(t, ok)
allocs := newHost.HostConfigured.Garage.Instances 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") t.Log("Checking that garage layout still contains the old allocation")
layout, err := primusGarageAdminClient.GetLayout(h.ctx) layout, err := primusGarageAdminClient.GetLayout(h.ctx)

View File

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