From 36dc8462acbe90e20a9d70e503e4ee49a9075f5f Mon Sep 17 00:00:00 2001 From: Karim Radhouani Date: Thu, 27 May 2021 22:24:52 +0800 Subject: [PATCH 1/2] fix mgm-net feature regression --- clab/clab.go | 4 +++- clab/config.go | 2 +- runtime/docker/docker.go | 5 +++-- runtime/runtime.go | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/clab/clab.go b/clab/clab.go index 8acb06148..8e2bc6231 100644 --- a/clab/clab.go +++ b/clab/clab.go @@ -84,7 +84,9 @@ func WithGracefulShutdown(gracefulShutdown bool) ClabOption { // NewContainerLab function defines a new container lab func NewContainerLab(opts ...ClabOption) *CLab { c := &CLab{ - Config: new(Config), + Config: &Config{ + Mgmt: new(types.MgmtNet), + }, TopoFile: new(TopoFile), m: new(sync.RWMutex), Nodes: make(map[string]*types.Node), diff --git a/clab/config.go b/clab/config.go index c632605e1..e3cdaef14 100644 --- a/clab/config.go +++ b/clab/config.go @@ -82,7 +82,7 @@ var srlTypes = map[string]string{ // Config defines lab configuration as it is provided in the YAML file type Config struct { Name string `json:"name,omitempty"` - Mgmt types.MgmtNet `json:"mgmt,omitempty"` + Mgmt *types.MgmtNet `json:"mgmt,omitempty"` Topology Topology `json:"topology,omitempty"` ConfigPath string `yaml:"config_path,omitempty"` } diff --git a/runtime/docker/docker.go b/runtime/docker/docker.go index 3c9c6e94e..e5d8baa75 100644 --- a/runtime/docker/docker.go +++ b/runtime/docker/docker.go @@ -28,7 +28,7 @@ const sysctlBase = "/proc/sys" type DockerRuntime struct { Client *dockerC.Client timeout time.Duration - Mgmt types.MgmtNet + Mgmt *types.MgmtNet debug bool gracefulShutdown bool } @@ -48,7 +48,7 @@ func NewDockerRuntime(d bool, dur time.Duration, gracefulShutdown bool) *DockerR } } -func (c *DockerRuntime) SetMgmtNet(n types.MgmtNet) { +func (c *DockerRuntime) SetMgmtNet(n *types.MgmtNet) { c.Mgmt = n } @@ -127,6 +127,7 @@ func (c *DockerRuntime) CreateNet(ctx context.Context) (err error) { default: return err } + fmt.Println("bridgeName", bridgeName) c.Mgmt.Bridge = bridgeName log.Debugf("Docker network '%s', bridge name '%s'", c.Mgmt.Network, bridgeName) diff --git a/runtime/runtime.go b/runtime/runtime.go index 7b7c3d486..44f5fb3c0 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -16,7 +16,7 @@ const ( type ContainerRuntime interface { // Set the network management details (generated by the config.go) - SetMgmtNet(types.MgmtNet) + SetMgmtNet(*types.MgmtNet) // Create container (bridge) network CreateNet(context.Context) error // Delete container (bridge) network From 5eaffd726e9c49437c42f61823537c956e5462ae Mon Sep 17 00:00:00 2001 From: Karim Radhouani Date: Thu, 27 May 2021 22:28:46 +0800 Subject: [PATCH 2/2] init Mgmt stuct --- runtime/docker/docker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/docker/docker.go b/runtime/docker/docker.go index e5d8baa75..e34121b0a 100644 --- a/runtime/docker/docker.go +++ b/runtime/docker/docker.go @@ -41,6 +41,7 @@ func NewDockerRuntime(d bool, dur time.Duration, gracefulShutdown bool) *DockerR return &DockerRuntime{ Client: c, + Mgmt: new(types.MgmtNet), // TODO: undo this hard-coding timeout: dur, debug: d, @@ -127,7 +128,6 @@ func (c *DockerRuntime) CreateNet(ctx context.Context) (err error) { default: return err } - fmt.Println("bridgeName", bridgeName) c.Mgmt.Bridge = bridgeName log.Debugf("Docker network '%s', bridge name '%s'", c.Mgmt.Network, bridgeName)