clusterCreate/network: only use the exact chosen network

Before, we just looked up the name of the docker network, causing docker
to do some sort of relaxed matching (prefix?) which could cause k3d to
choose the first matching network instead of the exact match.
Now we're enforcing exact Regex matching to prevent this.
Fixes #374
pull/378/head
iwilltry42 4 years ago
parent eb35667705
commit ca23c6d898
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 7
      pkg/runtimes/docker/network.go

@ -23,6 +23,7 @@ package docker
import (
"context"
"fmt"
"net"
"github.com/docker/docker/api/types"
@ -46,12 +47,12 @@ func (d Docker) CreateNetworkIfNotPresent(ctx context.Context, name string) (str
defer docker.Close()
// (1) configure list filters
args := filters.NewArgs()
args.Add("name", name)
filter := filters.NewArgs()
filter.Add("name", fmt.Sprintf("^/?%s$", name)) // regex filtering for exact name match
// (2) get filtered list of networks
networkList, err := docker.NetworkList(ctx, types.NetworkListOptions{
Filters: args,
Filters: filter,
})
if err != nil {
log.Errorln("Failed to list docker networks")

Loading…
Cancel
Save