srl-labs / containerlab

container-based networking labs
https://containerlab.dev
BSD 3-Clause "New" or "Revised" License
1.48k stars 251 forks source link

node network-mode with non-containerlab container reference fails #1946

Closed akaliwod closed 6 months ago

akaliwod commented 6 months ago

Hey,

I am trying to replicate https://www.sobyte.net/post/2022-09/containerlab-kind-cilium-bgp/ and not sure how I should be correctly referencing the container created outside of containerlab (e.g. created by kind)

Here are the docker containers created by kind:

$ docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS          PORTS                       NAMES
e4c4dadd61a0   kindest/node:v1.29.2   "/usr/local/bin/entr…"   8 minutes ago    Up 8 minutes                                clab-bgp-cplane-demo-worker2
6729b50324be   kindest/node:v1.29.2   "/usr/local/bin/entr…"   8 minutes ago    Up 8 minutes                                clab-bgp-cplane-demo-worker
b3e6469905d7   kindest/node:v1.29.2   "/usr/local/bin/entr…"   8 minutes ago    Up 8 minutes    127.0.0.1:37663->6443/tcp   clab-bgp-cplane-demo-control-plane
072ac06e7130   kindest/node:v1.29.2   "/usr/local/bin/entr…"   8 minutes ago    Up 8 minutes                                clab-bgp-cplane-demo-worker3

Containerlab Topology

name: bgp-cplane-demo
topology:
  kinds:
    linux:
      cmd: bash
  nodes:
    server0:
      kind: linux
      image: nicolaka/netshoot:latest
      network-mode: container:clab-bgp-cplane-demo-control-plane

It fails on the container reference

$ sudo clab dep -t ref-topo.yaml
INFO[0000] Containerlab v0.52.0 started
INFO[0000] Parsing & checking topology file: ref-topo.yaml
INFO[0000] Creating lab directory: /home/ubuntu/clab-bgp-cplane-demo
WARN[0000] node clab-bgp-cplane-demo-control-plane refrenced in namespace sharing not found, considering it an external dependency.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x1b11a3d]

goroutine 1 [running]:
github.com/srl-labs/containerlab/clab/dependency_manager.(*DependencyNode).AddDepender(0x0, {0x3070748, 0x6}, 0xc000430bd0, {0x3070748, 0x6})
        github.com/srl-labs/containerlab/clab/dependency_manager/dependency_node.go:133 +0x9d
github.com/srl-labs/containerlab/clab.(*CLab).createNamespaceSharingDependency(0xc0000a3ef0)
        github.com/srl-labs/containerlab/clab/clab.go:445 +0x1ae
github.com/srl-labs/containerlab/clab.(*CLab).CreateNodes(0xc0000a3ef0, {0x36d7d08, 0xc00061b3b0}, 0x2?, 0x2?)
        github.com/srl-labs/containerlab/clab/clab.go:387 +0x112
github.com/srl-labs/containerlab/cmd.deployFn(0x4f8caa0?, {0x306d70f?, 0x2?, 0x2?})
        github.com/srl-labs/containerlab/cmd/deploy.go:219 +0x10a8
github.com/spf13/cobra.(*Command).execute(0x4f8caa0, {0xc000b1a1e0, 0x2, 0x2})
        github.com/spf13/cobra@v1.8.0/command.go:983 +0xaaa
github.com/spf13/cobra.(*Command).ExecuteC(0x4f8a260)
        github.com/spf13/cobra@v1.8.0/command.go:1115 +0x425
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.8.0/command.go:1039
github.com/srl-labs/containerlab/cmd.Execute()
        github.com/srl-labs/containerlab/cmd/root.go:49 +0x25
main.main()
        github.com/srl-labs/containerlab/main.go:10 +0x17
hellt commented 6 months ago

This blog post predates the introduction of the ext-container kind

Try this method instead -- https://containerlab.dev/manual/kinds/ext-container/

(and this might be handy as well https://containerlab.dev/manual/kinds/k8s-kind/)

steiler commented 6 months ago

This is a bug. It was already reported in #1939 an consecutively fixed in #1940. @hellt can maybe comment on a next release, that will contain this fix.

hellt commented 6 months ago

The next release is going to be in a week