Skip to content

Commit

Permalink
Merge branch 'containerd' of github.com:steiler/container-lab into co…
Browse files Browse the repository at this point in the history
…ntainerd
  • Loading branch information
steiler committed Jun 15, 2021
2 parents 1633675 + dad20b6 commit 81a7b91
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 94 deletions.
2 changes: 1 addition & 1 deletion clab/srl.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ 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
// 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"}
Expand Down
10 changes: 5 additions & 5 deletions cmd/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,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 @@ -207,12 +207,12 @@ func destroyLab(ctx context.Context, c *clab.CLab) (err error) {
log.Debugf("Worker %d terminating...", i)
return
}
//if len(cont.Names) > 0 {
// name = strings.TrimLeft(cont.Names[0], "/")
//}
if len(cont.Names) > 0 {
name = strings.TrimLeft(cont.Names[0], "/")
}
err := c.Runtime.DeleteContainer(ctx, cont)
if err != nil {
log.Errorf("could not remove container: %v", err)
log.Errorf("could not remove container %s: %v", name, err)
}
case <-ctx.Done():
return
Expand Down
2 changes: 1 addition & 1 deletion cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func printContainerInspect(c *clab.CLab, containers []types.GenericContainer, br
IPv4Address: getContainerIPv4(cont, bridgeName),
IPv6Address: getContainerIPv6(cont, bridgeName),
}
cdet.ContainerID = cont.ID
cdet.ContainerID = cont.ShortID

if len(cont.Names) > 0 {
cdet.Name = strings.TrimLeft(cont.Names[0], "/")
Expand Down
78 changes: 0 additions & 78 deletions lab-examples/clos02/clos02-containerd.clab.yml

This file was deleted.

1 change: 1 addition & 0 deletions runtime/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ func (c *ContainerdRuntime) produceGenericContainerList(ctx context.Context, inp

ctr.Names = []string{i.ID()}
ctr.ID = i.ID()
ctr.ShortID = ctr.ID
ctr.Image = info.Image
ctr.Labels = info.Labels

Expand Down
18 changes: 10 additions & 8 deletions runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io/ioutil"
"path"
"strconv"
"strings"
"time"

dockerTypes "github.com/docker/docker/api/types"
Expand Down Expand Up @@ -374,12 +375,13 @@ func (c *DockerRuntime) produceGenericContainerList(inputContainers []dockerType

for _, i := range inputContainers {
ctr := types.GenericContainer{
Names: i.Names,
ID: i.ID,
Image: i.Image,
State: i.State,
Status: i.Status,
Labels: i.Labels,
Names: i.Names,
ID: i.ID,
ShortID: i.ID[:12],
Image: i.Image,
State: i.State,
Status: i.Status,
Labels: i.Labels,
NetworkSettings: &types.GenericMgmtIPs{
Set: false,
},
Expand Down Expand Up @@ -480,12 +482,12 @@ func (c *DockerRuntime) DeleteContainer(ctx context.Context, container *types.Ge
force = true
}
}
log.Debugf("Removing container: %s", container.Names[0])
log.Debugf("Removing container: %s", strings.TrimLeft(container.Names[0], "/"))
err = c.Client.ContainerRemove(ctx, container.ID, dockerTypes.ContainerRemoveOptions{Force: force})
if err != nil {
return err
}
log.Infof("Removed container: %s", container.Names[0])
log.Infof("Removed container: %s", strings.TrimLeft(container.Names[0], "/"))
return nil
}

Expand Down
6 changes: 5 additions & 1 deletion tests/01-smoke/04-generate.robot
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ Verify nodes

*** Keywords ***
Cleanup
Run sudo containerlab destroy -t ${CURDIR}/${lab-name}.clab.yml --cleanup
${rc} ${output} = Run And Return Rc And Output
... sudo containerlab destroy -t ${lab-name}.clab.yml --cleanup
Log ${output}
Should Be Equal As Integers ${rc} 0
OperatingSystem.Remove File ${lab-name}.clab.yml
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (node *Node) GenerateConfig(dst, defaultTemplatePath string) error {
type GenericContainer struct {
Names []string
ID string
ShortID string // trimmed ID for display purposes
Image string
State string
Status string
Expand Down

0 comments on commit 81a7b91

Please sign in to comment.