diff --git a/pkg/runtimes/docker/network.go b/pkg/runtimes/docker/network.go index e1d6b074..1157ec8e 100644 --- a/pkg/runtimes/docker/network.go +++ b/pkg/runtimes/docker/network.go @@ -131,6 +131,12 @@ func GetGatewayIP(ctx context.Context, network string) (net.IP, error) { // ConnectNodeToNetwork connects a node to a network func (d Docker) ConnectNodeToNetwork(ctx context.Context, node *k3d.Node, networkName string) error { + // check that node was not attached to network before + if isAttachedToNetwork(node, networkName) { + log.Infof("Container '%s' is already connected to '%s'", node.Name,networkName) + return nil + } + // get container container, err := getNodeContainer(ctx, node) if err != nil { diff --git a/pkg/runtimes/docker/util.go b/pkg/runtimes/docker/util.go index 7bc17e8f..05ff5f09 100644 --- a/pkg/runtimes/docker/util.go +++ b/pkg/runtimes/docker/util.go @@ -140,6 +140,7 @@ func (d Docker) WriteToNode(ctx context.Context, content []byte, dest string, no return nil } + // GetDockerClient returns a docker client func GetDockerClient() (*client.Client, error) { var err error @@ -168,3 +169,13 @@ func GetDockerClient() (*client.Client, error) { return cli, err } + +// isAttachedToNetwork return true if node is attached to network +func isAttachedToNetwork(node *k3d.Node, network string) bool { + for _, nw := range node.Networks { + if nw == network { + return true + } + } + return false +}