Skip to content

Commit

Permalink
fix mgmt bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
steiler committed Aug 4, 2023
1 parent 573fad3 commit fceb46e
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 102 deletions.
76 changes: 35 additions & 41 deletions clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,47 +496,6 @@ func (c *CLab) WaitForExternalNodeDependencies(ctx context.Context, nodeName str
runtime.WaitForContainerRunning(ctx, c.Runtimes[c.globalRuntime], contName, nodeName)
}

// // CreateLinks creates links using the specified number of workers.
// func (c *CLab) CreateLinks(ctx context.Context, workers uint, dm dependency_manager.DependencyManager) {
// wg := new(sync.WaitGroup)
// sem := semaphore.NewWeighted(int64(workers))

// for _, link := range c.Links {
// wg.Add(1)
// go func(li *types.Link) {
// defer wg.Done()

// var waitNodes []string
// for _, n := range []*types.NodeConfig{li.A.Node, li.B.Node} {
// // we should not wait for "host" fake node or mgmt-net node
// if n.Kind != "host" && n.ShortName != "mgmt-net" {
// waitNodes = append(waitNodes, n.ShortName)
// }
// }

// err := dm.WaitForNodes(waitNodes, dependency_manager.NodeStateCreated)
// if err != nil {
// log.Error(err)
// }

// // acquire Sem
// err = sem.Acquire(ctx, 1)
// if err != nil {
// log.Error(err)
// }
// defer sem.Release(1)
// // create the wiring
// err = c.CreateVirtualWiring(li)
// if err != nil {
// log.Error(err)
// }
// }(link)
// }

// // wait for all workers to finish
// wg.Wait()
// }

func (c *CLab) DeleteNodes(ctx context.Context, workers uint, serialNodes map[string]struct{}) {
wg := new(sync.WaitGroup)

Expand Down Expand Up @@ -647,3 +606,38 @@ func (c *CLab) VethCleanup(ctx context.Context) error {
}
return nil
}

func (c *CLab) ResolveLinks() error {
// create a types.LinkNode from the nodes.Node
// altough the nodes.Node interface is a Superset of the types.LinkNode
// we need to convert the map, since the whole map seems to not be dynamically typeconvertable
resolveNodes := make(map[string]types.LinkNode, len(c.Nodes))
for k, v := range c.Nodes {
resolveNodes[k] = v
}

// add the virtual host and mgmt-bridge nodes to the resolve nodes
specialNodes := map[string]types.LinkNode{
"host": types.GetFakeHostLinkNode(),
"mgmt-net": types.GetFakeMgmtBrLinkNode(c.Config.Mgmt.Bridge),
}
for _, n := range specialNodes {
resolveNodes[n.GetShortName()] = n
}

resolveParams := &types.ResolveParams{
Nodes: resolveNodes,
MgmtBridgeName: c.Config.Mgmt.Bridge,
}

for i, l := range c.Config.Topology.Links {
// i represents the endpoint integer and l provide the link struct
l, err := l.Link.Resolve(resolveParams)
if err != nil {
return err
}
c.Endpoints = append(c.Endpoints, l.GetEndpoints()...)
c.Links[i] = l
}
return nil
}
32 changes: 0 additions & 32 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,38 +125,6 @@ func (c *CLab) parseTopology() error {
}
}

// create a types.LinkNode from the nodes.Node
// altough the nodes.Node interface is a Superset of the types.LinkNode
// we need to convert the map, since the whole map seems to not be dynamically typeconvertable
resolveNodes := make(map[string]types.LinkNode, len(c.Nodes))
for k, v := range c.Nodes {
resolveNodes[k] = v
}

// add the virtual host and mgmt-bridge nodes to the resolve nodes
specialNodes := map[string]types.LinkNode{
"host": types.GetFakeHostLinkNode(),
"mgmt-net": types.GetFakeMgmtBrLinkNode(c.Config.Mgmt.Bridge),
}
for _, n := range specialNodes {
resolveNodes[n.GetShortName()] = n
}

