Add container update method
This adds an update method to the container interface for the client package. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
23
container.go
23
container.go
@@ -45,6 +45,8 @@ type Container interface {
|
||||
SetLabels(context.Context, map[string]string) (map[string]string, error)
|
||||
// Extensions returns the extensions set on the container
|
||||
Extensions() map[string]prototypes.Any
|
||||
// Update a container
|
||||
Update(context.Context, ...UpdateContainerOpts) error
|
||||
}
|
||||
|
||||
func containerFromRecord(client *Client, c containers.Container) *container {
|
||||
@@ -238,6 +240,27 @@ func (c *container) NewTask(ctx context.Context, ioCreate IOCreation, opts ...Ne
|
||||
return t, nil
|
||||
}
|
||||
|
||||
func (c *container) Update(ctx context.Context, opts ...UpdateContainerOpts) error {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
// fetch the current container config before updating it
|
||||
current, err := c.client.ContainerService().Get(ctx, c.ID())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, o := range opts {
|
||||
if err := o(ctx, c.client, ¤t); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
nc, err := c.client.ContainerService().Update(ctx, current)
|
||||
if err != nil {
|
||||
return errdefs.FromGRPC(err)
|
||||
}
|
||||
c.c = nc
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *container) loadTask(ctx context.Context, ioAttach IOAttach) (Task, error) {
|
||||
response, err := c.client.TaskService().Get(ctx, &tasks.GetRequest{
|
||||
ContainerID: c.c.ID,
|
||||
|
||||
Reference in New Issue
Block a user