Skip to content

Commit

Permalink
client: Deduplicate client and pool SyncContainerWithNetwork logic
Browse files Browse the repository at this point in the history
closes #458

Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
  • Loading branch information
smallhive committed Jul 7, 2023
1 parent 2e8790e commit 783122e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
4 changes: 2 additions & 2 deletions client/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, announcements [
return nil
}

// SyncContainerWithNetwork requests network configuration using passed client
// SyncContainerWithNetwork requests network configuration using passed [NetworkInfoExecutor]
// and applies it to the container. Container MUST not be nil.
//
// Note: if container does not match network configuration, SyncContainerWithNetwork
Expand All @@ -713,7 +713,7 @@ func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, announcements [
// Returns any network/parsing config errors.
//
// See also NetworkInfo, container.ApplyNetworkConfig.
func SyncContainerWithNetwork(ctx context.Context, cnr *container.Container, c *Client) error {
func SyncContainerWithNetwork(ctx context.Context, cnr *container.Container, c NetworkInfoExecutor) error {
res, err := c.NetworkInfo(ctx, PrmNetworkInfo{})
if err != nil {
return fmt.Errorf("network info call: %w", err)
Expand Down
5 changes: 5 additions & 0 deletions client/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ var (
rpcAPILocalNodeInfo = rpcapi.LocalNodeInfo
)

// NetworkInfoExecutor describes methods to get network information.
type NetworkInfoExecutor interface {
NetworkInfo(ctx context.Context, prm PrmNetworkInfo) (netmap.NetworkInfo, error)
}

// PrmEndpointInfo groups parameters of EndpointInfo operation.
type PrmEndpointInfo struct {
prmCommonMeta
Expand Down
19 changes: 0 additions & 19 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2226,25 +2226,6 @@ func (p *Pool) Close() {
<-p.closedCh
}

// SyncContainerWithNetwork applies network configuration received via
// the Pool to the container. Changes the container if it does not satisfy
// network configuration.
//
// Pool and container MUST not be nil.
//
// Returns any error that does not allow reading configuration
// from the network.
func SyncContainerWithNetwork(ctx context.Context, cnr *container.Container, p *Pool) error {
ni, err := p.NetworkInfo(ctx, sdkClient.PrmNetworkInfo{})
if err != nil {
return fmt.Errorf("network info: %w", err)
}

cnr.ApplyNetworkConfig(ni)

return nil
}

func (p *Pool) sdkClient() (*sdkClient.Client, error) {
conn, err := p.connection()
if err != nil {
Expand Down

0 comments on commit 783122e

Please sign in to comment.