Skip to content

Commit a847308

Browse files
authored
Merge pull request #9139 from chrischdi/pr-fix-capd-multi-error
🌱 CAPD: fix multi error handling in RunContainer
2 parents 7c6cd42 + ecfbbc8 commit a847308

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

test/infrastructure/container/docker.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/docker/docker/pkg/stdcopy"
3838
"github.com/docker/go-connections/nat"
3939
"github.com/pkg/errors"
40+
kerrors "k8s.io/apimachinery/pkg/util/errors"
4041
"k8s.io/utils/pointer"
4142

4243
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -508,8 +509,8 @@ func (d *dockerRuntime) RunContainer(ctx context.Context, runConfig *RunContaine
508509
err := errors.Wrapf(err, "error starting container %q", runConfig.Name)
509510
// Delete the container and retry later on. This helps getting around the race
510511
// condition where of hitting "port is already allocated" issues.
511-
if innerErr := d.dockerClient.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true, RemoveVolumes: true}); innerErr != nil {
512-
return errors.Wrapf(innerErr, "error removing container after failed start: %s", err)
512+
if reterr := d.dockerClient.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true, RemoveVolumes: true}); reterr != nil {
513+
return kerrors.NewAggregate([]error{err, errors.Wrapf(reterr, "error deleting container")})
513514
}
514515
return err
515516
}

0 commit comments

Comments
 (0)