Skip to content

Commit

Permalink
Merge pull request #674 from LimeHat/podman-support
Browse files Browse the repository at this point in the history
Podman support beta
  • Loading branch information
hellt authored Jan 24, 2022
2 parents 4141b37 + d594889 commit db5847d
Show file tree
Hide file tree
Showing 22 changed files with 1,310 additions and 58 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
${{ runner.os }}-go-
- name: Build containerlab
run: go build
run: CGO_ENABLED=0 go build -o containerlab -ldflags="-s -w -X 'github.com/srl-labs/containerlab/cmd.version=0.0.0' -X 'github.com/srl-labs/containerlab/cmd.commit=$(git rev-parse --short HEAD)' -X 'github.com/srl-labs/containerlab/cmd.date=$(date)'" -trimpath -tags "podman exclude_graphdriver_btrfs btrfs_noversion exclude_graphdriver_devicemapper exclude_graphdriver_overlay containers_image_openpgp" main.go
# store clab binary as artifact
- uses: actions/upload-artifact@v2
with:
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
runtime: ["docker", "containerd"]
runtime: ["docker", "containerd", "podman"]
needs:
- unit-test
- build-containerlab
Expand All @@ -121,6 +121,10 @@ jobs:
name: containerlab
- name: Move containerlab to usr/bin
run: sudo mv ./containerlab /usr/bin/containerlab && sudo chmod a+x /usr/bin/containerlab

- name: Enable Podman API service
run: sudo systemctl start podman

- uses: actions/setup-python@v2
with:
python-version: "3.8"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ site/
.DS_Store
__rd*
tests/out

**/.*clab.y?ml
3 changes: 3 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ builds:
- id: clab-bin
env:
- CGO_ENABLED=0
flags:
- -trimpath
- -tags="podman exclude_graphdriver_btrfs btrfs_noversion exclude_graphdriver_devicemapper exclude_graphdriver_overlay containers_image_openpgp"
ldflags:
- -s -w -X github.com/srl-labs/containerlab/cmd.version={{.Version}} -X github.com/srl-labs/containerlab/cmd.commit={{.ShortCommit}} -X github.com/srl-labs/containerlab/cmd.date={{.Date}}
goos:
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ build:
mkdir -p $(BIN_DIR)
go build -o $(BINARY) -ldflags="-s -w -X 'github.com/srl-labs/containerlab/cmd.version=0.0.0' -X 'github.com/srl-labs/containerlab/cmd.commit=$$(git rev-parse --short HEAD)' -X 'github.com/srl-labs/containerlab/cmd.date=$$(date)'" main.go

build-with-podman:
mkdir -p $(BIN_DIR)
CGO_ENABLED=0 go build -o $(BINARY) -ldflags="-s -w -X 'github.com/srl-labs/containerlab/cmd.version=0.0.0' -X 'github.com/srl-labs/containerlab/cmd.commit=$$(git rev-parse --short HEAD)' -X 'github.com/srl-labs/containerlab/cmd.date=$$(date)'" -trimpath -tags "podman exclude_graphdriver_btrfs btrfs_noversion exclude_graphdriver_devicemapper exclude_graphdriver_overlay containers_image_openpgp" main.go

test:
go test -race ./... -v