resolveParams := &types.ResolveParams{
Nodes: resolveNodes,
MgmtBridgeName: c.Config.Mgmt.Bridge,
}

for i, l := range c.Config.Topology.Links {
// i represents the endpoint integer and l provide the link struct
l, err := l.Link.Resolve(resolveParams)
if err != nil {
return err
}
c.Endpoints = append(c.Endpoints, l.GetEndpoints()...)
c.Links[i] = l
}

// set any containerlab defaults after we've parsed the input
c.setDefaults()

Expand Down
16 changes: 0 additions & 16 deletions clab/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,22 +466,6 @@ func TestLabelsInit(t *testing.T) {
}
}

func TestVerifyRootNetnsInterfaceUniqueness(t *testing.T) {
opts := []ClabOption{
WithTopoFile("test_data/topo7-dup-rootnetns.yml", ""),
}
c, err := NewContainerLab(opts...)
if err != nil {
t.Fatal(err)
}

err = c.verifyRootNetnsInterfaceUniqueness()
if err == nil {
t.Fatalf("expected duplicate rootns links error")
}
t.Logf("error: %v", err)
}

func TestEnvFileInit(t *testing.T) {
tests := map[string]struct {
got string
Expand Down
19 changes: 12 additions & 7 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,32 @@ func deployFn(_ *cobra.Command, _ []string) error {

opts := []clab.ClabOption{
clab.WithTimeout(timeout),
clab.WithTopoFile(topo, varsFile),
clab.WithNodeFilter(nodeFilter),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
clab.WithTopoFile(topo, varsFile),
clab.WithNodeFilter(nodeFilter),
clab.WithDebug(debug),
}
c, err := clab.NewContainerLab(opts...)
if err != nil {
return err
}

// create management network or use existing one
if err = c.CreateNetwork(ctx); err != nil {
return err
}

err = c.ResolveLinks()
if err != nil {
return err
}

setFlags(c.Config)
log.Debugf("lab Conf: %+v", c.Config)

Expand Down Expand Up @@ -185,11 +195,6 @@ func deployFn(_ *cobra.Command, _ []string) error {
return err
}

// create management network or use existing one
if err = c.CreateNetwork(ctx); err != nil {
return err
}

// determine the number of node and link worker
nodeWorkers, _, err := countWorkers(uint(len(c.Nodes)), uint(len(c.Links)), maxWorkers)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ func destroyFn(_ *cobra.Command, _ []string) error {
for topo := range topos {
opts := []clab.ClabOption{
clab.WithTimeout(timeout),
clab.WithTopoFile(topo, varsFile),
clab.WithNodeFilter(nodeFilter),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
clab.WithTopoFile(topo, varsFile),
clab.WithNodeFilter(nodeFilter),
clab.WithDebug(debug),
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ func execFn(_ *cobra.Command, _ []string) error {

opts := []clab.ClabOption{
clab.WithTimeout(timeout),
clab.WithTopoFile(topo, varsFile),
clab.WithNodeFilter(nodeFilter),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
clab.WithTopoFile(topo, varsFile),
clab.WithNodeFilter(nodeFilter),
clab.WithDebug(debug),
}
c, err := clab.NewContainerLab(opts...)
Expand Down
4 changes: 2 additions & 2 deletions cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ Refer to the https://containerlab.dev/cmd/save/ documentation to see the exact c
}
opts := []clab.ClabOption{
clab.WithTimeout(timeout),
clab.WithTopoFile(topo, varsFile),
clab.WithNodeFilter(nodeFilter),
clab.WithRuntime(rt,
&runtime.RuntimeConfig{
Debug: debug,
Timeout: timeout,
GracefulShutdown: graceful,
},
),
clab.WithTopoFile(topo, varsFile),
clab.WithNodeFilter(nodeFilter),
clab.WithDebug(debug),
}
c, err := clab.NewContainerLab(opts...)
Expand Down

0 comments on commit fceb46e

Please sign in to comment.