Skip to content
Open
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
6 changes: 5 additions & 1 deletion containers/docker/container_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ func (m *Manager) ContainerRestart(ctx context.Context, instance string, _ ...op
return status.Errorf(codes.Aborted, "expected container state to be %q, got %q",
container.StateExited, j.State.Status)
}
return m.restartContainer(ctx, j, true)
if err := m.client.ContainerStart(ctx, instance, container.StartOptions{}); err != nil {
return status.Errorf(codes.Internal,
"failed when starting container: %v", err)
}
return nil
}

// ContainerStart starts a container provided the image exists and that the ports requested are not
Expand Down
40 changes: 5 additions & 35 deletions containers/docker/container_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,46 +76,16 @@ func (m *Manager) performContainerUpdate(ctx context.Context, instance, image, t
// There was some error, let's try to restore previous state.
errPfx := fmt.Sprintf("failed to update instance %s due to: %v", instance, err)

if recreateErr := m.restartContainer(ctx, oldCntJSON,
false); recreateErr != nil {
s, ok := status.FromError(recreateErr)
if !ok {
return "", fmt.Errorf(
"programming error: restartContainer"+
" should return status error code, got %s: %s",
errPfx, recreateErr)
}
return "", status.Errorf(s.Code(), "%s; restoration of previous state %s", errPfx, recreateErr)
}

return instance, status.Errorf(codes.Internal, "%s; yet, restoration of previous state succeeded", errPfx)
}

// restartContainer recreates a container given a particular config.
// it is expected that the container in question has been stopped by the point this is called.
func (m *Manager) restartContainer(ctx context.Context, oldCntJSON types.ContainerJSON,
needsRemoval bool) error {
instanceName := strings.Replace(oldCntJSON.Name, "/", "", 1)
if needsRemoval {
if err := m.client.ContainerRemove(ctx, instanceName,
container.RemoveOptions{}); err != nil {
return status.Errorf(codes.Internal,
"failed when removing container: %v", err)
}
}
resp, err := m.client.ContainerCreate(ctx,
oldCntJSON.Config, oldCntJSON.HostConfig, &network.NetworkingConfig{},
nil, instanceName)
resp, err := m.client.ContainerCreate(ctx, oldCntJSON.Config, oldCntJSON.HostConfig, &network.NetworkingConfig{}, nil, instance)
if err != nil {
return status.Errorf(codes.Internal,
"failed when creating container: %v", err)
return "", status.Errorf(codes.Internal, "%s; restoration of previous state failed when creating container: %v", errPfx, err)
}

if err := m.client.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil {
return status.Errorf(codes.Internal,
"failed when starting container: %v", err)
return "", status.Errorf(codes.Internal, "%s; restoration of previous state failed when starting container: %v", errPfx, err)
}
return nil

return instance, status.Errorf(codes.Internal, "%s; yet, restoration of previous state succeeded", errPfx)
}

func (m *Manager) performContainerUpdatePrechecks(ctx context.Context, instance, imageName, tag, cmd string, async bool, opts ...options.Option) ([]types.Container, error) {
Expand Down
Loading