github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/daemon/cluster/executor/container/attachment.go (about)

     1  package container // import "github.com/docker/docker/daemon/cluster/executor/container"
     2  
     3  import (
     4  	"context"
     5  
     6  	executorpkg "github.com/docker/docker/daemon/cluster/executor"
     7  	"github.com/docker/swarmkit/agent/exec"
     8  	"github.com/docker/swarmkit/api"
     9  )
    10  
    11  // networkAttacherController implements agent.Controller against docker's API.
    12  //
    13  // networkAttacherController manages the lifecycle of network
    14  // attachment of a docker unmanaged container managed as a task from
    15  // agent point of view. It provides network attachment information to
    16  // the unmanaged container for it to attach to the network and run.
    17  type networkAttacherController struct {
    18  	backend executorpkg.Backend
    19  	task    *api.Task
    20  	adapter *containerAdapter
    21  	closed  chan struct{}
    22  }
    23  
    24  func newNetworkAttacherController(b executorpkg.Backend, i executorpkg.ImageBackend, v executorpkg.VolumeBackend, task *api.Task, node *api.NodeDescription, dependencies exec.DependencyGetter) (*networkAttacherController, error) {
    25  	adapter, err := newContainerAdapter(b, i, v, task, node, dependencies)
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	return &networkAttacherController{
    31  		backend: b,
    32  		task:    task,
    33  		adapter: adapter,
    34  		closed:  make(chan struct{}),
    35  	}, nil
    36  }
    37  
    38  func (nc *networkAttacherController) Update(ctx context.Context, t *api.Task) error {
    39  	return nil
    40  }
    41  
    42  func (nc *networkAttacherController) Prepare(ctx context.Context) error {
    43  	// Make sure all the networks that the task needs are created.
    44  	return nc.adapter.createNetworks(ctx)
    45  }
    46  
    47  func (nc *networkAttacherController) Start(ctx context.Context) error {
    48  	return nc.adapter.networkAttach(ctx)
    49  }
    50  
    51  func (nc *networkAttacherController) Wait(pctx context.Context) error {
    52  	ctx, cancel := context.WithCancel(pctx)
    53  	defer cancel()
    54  
    55  	return nc.adapter.waitForDetach(ctx)
    56  }
    57  
    58  func (nc *networkAttacherController) Shutdown(ctx context.Context) error {
    59  	return nil
    60  }
    61  
    62  func (nc *networkAttacherController) Terminate(ctx context.Context) error {
    63  	return nil
    64  }
    65  
    66  func (nc *networkAttacherController) Remove(ctx context.Context) error {
    67  	// Try removing the network referenced in this task in case this
    68  	// task is the last one referencing it
    69  	return nc.adapter.removeNetworks(ctx)
    70  }
    71  
    72  func (nc *networkAttacherController) Close() error {
    73  	return nil
    74  }