Skip to content

Commit

Permalink
CAPD: delete container after failed start to work around port allocat…
Browse files Browse the repository at this point in the history
…ion issues
  • Loading branch information
chrischdi authored and k8s-infra-cherrypick-robot committed Aug 7, 2023
1 parent ea27b14 commit 3b240eb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion test/infrastructure/container/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,13 @@ func (d *dockerRuntime) RunContainer(ctx context.Context, runConfig *RunContaine

// Actually start the container
if err := d.dockerClient.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{}); err != nil {
return errors.Wrapf(err, "error starting container %q", runConfig.Name)
err := errors.Wrapf(err, "error starting container %q", runConfig.Name)
// Delete the container and retry later on. This helps getting around the race
// condition where of hitting "port is already allocated" issues.
if innerErr := d.dockerClient.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true, RemoveVolumes: true}); innerErr != nil {
return errors.Wrapf(innerErr, "error removing container after failed start: %s", err)
}
return err
}

if output != nil {
Expand Down

0 comments on commit 3b240eb

Please sign in to comment.