From cb6be7193bbe628424c72e7d9388b6a499e09d3b Mon Sep 17 00:00:00 2001 From: Alexander Scheel Date: Mon, 24 Apr 2023 08:35:32 -0400 Subject: [PATCH] Fix support on Podman service (#20300) When using the podman service runner (creating a socket equivalent to Docker's), tests fail with a nil pointer exception since the bridge network is named "podman", not "bridge". Allow single networked containers and use whatever name the container runner assigns to it. Signed-off-by: Alexander Scheel --- sdk/helper/docker/testhelpers.go | 8 +++++++- sdk/helper/testcluster/docker/environment.go | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/sdk/helper/docker/testhelpers.go b/sdk/helper/docker/testhelpers.go index 55aa0b525a9c..c5348f00a417 100644 --- a/sdk/helper/docker/testhelpers.go +++ b/sdk/helper/docker/testhelpers.go @@ -435,7 +435,13 @@ func (d *Runner) Start(ctx context.Context, addSuffix, forceLocalAddr bool) (*st var realIP string if d.RunOptions.NetworkID == "" { - realIP = inspect.NetworkSettings.Networks["bridge"].IPAddress + if len(inspect.NetworkSettings.Networks) > 1 { + return nil, fmt.Errorf("Set d.RunOptions.NetworkName instead for container with multiple networks: %v", inspect.NetworkSettings.Networks) + } + for _, network := range inspect.NetworkSettings.Networks { + realIP = network.IPAddress + break + } } else { realIP = inspect.NetworkSettings.Networks[d.RunOptions.NetworkName].IPAddress } diff --git a/sdk/helper/testcluster/docker/environment.go b/sdk/helper/testcluster/docker/environment.go index faf1895e3662..76e15648d0a8 100644 --- a/sdk/helper/testcluster/docker/environment.go +++ b/sdk/helper/testcluster/docker/environment.go @@ -732,7 +732,14 @@ func (n *dockerClusterNode) start(ctx context.Context, caDir string, opts *Docke n.container = svc.Container netName := opts.NetworkName if netName == "" { - netName = "bridge" + if len(svc.Container.NetworkSettings.Networks) > 1 { + return fmt.Errorf("Set d.RunOptions.NetworkName instead for container with multiple networks: %v", svc.Container.NetworkSettings.Networks) + } + for netName = range svc.Container.NetworkSettings.Networks { + // Networks above is a map; we just need to find the first and + // only key of this map (network name). The range handles this + // for us, but we need a loop construction in order to use range. + } } n.RealAPIAddr = "https://" + svc.Container.NetworkSettings.Networks[netName].IPAddress + ":8200" n.cleanupContainer = svc.Cleanup