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

containerd #427

Merged
merged 54 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
77fae8f
containerd
steiler May 25, 2021
11f43d9
update
steiler May 26, 2021
a519147
containers starting now
steiler May 27, 2021
d9e885f
continued
steiler May 27, 2021
5221623
fixed staticcheck and implemented host mode
steiler May 27, 2021
5961a84
fix test
steiler May 27, 2021
a29ede6
cni introduced
steiler Jun 1, 2021
d33387a
port bindings and mac address config
steiler Jun 2, 2021
78772e1
fixed hostmode
steiler Jun 2, 2021
9c5dc68
fixing issues
steiler Jun 2, 2021
a3bc4af
fix destroy command
steiler Jun 7, 2021
cafd1d0
bind mounts do work now
steiler Jun 8, 2021
bb930a2
remove existing netnamespace links
steiler Jun 9, 2021
62de6b3
free cni based ip allocations
steiler Jun 9, 2021
fb87ca6
mgmt ips in deploy output
steiler Jun 9, 2021
f1996a1
srl up and running
steiler Jun 10, 2021
4b87dfa
accept 'implicit', image defined user and cmd (as well as entrypoint)
steiler Jun 10, 2021
2514944
cni config put in code, CNI_BIN env var to overwrite cni plugin binar…
steiler Jun 10, 2021
4e64d2a
store mgmt ip in container labels for later usage
steiler Jun 10, 2021
3884a9f
fixed concurrent access issue, also preparing ip information label fo…
steiler Jun 11, 2021
9d02826
Merge remote-tracking branch 'remotes/wim/master' into containerd
Jun 11, 2021
5a644ff
fixed merge regression
steiler Jun 11, 2021
164cbf1
fixing smoketests
steiler Jun 11, 2021
26a7123
fixing deepsource issues
steiler Jun 11, 2021
d89e783
add support for non canonical image names for containerd
hellt Jun 14, 2021
0e48e7c
drop non required sysctl; streamline method name
steiler Jun 14, 2021
0bde6cf
bring back cont name in delete error msg
hellt Jun 15, 2021
8256a24
trim slashes in cont name
hellt Jun 15, 2021
192ec5e
fix test cleanup
hellt Jun 15, 2021
b93604d
added comment about .dockerenv for srl
hellt Jun 15, 2021
29134ba
removed unused example
hellt Jun 15, 2021
bee3dab
added short id for table printer
hellt Jun 15, 2021
dad20b6
linter
hellt Jun 15, 2021
1633675
containerd exec, exitnowait
steiler Jun 15, 2021
81a7b91
Merge branch 'containerd' of github.com:steiler/container-lab into co…
steiler Jun 15, 2021
3f113be
Merge remote-tracking branch 'wim/master' into containerd
steiler Jun 15, 2021
fa56d64
adjusted containerd to new runtime interface changes
steiler Jun 15, 2021
095f043
refactored tests to accommodate for containerd
hellt Jun 15, 2021
e9b76d9
fix test name
hellt Jun 15, 2021
5cc5f43
gitlab ci for containerd
hellt Jun 15, 2021
e6064e7
added runtime var for smoke tests
hellt Jun 15, 2021
937cad9
CNI binary check
steiler Jun 16, 2021
77d934e
Merge branch 'containerd' of github.com:steiler/container-lab into co…
steiler Jun 16, 2021
44e13ad
docker runtime to issue err instead of log.fatal
steiler Jun 16, 2021
71553aa
Update clos02.clab.yml
steiler Jun 16, 2021
d55245c
pull GetCNIBinaryPath into utils package
steiler Jun 16, 2021
9158e9e
incorporated @karimra's comments
steiler Jun 16, 2021
839b164
second round of @karimra's comments
steiler Jun 16, 2021
7cb24d8
print actual runtime to log
steiler Jun 16, 2021
e0fce2d
allow runtime to be selected via CLAB_RUNTIME environment variable
steiler Jun 16, 2021
d3df161
allow implicit latest tag for containerd
steiler Jun 16, 2021
8261c10
return error for not implemented container inspect
hellt Jun 16, 2021
793cb48
removed junk file
hellt Jun 16, 2021
91bcd27
refactor runtime version election
hellt Jun 16, 2021
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
6 changes: 1 addition & 5 deletions clab/ceos.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net"
"path"
"path/filepath"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -41,13 +40,10 @@ func ceosPostDeploy(ctx context.Context, c *CLab, node *types.Node, lworkers uin
if err != nil {
return err
}
// since container has been restarted, we need to get its new NSPath and link netns
cont, err := c.Runtime.ContainerInspect(ctx, node.ContainerID)
node.NSPath, err = c.Runtime.GetNSPath(ctx, node.ContainerID)
if err != nil {
return err
}
log.Debugf("node %s new pid %v", node.LongName, cont.Pid)
node.NSPath = "/proc/" + strconv.Itoa(cont.Pid) + "/ns/net"
err = utils.LinkContainerNS(node.NSPath, node.LongName)
if err != nil {
return err
Expand Down
7 changes: 5 additions & 2 deletions clab/clab.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ func WithRuntime(name string, d bool, dur time.Duration, gracefulShutdown bool)
return func(c *CLab) {
if rInit, ok := runtime.ContainerRuntimes[name]; ok {
c.Runtime = rInit()
c.Runtime.Init(
err := c.Runtime.Init(
runtime.WithConfig(&runtime.RuntimeConfig{
Timeout: dur,
Debug: d,
}),
runtime.WithMgmtNet(c.Config.Mgmt),
)
if err != nil {
log.Fatalf("failed to init the container runtime: %s", err)
}
return
}
log.Fatalf("unknown container runtime %q", name)
Expand Down Expand Up @@ -341,7 +344,7 @@ func (c *CLab) DeleteNodes(ctx context.Context, workers uint, containers []types
if len(cont.Names) > 0 {
name = strings.TrimLeft(cont.Names[0], "/")
steiler marked this conversation as resolved.
Show resolved Hide resolved
}
err := c.Runtime.DeleteContainer(ctx, name)
err := c.Runtime.DeleteContainer(ctx, cont)
if err != nil {
log.Errorf("could not remove container '%s': %v", name, err)
}
steiler marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 1 addition & 1 deletion clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func (c *CLab) VerifyContainersUniqueness(ctx context.Context) error {
nctx, cancel := context.WithTimeout(ctx, c.timeout)
defer cancel()

var labels []string
labels := []*types.GenericFilter{}
steiler marked this conversation as resolved.
Show resolved Hide resolved
containers, err := c.Runtime.ListContainers(nctx, labels)
if err != nil {
return fmt.Errorf("could not list containers: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions clab/srl.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func initSRLNode(c *CLab, nodeCfg NodeConfig, node *types.Node, user string, env
log.Fatalf("wrong node type. '%s' doesn't exist. should be any of %s", node.NodeType, strings.Join(keys, ", "))
}

// initialize specifc container information
node.Cmd = "sudo sr_linux"
// the addition touch is needed to support non docker runtimes
node.Cmd = "sudo bash -c 'touch /.dockerenv && /opt/srlinux/bin/sr_linux'"

kindEnv := map[string]string{"SRLINUX": "1"}
node.Env = mergeStringMaps(kindEnv, envs)
Expand Down
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var deployCmd = &cobra.Command{
}
log.Debug("containers created, retrieving state and IP addresses...")

labels = append(labels, "containerlab="+c.Config.Name)
labels := []*types.GenericFilter{{FilterType: "label", Match: c.Config.Name, Field: "containerlab", Operator: "="}}
containers, err := c.Runtime.ListContainers(ctx, labels)
if err != nil {
return fmt.Errorf("could not list containers: %v", err)
Expand Down
10 changes: 6 additions & 4 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var destroyCmd = &cobra.Command{
}
c := clab.NewContainerLab(opts...)
// list all containerlab containers
containers, err := c.Runtime.ListContainers(ctx, []string{"containerlab"})
containers, err := c.Runtime.ListContainers(ctx, []*types.GenericFilter{{FilterType: "label", Field: "containerlab", Operator: "exists"}})
if err != nil {
return fmt.Errorf("could not list containers: %v", err)
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func deleteEntriesFromHostsFile(containers []types.GenericContainer, bridgeName
if bridgeName == "" {
return fmt.Errorf("missing bridge name")
}
f, err := os.OpenFile("/etc/hosts", os.O_RDWR, 0644)
f, err := os.OpenFile("/etc/hosts", os.O_RDWR, 0644) // skipcq: GSC-G302
if err != nil {
return err
}
Expand Down Expand Up @@ -171,7 +171,9 @@ func deleteEntriesFromHostsFile(containers []types.GenericContainer, bridgeName
}

func destroyLab(ctx context.Context, c *clab.CLab) (err error) {
containers, err := c.Runtime.ListContainers(ctx, []string{fmt.Sprintf("containerlab=%s", c.Config.Name)})

labels := []*types.GenericFilter{{FilterType: "label", Match: c.Config.Name, Field: "containerlab", Operator: "="}}
containers, err := c.Runtime.ListContainers(ctx, labels)
if err != nil {
return fmt.Errorf("could not list containers: %v", err)
}
Expand Down Expand Up @@ -207,7 +209,7 @@ func destroyLab(ctx context.Context, c *clab.CLab) (err error) {
}

// delete lab management network
log.Infof("Deleting docker network '%s'...", c.Config.Mgmt.Network)
log.Infof("Deleting network '%s'...", c.Config.Mgmt.Network)
if err = c.Runtime.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 Down
8 changes: 3 additions & 5 deletions cmd/disableTxOffload.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package cmd

import (
"context"
"strconv"

"github.com/containernetworking/plugins/pkg/ns"
log "github.com/sirupsen/logrus"
Expand All @@ -33,13 +32,12 @@ var disableTxOffloadCmd = &cobra.Command{
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

cnt, err := c.Runtime.ContainerInspect(ctx, cntName)
log.Infof("getting container '%s' information", cntName)

NSPath, err := c.Runtime.GetNSPath(ctx, cntName)
if err != nil {
return err
}

log.Infof("getting container '%s' information", cntName)
NSPath := "/proc/" + strconv.Itoa(cnt.Pid) + "/ns/net"
nodeNS, err := ns.GetNS(NSPath)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/srl-labs/containerlab/clab"
"github.com/srl-labs/containerlab/types"
)

var labels []string
Expand Down Expand Up @@ -44,7 +45,7 @@ var execCmd = &cobra.Command{
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
labels = append(labels, "containerlab="+name)
labels := []*types.GenericFilter{{FilterType: "label", Match: name, Field: "containerlab", Operator: "="}}
steiler marked this conversation as resolved.
Show resolved Hide resolved
containers, err := c.Runtime.ListContainers(ctx, labels)
if err != nil {
log.Fatalf("could not list containers: %v", err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ var graphCmd = &cobra.Command{
// if offline mode is not enforced, list containers matching lab name
if !offline {
var err error
containers, err = c.Runtime.ListContainers(ctx, []string{fmt.Sprintf("containerlab=%s", c.Config.Name)})
labels := []*types.GenericFilter{{FilterType: "label", Match: c.Config.Name, Field: "containerlab", Operator: "="}}
containers, err = c.Runtime.ListContainers(ctx, labels)
if err != nil {
log.Errorf("could not list containers: %v", err)
}
Expand Down
16 changes: 10 additions & 6 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ var inspectCmd = &cobra.Command{
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
var glabels []*types.GenericFilter
if all {
labels = append(labels, "containerlab")
glabels = []*types.GenericFilter{{FilterType: "label", Field: "containerlab", Operator: "exists"}}
} else {
labels = append(labels, "containerlab="+name)
if name != "" {
glabels = []*types.GenericFilter{{FilterType: "label", Match: name, Field: "containerlab", Operator: "="}}
} else if topo != "" {
glabels = []*types.GenericFilter{{FilterType: "label", Match: c.Config.Name, Field: "containerlab", Operator: "="}}
}
}
containers, err := c.Runtime.ListContainers(ctx, labels)
containers, err := c.Runtime.ListContainers(ctx, glabels)
if err != nil {
log.Fatalf("could not list containers: %v", err)
}
Expand Down Expand Up @@ -128,9 +133,8 @@ func printContainerInspect(c *clab.CLab, containers []types.GenericContainer, br
IPv4Address: getContainerIPv4(cont, bridgeName),
IPv6Address: getContainerIPv6(cont, bridgeName),
}
if len(cont.ID) > 11 {
hellt marked this conversation as resolved.
Show resolved Hide resolved
cdet.ContainerID = cont.ID[:12]
}
cdet.ContainerID = cont.ShortID

if len(cont.Names) > 0 {
cdet.Name = strings.TrimLeft(cont.Names[0], "/")
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Refer to the https://containerlab.srlinux.dev/cmd/save/ documentation to see the
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

containers, err := c.Runtime.ListContainers(ctx, []string{"containerlab=" + c.Config.Name})
labels := []*types.GenericFilter{{FilterType: "label", Match: c.Config.Name, Field: "containerlab", Operator: "="}}
containers, err := c.Runtime.ListContainers(ctx, labels)
if err != nil {
return fmt.Errorf("could not list containers: %v", err)
}
Expand Down
13 changes: 8 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,27 @@ require (
github.com/Juniper/go-netconf v0.1.1
github.com/awalterschulze/gographviz v2.0.1+incompatible
github.com/cloudflare/cfssl v1.4.1
github.com/containerd/containerd v1.5.0 // indirect
github.com/containerd/containerd v1.5.2
github.com/containernetworking/cni v0.8.1
github.com/containernetworking/plugins v0.9.1
github.com/digitalocean/go-openvswitch v0.0.0-20201214180534-ce0f183468d8
github.com/docker/docker v20.10.6+incompatible
github.com/docker/go-connections v0.4.0
github.com/google/go-cmp v0.5.4
github.com/docker/go-units v0.4.0
github.com/google/go-cmp v0.5.6
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.2.0
github.com/hashicorp/go-version v1.2.1
github.com/jsimonetti/rtnetlink v0.0.0-20210226120601-1b79e63a70a0
github.com/mitchellh/go-homedir v1.1.0
github.com/morikuni/aec v1.0.0 // indirect
github.com/olekukonko/tablewriter v0.0.5-0.20201029120751-42e21c7531a3
github.com/sirupsen/logrus v1.7.0
github.com/opencontainers/runtime-spec v1.0.3-0.20210303205135-43e4633e40c1
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.0.0
github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852
github.com/vishvananda/netlink v1.1.1-0.20210330154013-f5de75959ad5
github.com/ziutek/telnet v0.0.0-20180329124119-c3b780dc415b // indirect
golang.org/x/term v0.0.0-20210503060354-a79de5458b56
gopkg.in/yaml.v2 v2.4.0
)

Loading