Skip to content

Commit

Permalink
Isolation strings, should match user input
Browse files Browse the repository at this point in the history
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 <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Feb 23, 2021
1 parent 72ef182 commit 1bcf06d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Expand Up @@ -11,7 +11,6 @@ linters:
disable:
# All these break for one reason or another
- dupl
- funlen
- gochecknoglobals
- gochecknoinits
- goconst
Expand Down
10 changes: 4 additions & 6 deletions define/isolation.go
Expand Up @@ -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)
}
35 changes: 35 additions & 0 deletions 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)
}
}
}
2 changes: 1 addition & 1 deletion pkg/parse/parse.go
Expand Up @@ -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
Expand Down

0 comments on commit 1bcf06d

Please sign in to comment.