Expand All @@ -28,5 +32,5 @@ site:
.PHONY: htmltest
htmltest:
docker run --rm -v $$(pwd):/docs --entrypoint mkdocs squidfunk/mkdocs-material:$(MKDOCS_VER) build --clean --strict
docker run --rm -v $$(pwd):/test wjdp/htmltest --conf ./site/htmltest.yml
docker run --rm -v $$(pwd):/test wjdp/htmltest --conf ./site/htmltest-w-github.yml
rm -rf ./site
7 changes: 5 additions & 2 deletions clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func WithRuntime(name string, rtconfig *runtime.RuntimeConfig) ClabOption {
// define runtime name.
// order of preference: cli flag -> env var -> default value of docker
envN := os.Getenv("CLAB_RUNTIME")
log.Debugf("envN runtime var value is %v", envN)
switch {
case name != "":
case envN != "":
Expand All @@ -69,6 +70,7 @@ func WithRuntime(name string, rtconfig *runtime.RuntimeConfig) ClabOption {

if rInit, ok := runtime.ContainerRuntimes[name]; ok {
r := rInit()
log.Debugf("Running runtime.Init with params %+v and %+v", rtconfig, c.Config.Mgmt)
err := r.Init(
runtime.WithConfig(rtconfig),
runtime.WithMgmtNet(c.Config.Mgmt),
Expand All @@ -78,7 +80,7 @@ func WithRuntime(name string, rtconfig *runtime.RuntimeConfig) ClabOption {
}

c.Runtimes[name] = r

log.Debugf("initialized a runtime with params %+v", r)
return nil
}
return fmt.Errorf("unknown container runtime %q", name)
Expand Down Expand Up @@ -136,14 +138,15 @@ func NewContainerLab(opts ...ClabOption) (*CLab, error) {

// initMgmtNetwork sets management network config
func (c *CLab) initMgmtNetwork() error {
log.Debugf("method initMgmtNetwork was called mgmt params %+v", c.Config.Mgmt)
if c.Config.Mgmt.Network == "" {
c.Config.Mgmt.Network = dockerNetName
}
if c.Config.Mgmt.IPv4Subnet == "" && c.Config.Mgmt.IPv6Subnet == "" {
c.Config.Mgmt.IPv4Subnet = dockerNetIPv4Addr
c.Config.Mgmt.IPv6Subnet = dockerNetIPv6Addr
}

log.Debugf("New mgmt params are %+v", c.Config.Mgmt)
// init docker network mtu
if c.Config.Mgmt.MTU == "" {
m, err := utils.DefaultNetMTU()
Expand Down
12 changes: 9 additions & 3 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ var destroyCmd = &cobra.Command{
topos[cont.Labels["clab-topo-file"]] = struct{}{}
}
}

log.Debugf("We got a topos struct for detroy: %+v", topos)
for topo := range topos {
opts := append(opts,
clab.WithTopoFile(topo, varsFile),
)
log.Debugf("going through extracted topos for destroy, got a topo file %v and generated opts list %+v", topo, opts)
c, err := clab.NewContainerLab(opts...)
if err != nil {
return err
Expand Down Expand Up @@ -167,11 +168,12 @@ func destroyLab(ctx context.Context, c *clab.CLab) (err error) {
log.Info("Removing containerlab host entries from /etc/hosts file")
err = clab.DeleteEntriesFromHostsFile(c.Config.Name)
if err != nil {
return err
return fmt.Errorf("error while trying to clean up the hosts file: %w", err)
}

// delete lab management network
if c.Config.Mgmt.Network != "bridge" && !keepMgmtNet {
log.Debugf("Calling DeleteNet method. *CLab.Config.Mgmt value is: %+v", c.Config.Mgmt)
if err = c.GlobalRuntime().DeleteNet(ctx); err != nil {
// do not log error message if deletion error simply says that such network doesn't exist
if err.Error() != fmt.Sprintf("Error: No such network: %s", c.Config.Mgmt.Network) {
Expand All @@ -180,5 +182,9 @@ func destroyLab(ctx context.Context, c *clab.CLab) (err error) {
}
}
// delete container network namespaces symlinks
return c.DeleteNetnsSymlinks()
err = c.DeleteNetnsSymlinks()
if err != nil {
return fmt.Errorf("error while deleting netns symlinks: %w", err)
}
return nil
}
7 changes: 4 additions & 3 deletions docs/cmd/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ Refer to the [configuration artifacts](../manual/conf-artifacts.md) page to get
With `--max-workers` flag it is possible to limit the amout of concurrent workers that create containers or wire virtual links. By default the number of workers equals the number of nodes/links to create.

#### runtime
Containerlab nodes can be started by different runtimes, with `docker` being the default one. Besides `docker`, containerlab has experimental support for `containerd` and `ignite` runtimes.
Containerlab nodes can be started by different runtimes, with `docker` being the default one. Besides that, containerlab has experimental support for `podman`, `containerd`, and `ignite` runtimes.

A global runtime can be selected with a global `--runtime | -r` flag that will select a runtime to use. The supported value are:
A global runtime can be selected with a global `--runtime | -r` flag that will select a runtime to use. The possible value are:

* `docker` - default
* `containerd`
* `podman` - beta support
* `containerd` - experimental support
* `ignite`

#### timeout
Expand Down
29 changes: 29 additions & 0 deletions docs/htmltest-w-github.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# adopted from https://github.com/goreleaser/goreleaser/blob/5adf43295767b5be05fa38a01ffb3ad25bd21797/www/htmltest.yml
# using https://github.com/wjdp/htmltest

# this version does not ignore github links and is meant to be run via makefile on the user's machine
# the CI-friendly htmltest config file is named htmltest.yml and excludes github.com links, as they are often return HTTP 429
DirectoryPath: ./site
IgnoreURLs:
- fonts.gstatic.com
- img.shields.io
- www.reddit.com/r/bashonubuntuonwindows/comments/ldbyxa/what_is_the_current_state_of_kvm_acceleration_on/ # sometimes timeouts for unknown reason
- goreleaser.com # doesn't support `range 0` GETs which htmltest uses
- https://documentation.nokia.com/cgi-bin/dbaccessfilename.cgi/3HE15836AAADTQZZA01_V1_vSIM%20Installation%20and%20Setup%20Guide%2020.10.R1.pdf # fuck this false positives...
- https://documentation.nokia.com/cgi-bin/dbaccessfilename.cgi/3HE16113AAAATQZZA01_V1_SR%20Linux%20R20.6%20Software%20Installation.pdf
- https://github.com/srl-labs/containerlab/releases/ # gh rate limiters for this particular endpoint are too aggressive
- https://github.com/srl-labs/containerlab/pkgs/container/clab
- https://linkedin.com/in
- https://www.linkedin.com/in
IgnoreDirectoryMissingTrailingSlash: true
IgnoreAltMissing: true
IgnoreSSLVerify: true
IgnoreDirs:
- overrides
IgnoreInternalEmptyHash: true
ExternalTimeout: 60
HTTPHeaders:
"Range": "bytes=0-10"
"Accept": "*/*"
CacheExpires: "168h"
HTTPConcurrencyLimit: 1
1 change: 1 addition & 0 deletions docs/htmltest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ IgnoreURLs:
- https://github.com/srl-labs/containerlab/pkgs/container/clab
- https://linkedin.com/in
- https://www.linkedin.com/in
- https://*github.com/
IgnoreDirectoryMissingTrailingSlash: true
IgnoreAltMissing: true
IgnoreSSLVerify: true
Expand Down
3 changes: 2 additions & 1 deletion docs/manual/nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,13 @@ my-node:
The `network-mode` configuration option set to `host` will launch the node in the [host networking mode](https://docs.docker.com/network/host/).

### runtime
By default containerlab nodes will be started by `docker` container runtime. Besides that, containerlab has experimental support for `containerd` and `ignite` runtimes.
By default containerlab nodes will be started by `docker` container runtime. Besides that, containerlab has experimental support for `podman`, `containerd`, and `ignite` runtimes.

It is possible to specify a global runtime with a global `--runtime` flag, or set the runtime on a per-node basis:

Options for the runtime parameter are:
- `docker`
- `podman`
- `containerd`
- `ignite`

Expand Down
Loading

0 comments on commit db5847d

Please sign in to comment.