From 4e64d2ad115e1d8dd798eaf344d1e751f8b733a5 Mon Sep 17 00:00:00 2001 From: steiler Date: Thu, 10 Jun 2021 14:22:48 +0000 Subject: [PATCH] store mgmt ip in container labels for later usage --- runtime/containerd/containerd.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/runtime/containerd/containerd.go b/runtime/containerd/containerd.go index d1f01446c..d3e6bb4d9 100644 --- a/runtime/containerd/containerd.go +++ b/runtime/containerd/containerd.go @@ -69,7 +69,6 @@ func (c *ContainerdRuntime) SetMgmtNet(n types.MgmtNet) { func (c *ContainerdRuntime) CreateNet(ctx context.Context) error { log.Debug("CreateNet() - Not needed with containerd") - // TODO: need to implement return nil } func (c *ContainerdRuntime) DeleteNet(context.Context) error { @@ -210,7 +209,7 @@ func (c *ContainerdRuntime) CreateContainer(ctx context.Context, node *types.Nod containerd.WithNewSpec(opts...), ) - _, err = c.client.NewContainer( + newContainer, err := c.client.NewContainer( ctx, node.LongName, cOpts..., @@ -265,6 +264,17 @@ func (c *ContainerdRuntime) CreateContainer(ctx context.Context, node *types.Nod } } netInfo[node.LongName] = &types.GenericMgmtIPs{Set: isSet, IPv4addr: ipv4, IPv4pLen: ipv4nm, IPv6addr: ipv6, IPv6pLen: ipv6nm} + + additionalLabels := map[string]string{ + "clab.ipv4.addr": ipv4, + "clab.ipv4.netmask": strconv.Itoa(ipv4nm), + "clab.ipv6.addr": ipv6, + "clab.ipv6.netmask": strconv.Itoa(ipv6nm), + } + _, err = newContainer.SetLabels(ctx, additionalLabels) + if err != nil { + return err + } } return nil }