[lxc-devel] [crio-lxc/master] create.go: only use rootfs.managed if it is supported by the api

hallyn on Github lxc-bot at linuxcontainers.org
Fri Apr 19 04:59:48 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 410 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190418/c3058dc0/attachment.bin>
-------------- next part --------------
From dd066fec24a03f6890c7bef5d29e12f16c8d81ca Mon Sep 17 00:00:00 2001
From: Serge Hallyn <shallyn at cisco.com>
Date: Thu, 18 Apr 2019 20:56:06 -0700
Subject: [PATCH] create.go: only use rootfs.managed if it is supported by the
 api

It's a pretty new flag, and not yet available in bionic.

Signed-off-by: Serge Hallyn <shallyn at cisco.com>
---
 cmd/create.go | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/cmd/create.go b/cmd/create.go
index c867ef2..cbf867e 100644
--- a/cmd/create.go
+++ b/cmd/create.go
@@ -100,6 +100,17 @@ func doCreate(ctx *cli.Context) error {
 	return nil
 }
 
+func lxcApiHasKey(c *lxc.Container, key string) bool {
+	keys := c.ConfigKeys()
+	fmt.Printf("XXX keys are %v\n", keys)
+	for _, k := range keys {
+		if k == key {
+			return true
+		}
+	}
+	return false
+}
+
 func configureContainer(ctx *cli.Context, c *lxc.Container, spec *specs.Spec) error {
 	if ctx.Bool("debug") {
 		c.SetVerbosity(lxc.Verbose)
@@ -114,8 +125,10 @@ func configureContainer(ctx *cli.Context, c *lxc.Container, spec *specs.Spec) er
 	if err := c.SetConfigItem("lxc.rootfs.path", spec.Root.Path); err != nil {
 		return errors.Wrapf(err, "failed to set rootfs: '%s'", spec.Root.Path)
 	}
-	if err := c.SetConfigItem("lxc.rootfs.managed", "0"); err != nil {
-		return errors.Wrap(err, "failed to set rootfs.managed to 0")
+	if lxcApiHasKey(c, "lxc.rootfs.managed") {
+		if err := c.SetConfigItem("lxc.rootfs.managed", "0"); err != nil {
+			return errors.Wrap(err, "failed to set rootfs.managed to 0")
+		}
 	}
 
 	for _, envVar := range spec.Process.Env {


More information about the lxc-devel mailing list