Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing #456 #458

Merged
merged 3 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func init() {

func (c *ContainerdRuntime) Init(opts ...runtime.RuntimeOption) error {
var err error
log.Info("Runtime: containerd")
log.Debug("Runtime: containerd")
c.client, err = containerd.New("/run/containerd/containerd.sock")
if err != nil {
return err
Expand Down
8 changes: 2 additions & 6 deletions runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type DockerRuntime struct {

func (c *DockerRuntime) Init(opts ...runtime.RuntimeOption) error {
var err error
log.Info("Runtime: Docker")
log.Debug("Runtime: Docker")
c.Client, err = dockerC.NewClientWithOpts(dockerC.FromEnv, dockerC.WithAPIVersionNegotiation())
if err != nil {
return err
Expand Down Expand Up @@ -360,14 +360,10 @@ func (c *DockerRuntime) ListContainers(ctx context.Context, gfilters []*types.Ge
}
var nr []dockerTypes.NetworkResource
if c.Mgmt.Network == "" {
netFilter := filters.NewArgs()
netFilter.Add("label", "containerlab")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can create a filter that will capture both networks that have a containerlab label OR network which have bridge name

That way we will avoid getting the networks that could be created by users/other_systems and which are not needed for our purposes.

It is potentially an optimization, which is not necessary, but seems like nice to have.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be an AND operation if you add name=bridge
To do an OR, 2 queries need to be performed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, here is what I did

	if c.Mgmt.Network == "" {
		nctx, cancel := context.WithTimeout(ctx, c.timeout)
		defer cancel()
		// fetch containerlab created networks
		f := filters.NewArgs()
		f.Add("label", "containerlab")
		nr, err = c.Client.NetworkList(nctx, dockerTypes.NetworkListOptions{
			Filters: f,
		})

		if err != nil {
			return nil, err
		}

		// fetch default bridge network
		f = filters.NewArgs()
		f.Add("name", "bridge")
		bridgenet, err := c.Client.NetworkList(nctx, dockerTypes.NetworkListOptions{
			Filters: f,
		})

		if err != nil {
			return nil, err
		}

		nr = append(nr, bridgenet...)

not sure which is better though =)

nctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()

nr, err = c.Client.NetworkList(nctx, dockerTypes.NetworkListOptions{
Filters: netFilter,
})
nr, err = c.Client.NetworkList(nctx, dockerTypes.NetworkListOptions{})
if err != nil {
return nil, err
}
Expand Down