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

Moved docker behind a new runtime interface #416

Merged
merged 11 commits into from
May 11, 2021
Merged

Moved docker behind a new runtime interface #416

merged 11 commits into from
May 11, 2021

Conversation

networkop
Copy link
Contributor

@networkop networkop commented May 5, 2021

This is some quick prototyping I've done to kick-start the discussion raised in #415. Most of the code logic is still the same, the only difference is all docker api interactions are hidden behind a generic container runtime interface.
There are 3 new folders:

  1. ./runtime - contains interface definition and docker runtime
  2. ./types - generic types that are required by both clab and runtimes (moved some types from config.go to avoid circular imports)
  3. ./utils - again some generic util functions

Have a look, let me know what you think 😄

@hellt
Copy link
Member

hellt commented May 6, 2021

thanks @networkop
basic integration tests for ceos and srl have passed as well - https://gitlab.com/rdodin/containerlab/-/pipelines/298197975

I wonder how you imagine the runtime selection/sensing needs to be handled?

@networkop
Copy link
Contributor Author

@hellt there's a new CLI argument --runtime that defaults to docker. check out ./cmd/root.go. that's how pretty much most of the tools I'd seen are working. auto-sensing is too laborious to implement and maintain.

@networkop
Copy link
Contributor Author

latest commit was tested on docker-ce 19.03.15.

cmd/deploy.go Outdated Show resolved Hide resolved
clab/clab.go Outdated Show resolved Hide resolved
clab/clab.go Outdated
}
// init docker network mtu
if c.Config.Mgmt.MTU == "" {
m, err := getDefaultDockerMTU()
Copy link
Member

Choose a reason for hiding this comment

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

likely this func needs to be runtime-scoped? i.e. with containerd/podman the logic should be runtime-specific as docker0 interface won't be there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so should we move this whole function under the runtime interface? or do you want to just skip MTU here and set it in the runtime?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tbh, I don't fully understand the need to initMgmtNetwork. why can't we just defer to the runtime to set it all up (after all it's managing it's own IPAM). maybe you can elaborate @hellt ?

Copy link
Member

Choose a reason for hiding this comment

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

I think we can start with a small change of adding a new runtime-specific function named DefaultMgmtNetMTU which will return the default management network MTU using the runtime-specific methods.

Copy link
Member

Choose a reason for hiding this comment

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

@networkop the initMgmtNetwork was created to set the default configuration values for mgmtNetName (clab) and default subnets for ipv4/6

It might be that this can be removed/changed with the default values to be passed over to the respective runtime func that creates the network

Copy link
Contributor Author

Choose a reason for hiding this comment

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

at this stage, i think the only right solution (I think) is to leave MTU unchanged and do a check (if empty, then lookup) inside the CreateNet function, which is the only place where MTU is used.

Copy link
Member

Choose a reason for hiding this comment

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

but the runtime name is always provided via rt value, and has a docker default, no?

Copy link
Contributor Author

@networkop networkop May 10, 2021

Choose a reason for hiding this comment

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

yes, there's always a runtime set. The problem is that runtime is currently optional and most of the config_test.go functions are set up just WithTopoFile. It's not a problem adding a WithRuntime to them as well, it'll work, but it is an indication of leaking dependencies -- your config test code should not really rely on a runtime being set.
But if you're ok with this, I'm happy to add runtime to every test in config_test.go, so they'll all look like:

	for name, tc := range tests {
		t.Run(name, func(t *testing.T) {
			opts := []ClabOption{
				WithTopoFile(tc.got),
+                              WithRuntime(...),
			}

Copy link
Member

Choose a reason for hiding this comment

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

maybe we should defer this till we sort the other things

Copy link
Contributor Author

@networkop networkop May 10, 2021

Choose a reason for hiding this comment

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

another issue with getting default MTU is determining which bridge to use. Some runtimes may defer to CNI plugins to setup the networking, which means we'd have to parse all CNI configuration files in order to extract the name of the bridge, and it may not even exist in case of a P2P CNI plugin. So maybe we should just have the magic getDefaultMTU function that picks the lowest MTU off several well-known bridge names, and, if none found, falls back to some safe default, e.g. 1400. wdyt @hellt

cmd/deploy.go Outdated Show resolved Hide resolved
@hellt
Copy link
Member

hellt commented May 10, 2021

runtime/runtime.go Outdated Show resolved Hide resolved
@networkop
Copy link
Contributor Author

@networkop can we address this deprecation issue as well? https://github.com/srl-labs/containerlab/pull/416/checks?check_run_id=2545109898#step:4:26

This is a transitive dependency, I'll just add this to go.mod, i think that should fix it?

replace golang.org/x/crypto/ssh/terminal => golang.org/x/term v0.0.0-20210503060354-a79de5458b56

go.mod Outdated Show resolved Hide resolved
cmd/inspect.go Outdated Show resolved Hide resolved
@hellt hellt merged commit b9c0c26 into srl-labs:master May 11, 2021
@hellt hellt mentioned this pull request May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants