Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate client and pool SyncContainerWithNetwork logic #464

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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