Skip to content

Commit

Permalink
Fix namespace flag parsing for podman build
Browse files Browse the repository at this point in the history
The namespace options for pid,ipc,uts were completely ignored.
The network namespace did not accept `none`.

This commit fixes these issues simply by calling `parse.NamespaceOptions`
from buildah instead of implementing our own logic.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Paul Holzinger committed Nov 12, 2020
1 parent 79f5aed commit eab0905
Showing 1 changed file with 1 addition and 38 deletions.
39 changes: 1 addition & 38 deletions cmd/podman/images/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/containers/podman/v2/cmd/podman/utils"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/docker/go-units"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -315,22 +314,11 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil
}
}

nsValues, err := getNsValues(flags)
nsValues, networkPolicy, err := parse.NamespaceOptions(c)
if err != nil {
return nil, err
}

networkPolicy := buildah.NetworkDefault
for _, ns := range nsValues {
if ns.Name == "none" {
networkPolicy = buildah.NetworkDisabled
break
} else if !filepath.IsAbs(ns.Path) {
networkPolicy = buildah.NetworkEnabled
break
}
}

// `buildah bud --layers=false` acts like `docker build --squash` does.
// That is all of the new layers created during the build process are
// condensed into one, any layers present prior to this build are retained
Expand Down Expand Up @@ -451,28 +439,3 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *buil

return &entities.BuildOptions{BuildOptions: opts}, nil
}

func getNsValues(flags *buildFlagsWrapper) ([]buildah.NamespaceOption, error) {
var ret []buildah.NamespaceOption
if flags.Network != "" {
switch {
case flags.Network == "host":
ret = append(ret, buildah.NamespaceOption{
Name: string(specs.NetworkNamespace),
Host: true,
})
case flags.Network == "container":
ret = append(ret, buildah.NamespaceOption{
Name: string(specs.NetworkNamespace),
})
case flags.Network[0] == '/':
ret = append(ret, buildah.NamespaceOption{
Name: string(specs.NetworkNamespace),
Path: flags.Network,
})
default:
return nil, errors.Errorf("unsupported configuration network=%s", flags.Network)
}
}
return ret, nil
}

0 comments on commit eab0905

Please sign in to comment.