From 1bcf06d5aa15b874e7e8949afa10fc962da77a46 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 23 Feb 2021 07:27:24 -0500 Subject: [PATCH] Isolation strings, should match user input When we parse isolation we expect users to input chroot, oci, rootless. So when we translate the constants back to strings, we should use the same values. These human names need to be passed over the podman-remote build bindings, so we need to make them match. Also docker describes an isolation of "default", which we should also handle for potential scripts. Signed-off-by: Daniel J Walsh --- .golangci.yml | 1 - define/isolation.go | 10 ++++------ define/isolation_test.go | 35 +++++++++++++++++++++++++++++++++++ pkg/parse/parse.go | 2 +- 4 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 define/isolation_test.go diff --git a/.golangci.yml b/.golangci.yml index 0c7e3100793..f3a5b8b3fc8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,7 +11,6 @@ linters: disable: # All these break for one reason or another - dupl - - funlen - gochecknoglobals - gochecknoinits - goconst diff --git a/define/isolation.go b/define/isolation.go index 5bc9cfff72c..53bea85fdb0 100644 --- a/define/isolation.go +++ b/define/isolation.go @@ -21,14 +21,12 @@ const ( // String converts a Isolation into a string. func (i Isolation) String() string { switch i { - case IsolationDefault: - return "IsolationDefault" - case IsolationOCI: - return "IsolationOCI" + case IsolationDefault, IsolationOCI: + return "oci" case IsolationChroot: - return "IsolationChroot" + return "chroot" case IsolationOCIRootless: - return "IsolationOCIRootless" + return "rootless" } return fmt.Sprintf("unrecognized isolation type %d", i) } diff --git a/define/isolation_test.go b/define/isolation_test.go new file mode 100644 index 00000000000..eaeefbba618 --- /dev/null +++ b/define/isolation_test.go @@ -0,0 +1,35 @@ +package define + +import ( + "testing" + + "github.com/containers/buildah/pkg/parse" + "github.com/containers/storage/pkg/unshare" +) + +func TestIsolation(t *testing.T) { + isolations := []string{"", "default", "oci", "chroot", "rootless"} + for _, i := range isolations { + isolation, err := parse.IsolationOption(i) + if err != nil { + t.Errorf("Isolation %q not supported.", i) + } + var expected string + switch i { + case "": + if unshare.IsRootless() { + expected = "rootless" + } else { + expected = "oci" + } + case "default": + expected = "oci" + default: + expected = i + } + + if isolation.String() != expected { + t.Errorf("Isolation %q not equal to user input %q.", isolation.String(), expected) + } + } +} diff --git a/pkg/parse/parse.go b/pkg/parse/parse.go index bdab1f6fca0..9497ca4b6b4 100644 --- a/pkg/parse/parse.go +++ b/pkg/parse/parse.go @@ -959,7 +959,7 @@ func defaultIsolation() (define.Isolation, error) { func IsolationOption(isolation string) (define.Isolation, error) { if isolation != "" { switch strings.ToLower(isolation) { - case "oci": + case "oci", "default": return define.IsolationOCI, nil case "rootless": return define.IsolationOCIRootless, nil