From a2415388c7670324b85493bdfa803c036fb5315e Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Mon, 7 Aug 2023 19:33:47 +0200 Subject: [PATCH] CAPD: fix multi error handling in RunContainer --- test/infrastructure/container/docker.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/infrastructure/container/docker.go b/test/infrastructure/container/docker.go index 75e4565a53fb..f2de71416eae 100644 --- a/test/infrastructure/container/docker.go +++ b/test/infrastructure/container/docker.go @@ -37,6 +37,7 @@ import ( "github.com/docker/docker/pkg/stdcopy" "github.com/docker/go-connections/nat" "github.com/pkg/errors" + kerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/utils/pointer" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" @@ -508,8 +509,8 @@ func (d *dockerRuntime) RunContainer(ctx context.Context, runConfig *RunContaine 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) + if reterr := d.dockerClient.ContainerRemove(ctx, resp.ID, types.ContainerRemoveOptions{Force: true, RemoveVolumes: true}); reterr != nil { + return kerrors.NewAggregate([]error{err, errors.Wrapf(reterr, "error deleting container")}) } return err }