[lxc-devel] [crio-lxc/master] Miscellaneous fixes
hallyn on Github
lxc-bot at linuxcontainers.org
Sat Apr 20 06:06:06 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 404 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190419/9c165e6b/attachment-0001.bin>
-------------- next part --------------
From 9035ad0e22b7180664ab993ab5bd17dc40a8b89c Mon Sep 17 00:00:00 2001
From: Serge Hallyn <shallyn at cisco.com>
Date: Fri, 19 Apr 2019 21:09:13 -0500
Subject: [PATCH 1/4] manual test: use alpine instead of centos
Signed-off-by: Serge Hallyn <shallyn at cisco.com>
---
test/manual.bats | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/test/manual.bats b/test/manual.bats
index 7ce34a9..7dc4ecf 100644
--- a/test/manual.bats
+++ b/test/manual.bats
@@ -2,8 +2,8 @@ load helpers
function setup() {
make_tempdir
- skopeo --insecure-policy copy docker://centos:latest oci:$ROOT_DIR/test/oci-cache:centos
- umoci unpack --image "$ROOT_DIR/test/oci-cache:centos" "$TEMP_DIR/dest"
+ skopeo --insecure-policy copy docker://alpine:latest oci:$ROOT_DIR/test/oci-cache:alpine
+ umoci unpack --image "$ROOT_DIR/test/oci-cache:alpine" "$TEMP_DIR/dest"
sed -i -e "s?rootfs?$TEMP_DIR/dest/rootfs?" "$TEMP_DIR/dest/config.json"
}
@@ -12,6 +12,6 @@ function teardown() {
}
@test "manual invocation" {
- crio-lxc --debug --log-level trace --log-file "$TEMP_DIR/log" create --bundle "$TEMP_DIR/dest" centos
- crio-lxc --debug --log-level trace --log-file "$TEMP_DIR/log" start centos
+ crio-lxc --debug --log-level trace --log-file "$TEMP_DIR/log" create --bundle "$TEMP_DIR/dest" alpine
+ crio-lxc --debug --log-level trace --log-file "$TEMP_DIR/log" start alpine
}
From 80f09178de89c0f637fd8605c97d529c2e5cdec5 Mon Sep 17 00:00:00 2001
From: Serge Hallyn <shallyn at cisco.com>
Date: Sat, 20 Apr 2019 00:37:03 -0500
Subject: [PATCH 2/4] update README to show some prereqs to running the tests
---
README.md | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/README.md b/README.md
index bfa2b23..7aaaa5d 100644
--- a/README.md
+++ b/README.md
@@ -19,3 +19,30 @@ Note that you must have a new enough liblxc, one which supports the
"lxc.rootfs.managed" key. 3.0.3 is not new enough, 3.1 is. On Ubuntu,
you can upgrade using the ubuntu-lxc/lxc-git-master PPA. Arch and
OpenSUSE tumbleweed should be uptodate.
+
+## Tests
+
+To run the 'basic' test, you'll need to build cri-o.
+
+```
+mkdir ~/packages
+cd packages
+git clone https://github.com/kubernetes-sigs/cri-o
+cd cri-o
+make
+```
+
+You'll also need crictl. Download the tarball, extract it, and
+copy crictl to /usr/bin:
+
+```
+wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.13.0/crictl-v1.14.0-linux-amd64.tar.gz
+tar zxf crictl-v1.14.0-linux-amd64.tar.gz
+sudo cp crictl /usr/bin
+```
+
+You'll also need conntrack installed:
+
+```
+apt install conntrack
+```
From 581c2e8038709c90743d45eb54662727d64a3737 Mon Sep 17 00:00:00 2001
From: Serge Hallyn <shallyn at cisco.com>
Date: Sat, 20 Apr 2019 00:37:36 -0500
Subject: [PATCH 3/4] delete: accept --force argument (critool passes it)
---
cmd/delete.go | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/cmd/delete.go b/cmd/delete.go
index 506412d..c743cfd 100644
--- a/cmd/delete.go
+++ b/cmd/delete.go
@@ -20,7 +20,12 @@ var deleteCmd = cli.Command{
<containerID> is the ID of the container to delete
`,
- Flags: []cli.Flag{},
+ Flags: []cli.Flag{
+ cli.BoolFlag{
+ Name: "force",
+ Usage: "force deletion",
+ },
+ },
}
func doDelete(ctx *cli.Context) error {
@@ -49,8 +54,9 @@ func doDelete(ctx *cli.Context) error {
}
+ force := ctx.Bool("force")
if c.Running() {
- if checkHackyPreStart(c) == "started" {
+ if checkHackyPreStart(c) == "started" && !force {
return fmt.Errorf("container '%s' is running, cannot delete.", containerID)
}
if err := c.Stop(); err != nil {
From 44e584760de603bdeba47e6b1345595710a0513f Mon Sep 17 00:00:00 2001
From: Serge Hallyn <shallyn at cisco.com>
Date: Sat, 20 Apr 2019 00:38:08 -0500
Subject: [PATCH 4/4] create: ensure sh, stat and tee are there for our fifo
script
---
cmd/create.go | 30 ++++++++++++++++++++++++++++++
cmd/utils.go | 11 +++++++++++
2 files changed, 41 insertions(+)
diff --git a/cmd/create.go b/cmd/create.go
index 51a9949..1b9d73d 100644
--- a/cmd/create.go
+++ b/cmd/create.go
@@ -42,6 +42,34 @@ var createCmd = cli.Command{
},
}
+func ensureShell(rootfs string) {
+ shPath := filepath.Join(rootfs, "bin/sh")
+ if exists, _ := pathExists(shPath); exists {
+ return
+ }
+ var err error
+ err = RunCommand("mkdir", filepath.Join(rootfs, "bin"))
+ if err != nil {
+ fmt.Printf("Failed doing mkdir: %v\n", err)
+ }
+ err = RunCommand("cp", "/bin/busybox", filepath.Join(rootfs, "bin/"))
+ if err != nil {
+ fmt.Printf("Failed copying busybox: %v\n", err)
+ }
+ err = RunCommand("ln", filepath.Join(rootfs, "bin/busybox"), filepath.Join(rootfs, "bin/stat"))
+ if err != nil {
+ fmt.Printf("Failed linking stat: %v\n", err)
+ }
+ err = RunCommand("ln", filepath.Join(rootfs, "bin/busybox"), filepath.Join(rootfs, "bin/sh"))
+ if err != nil {
+ fmt.Printf("Failed linking sh: %v\n", err)
+ }
+ err = RunCommand("ln", filepath.Join(rootfs, "bin/busybox"), filepath.Join(rootfs, "bin/tee"))
+ if err != nil {
+ fmt.Printf("Failed linking tee : %v\n", err)
+ }
+}
+
func emitFifoWaiter(file string) error {
fifoWaiter := fmt.Sprintf(`#!/bin/sh
stat /syncfifo
@@ -143,6 +171,8 @@ func configureContainer(ctx *cli.Context, c *lxc.Container, spec *specs.Spec) er
return errors.Wrapf(err, "couldn't write wrapper init")
}
+ ensureShell(spec.Root.Path)
+
if err := c.SetConfigItem("lxc.init.cwd", spec.Process.Cwd); err != nil {
return errors.Wrap(err, "failed to set CWD")
}
diff --git a/cmd/utils.go b/cmd/utils.go
index ca42b7d..a83bf13 100644
--- a/cmd/utils.go
+++ b/cmd/utils.go
@@ -4,7 +4,9 @@ import (
"encoding/json"
"fmt"
"os"
+ "os/exec"
"path/filepath"
+ "strings"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
@@ -75,3 +77,12 @@ func containerExists(containerID string) (bool, error) {
return configExists, nil
}
+
+func RunCommand(args ...string) error {
+ cmd := exec.Command(args[0], args[1:]...)
+ output, err := cmd.CombinedOutput()
+ if err != nil {
+ return errors.Errorf("%s: %s: %s", strings.Join(args, " "), err, string(output))
+ }
+ return nil
+}
More information about the lxc-devel
mailing list