Skip to content

Commit

Permalink
Deduplicate client and pool SyncContainerWithNetwork logic (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
cthulhu-rider authored Jul 13, 2023
2 parents 2dcae11 + 21e5041 commit 1e823aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
15 changes: 8 additions & 7 deletions client/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,16 +640,17 @@ func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, announcements [
return nil
}

// SyncContainerWithNetwork requests network configuration using passed client
// and applies it to the container. Container MUST not be nil.
//
// Note: if container does not match network configuration, SyncContainerWithNetwork
// changes it.
// SyncContainerWithNetwork requests network configuration using passed [NetworkInfoExecutor]
// and applies/rewrites it to the container.
//
// Returns any network/parsing config errors.
//
// See also NetworkInfo, container.ApplyNetworkConfig.
func SyncContainerWithNetwork(ctx context.Context, cnr *container.Container, c *Client) error {
// See also [client.Client.NetworkInfo], [container.Container.ApplyNetworkConfig].
func SyncContainerWithNetwork(ctx context.Context, cnr *container.Container, c NetworkInfoExecutor) error {
if cnr == nil {
return errors.New("empty container")
}

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 @@ -2193,25 +2193,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 1e823aa

Please sign in to comment.