summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/api/handlers/compat/containers.go15
-rw-r--r--pkg/api/handlers/compat/images_build.go14
-rw-r--r--pkg/api/handlers/compat/version.go9
-rw-r--r--pkg/api/handlers/utils/handler.go45
-rw-r--r--pkg/api/handlers/utils/handler_test.go5
-rw-r--r--pkg/api/server/handler_api.go7
-rw-r--r--pkg/bindings/bindings.go26
-rw-r--r--pkg/bindings/connection.go10
-rw-r--r--pkg/bindings/test/attach_test.go2
-rw-r--r--pkg/bindings/test/common_test.go4
-rw-r--r--pkg/bindings/test/containers_test.go90
-rw-r--r--pkg/bindings/test/exec_test.go5
-rw-r--r--pkg/bindings/test/images_test.go2
-rw-r--r--pkg/bindings/test/info_test.go6
-rw-r--r--pkg/bindings/test/pods_test.go6
-rw-r--r--pkg/bindings/test/system_test.go17
-rw-r--r--pkg/copy/fileinfo.go11
-rw-r--r--pkg/domain/entities/containers.go3
-rw-r--r--pkg/domain/infra/abi/archive.go163
-rw-r--r--pkg/domain/infra/abi/containers_stat.go127
-rw-r--r--pkg/domain/infra/abi/images.go5
-rw-r--r--pkg/domain/infra/abi/network.go10
-rw-r--r--pkg/specgen/generate/oci.go28
23 files changed, 161 insertions, 449 deletions
diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go
index 1e84888af..d26bb50f4 100644
--- a/pkg/api/handlers/compat/containers.go
+++ b/pkg/api/handlers/compat/containers.go
@@ -321,6 +321,19 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
Type: portMapping.Protocol,
}
}
+ inspect, err := l.Inspect(false)
+ if err != nil {
+ return nil, err
+ }
+
+ n, err := json.Marshal(inspect.NetworkSettings)
+ if err != nil {
+ return nil, err
+ }
+ networkSettings := types.SummaryNetworkSettings{}
+ if err := json.Unmarshal(n, &networkSettings); err != nil {
+ return nil, err
+ }
return &handlers.Container{Container: types.Container{
ID: l.ID(),
@@ -339,7 +352,7 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error
NetworkMode string `json:",omitempty"`
}{
"host"},
- NetworkSettings: nil,
+ NetworkSettings: &networkSettings,
Mounts: nil,
},
ContainerCreateConfig: types.ContainerCreateConfig{},
diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go
index 009fcf7e8..e06f93b89 100644
--- a/pkg/api/handlers/compat/images_build.go
+++ b/pkg/api/handlers/compat/images_build.go
@@ -222,9 +222,17 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
// convert label formats
var labels = []string{}
if _, found := r.URL.Query()["labels"]; found {
- if err := json.Unmarshal([]byte(query.Labels), &labels); err != nil {
- utils.BadRequest(w, "labels", query.Labels, err)
- return
+ makeLabels := make(map[string]string)
+ err := json.Unmarshal([]byte(query.Labels), &makeLabels)
+ if err == nil {
+ for k, v := range makeLabels {
+ labels = append(labels, k+"="+v)
+ }
+ } else {
+ if err := json.Unmarshal([]byte(query.Labels), &labels); err != nil {
+ utils.BadRequest(w, "labels", query.Labels, err)
+ return
+ }
}
}
jobs := 1
diff --git a/pkg/api/handlers/compat/version.go b/pkg/api/handlers/compat/version.go
index d90a892c1..fae147440 100644
--- a/pkg/api/handlers/compat/version.go
+++ b/pkg/api/handlers/compat/version.go
@@ -10,6 +10,7 @@ import (
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/api/handlers/utils"
"github.com/containers/podman/v3/pkg/domain/entities"
+ "github.com/containers/podman/v3/version"
docker "github.com/docker/docker/api/types"
"github.com/pkg/errors"
)
@@ -35,20 +36,20 @@ func VersionHandler(w http.ResponseWriter, r *http.Request) {
Name: "Podman Engine",
Version: versionInfo.Version,
Details: map[string]string{
- "APIVersion": utils.APIVersion[utils.LibpodTree][utils.CurrentAPIVersion].String(),
+ "APIVersion": version.APIVersion[version.Libpod][version.CurrentAPI].String(),
"Arch": goRuntime.GOARCH,
"BuildTime": time.Unix(versionInfo.Built, 0).Format(time.RFC3339),
"Experimental": "true",
"GitCommit": versionInfo.GitCommit,
"GoVersion": versionInfo.GoVersion,
"KernelVersion": infoData.Host.Kernel,
- "MinAPIVersion": utils.APIVersion[utils.LibpodTree][utils.MinimalAPIVersion].String(),
+ "MinAPIVersion": version.APIVersion[version.Libpod][version.MinimalAPI].String(),
"Os": goRuntime.GOOS,
},
}}
- apiVersion := utils.APIVersion[utils.CompatTree][utils.CurrentAPIVersion]
- minVersion := utils.APIVersion[utils.CompatTree][utils.MinimalAPIVersion]
+ apiVersion := version.APIVersion[version.Compat][version.CurrentAPI]
+ minVersion := version.APIVersion[version.Compat][version.MinimalAPI]
utils.WriteResponse(w, http.StatusOK, entities.ComponentVersion{
Version: docker.Version{
diff --git a/pkg/api/handlers/utils/handler.go b/pkg/api/handlers/utils/handler.go
index b3c674788..7625f9546 100644
--- a/pkg/api/handlers/utils/handler.go
+++ b/pkg/api/handlers/utils/handler.go
@@ -10,49 +10,14 @@ import (
"unsafe"
"github.com/blang/semver"
+ "github.com/containers/podman/v3/version"
"github.com/gorilla/mux"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
-type (
- // VersionTree determines which API endpoint tree for version
- VersionTree int
- // VersionLevel determines which API level, current or something from the past
- VersionLevel int
-)
-
-const (
- // LibpodTree supports Libpod endpoints
- LibpodTree = VersionTree(iota)
- // CompatTree supports Libpod endpoints
- CompatTree
-
- // CurrentAPIVersion announces what is the current API level
- CurrentAPIVersion = VersionLevel(iota)
- // MinimalAPIVersion announces what is the oldest API level supported
- MinimalAPIVersion
-)
-
var (
- // See https://docs.docker.com/engine/api/v1.40/
- // libpod compat handlers are expected to honor docker API versions
-
- // APIVersion provides the current and minimal API versions for compat and libpod endpoint trees
- // Note: GET|HEAD /_ping is never versioned and provides the API-Version and Libpod-API-Version headers to allow
- // clients to shop for the Version they wish to support
- APIVersion = map[VersionTree]map[VersionLevel]semver.Version{
- LibpodTree: {
- CurrentAPIVersion: semver.MustParse("3.0.0"),
- MinimalAPIVersion: semver.MustParse("3.0.0"),
- },
- CompatTree: {
- CurrentAPIVersion: semver.MustParse("1.40.0"),
- MinimalAPIVersion: semver.MustParse("1.24.0"),
- },
- }
-
// ErrVersionNotGiven returned when version not given by client
ErrVersionNotGiven = errors.New("version not given in URL path")
// ErrVersionNotSupported returned when given version is too old
@@ -98,14 +63,14 @@ func SupportedVersion(r *http.Request, condition string) (semver.Version, error)
// SupportedVersionWithDefaults validates that the version provided by client valid is supported by server
// minimal API version <= client path version <= maximum API version focused on the endpoint tree from URL
func SupportedVersionWithDefaults(r *http.Request) (semver.Version, error) {
- tree := CompatTree
+ tree := version.Compat
if IsLibpodRequest(r) {
- tree = LibpodTree
+ tree = version.Libpod
}
return SupportedVersion(r,
- fmt.Sprintf(">=%s <=%s", APIVersion[tree][MinimalAPIVersion].String(),
- APIVersion[tree][CurrentAPIVersion].String()))
+ fmt.Sprintf(">=%s <=%s", version.APIVersion[tree][version.MinimalAPI].String(),
+ version.APIVersion[tree][version.CurrentAPI].String()))
}
// WriteResponse encodes the given value as JSON or string and renders it for http client
diff --git a/pkg/api/handlers/utils/handler_test.go b/pkg/api/handlers/utils/handler_test.go
index d9fd22b80..18a1d2678 100644
--- a/pkg/api/handlers/utils/handler_test.go
+++ b/pkg/api/handlers/utils/handler_test.go
@@ -7,17 +7,18 @@ import (
"net/http/httptest"
"testing"
+ "github.com/containers/podman/v3/version"
"github.com/gorilla/mux"
)
func TestSupportedVersion(t *testing.T) {
req, err := http.NewRequest("GET",
- fmt.Sprintf("/v%s/libpod/testing/versions", APIVersion[LibpodTree][CurrentAPIVersion]),
+ fmt.Sprintf("/v%s/libpod/testing/versions", version.APIVersion[version.Libpod][version.CurrentAPI]),
nil)
if err != nil {
t.Fatal(err)
}
- req = mux.SetURLVars(req, map[string]string{"version": APIVersion[LibpodTree][CurrentAPIVersion].String()})
+ req = mux.SetURLVars(req, map[string]string{"version": version.APIVersion[version.Libpod][version.CurrentAPI].String()})
rr := httptest.NewRecorder()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
diff --git a/pkg/api/server/handler_api.go b/pkg/api/server/handler_api.go
index e7bf94fc6..28b8706a8 100644
--- a/pkg/api/server/handler_api.go
+++ b/pkg/api/server/handler_api.go
@@ -8,6 +8,7 @@ import (
"github.com/containers/podman/v3/pkg/api/handlers/utils"
"github.com/containers/podman/v3/pkg/auth"
+ "github.com/containers/podman/v3/version"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
)
@@ -55,10 +56,10 @@ func (s *APIServer) APIHandler(h http.HandlerFunc) http.HandlerFunc {
c = context.WithValue(c, "idletracker", s.idleTracker) // nolint
r = r.WithContext(c)
- cv := utils.APIVersion[utils.CompatTree][utils.CurrentAPIVersion]
+ cv := version.APIVersion[version.Compat][version.CurrentAPI]
w.Header().Set("API-Version", fmt.Sprintf("%d.%d", cv.Major, cv.Minor))
- lv := utils.APIVersion[utils.LibpodTree][utils.CurrentAPIVersion].String()
+ lv := version.APIVersion[version.Libpod][version.CurrentAPI].String()
w.Header().Set("Libpod-API-Version", lv)
w.Header().Set("Server", "Libpod/"+lv+" ("+runtime.GOOS+")")
@@ -72,5 +73,5 @@ func (s *APIServer) APIHandler(h http.HandlerFunc) http.HandlerFunc {
// VersionedPath prepends the version parsing code
// any handler may override this default when registering URL(s)
func VersionedPath(p string) string {
- return "/v{version:[0-9][0-9.]*}" + p
+ return "/v{version:[0-9][0-9A-Za-z.-]*}" + p
}
diff --git a/pkg/bindings/bindings.go b/pkg/bindings/bindings.go
deleted file mode 100644
index 14f306910..000000000
--- a/pkg/bindings/bindings.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Package bindings provides golang-based access
-// to the Podman REST API. Users can then interact with API endpoints
-// to manage containers, images, pods, etc.
-//
-// This package exposes a series of methods that allow users to firstly
-// create their connection with the API endpoints. Once the connection
-// is established, users can then manage the Podman container runtime.
-package bindings
-
-import (
- "github.com/blang/semver"
-)
-
-var (
- // PTrue is a convenience variable that can be used in bindings where
- // a pointer to a bool (optional parameter) is required.
- pTrue = true
- PTrue = &pTrue
- // PFalse is a convenience variable that can be used in bindings where
- // a pointer to a bool (optional parameter) is required.
- pFalse = false
- PFalse = &pFalse
-
- // APIVersion - podman will fail to run if this value is wrong
- APIVersion = semver.MustParse("2.0.0")
-)
diff --git a/pkg/bindings/connection.go b/pkg/bindings/connection.go
index ad16498d5..21a8e7a8b 100644
--- a/pkg/bindings/connection.go
+++ b/pkg/bindings/connection.go
@@ -14,6 +14,7 @@ import (
"github.com/blang/semver"
"github.com/containers/podman/v3/pkg/terminal"
+ "github.com/containers/podman/v3/version"
jsoniter "github.com/json-iterator/go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -25,7 +26,7 @@ var (
BasePath = &url.URL{
Scheme: "http",
Host: "d",
- Path: "/v" + APIVersion.String() + "/libpod",
+ Path: "/v" + version.APIVersion[version.Libpod][version.CurrentAPI].String() + "/libpod",
}
)
@@ -168,15 +169,16 @@ func pingNewConnection(ctx context.Context) error {
return err
}
- switch APIVersion.Compare(versionSrv) {
+ switch version.APIVersion[version.Libpod][version.MinimalAPI].Compare(versionSrv) {
case -1, 0:
// Server's job when Client version is equal or older
return nil
case 1:
- return errors.Errorf("server API version is too old. Client %q server %q", APIVersion.String(), versionSrv.String())
+ return errors.Errorf("server API version is too old. Client %q server %q",
+ version.APIVersion[version.Libpod][version.MinimalAPI].String(), versionSrv.String())
}
}
- return errors.Errorf("ping response was %q", response.StatusCode)
+ return errors.Errorf("ping response was %d", response.StatusCode)
}
func sshClient(_url *url.URL, secure bool, passPhrase string, identity string) (Connection, error) {
diff --git a/pkg/bindings/test/attach_test.go b/pkg/bindings/test/attach_test.go
index 16090e104..fbdf18d44 100644
--- a/pkg/bindings/test/attach_test.go
+++ b/pkg/bindings/test/attach_test.go
@@ -35,7 +35,7 @@ var _ = Describe("Podman containers attach", func() {
It("can run top in container", func() {
name := "TopAttachTest"
- id, err := bt.RunTopContainer(&name, nil, nil)
+ id, err := bt.RunTopContainer(&name, nil)
Expect(err).ShouldNot(HaveOccurred())
tickTock := time.NewTimer(2 * time.Second)
diff --git a/pkg/bindings/test/common_test.go b/pkg/bindings/test/common_test.go
index 588f38930..9bac4b620 100644
--- a/pkg/bindings/test/common_test.go
+++ b/pkg/bindings/test/common_test.go
@@ -188,14 +188,14 @@ func (b *bindingTest) restoreImageFromCache(i testImage) {
// Run a container within or without a pod
// and add or append the alpine image to it
-func (b *bindingTest) RunTopContainer(containerName *string, insidePod *bool, podName *string) (string, error) {
+func (b *bindingTest) RunTopContainer(containerName *string, podName *string) (string, error) {
s := specgen.NewSpecGenerator(alpine.name, false)
s.Terminal = false
s.Command = []string{"/usr/bin/top"}
if containerName != nil {
s.Name = *containerName
}
- if insidePod != nil && podName != nil {
+ if podName != nil {
s.Pod = *podName
}
ctr, err := containers.CreateWithSpec(b.conn, s, nil)
diff --git a/pkg/bindings/test/containers_test.go b/pkg/bindings/test/containers_test.go
index f2ab197ce..b0ddc7862 100644
--- a/pkg/bindings/test/containers_test.go
+++ b/pkg/bindings/test/containers_test.go
@@ -55,7 +55,7 @@ var _ = Describe("Podman containers ", func() {
It("podman pause a running container by name", func() {
// Pausing by name should work
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -69,7 +69,7 @@ var _ = Describe("Podman containers ", func() {
It("podman pause a running container by id", func() {
// Pausing by id should work
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, cid, nil)
Expect(err).To(BeNil())
@@ -83,7 +83,7 @@ var _ = Describe("Podman containers ", func() {
It("podman unpause a running container by name", func() {
// Unpausing by name should work
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -99,7 +99,7 @@ var _ = Describe("Podman containers ", func() {
It("podman unpause a running container by ID", func() {
// Unpausing by ID should work
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Pause by name
err = containers.Pause(bt.conn, name, nil)
@@ -118,7 +118,7 @@ var _ = Describe("Podman containers ", func() {
It("podman pause a paused container by name", func() {
// Pausing a paused container by name should fail
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -131,7 +131,7 @@ var _ = Describe("Podman containers ", func() {
It("podman pause a paused container by id", func() {
// Pausing a paused container by id should fail
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, cid, nil)
Expect(err).To(BeNil())
@@ -144,7 +144,7 @@ var _ = Describe("Podman containers ", func() {
It("podman pause a stopped container by name", func() {
// Pausing a stopped container by name should fail
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -157,7 +157,7 @@ var _ = Describe("Podman containers ", func() {
It("podman pause a stopped container by id", func() {
// Pausing a stopped container by id should fail
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, cid, nil)
Expect(err).To(BeNil())
@@ -170,7 +170,7 @@ var _ = Describe("Podman containers ", func() {
It("podman remove a paused container by id without force", func() {
// Removing a paused container without force should fail
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, cid, nil)
Expect(err).To(BeNil())
@@ -183,7 +183,7 @@ var _ = Describe("Podman containers ", func() {
It("podman remove a paused container by id with force", func() {
// Removing a paused container with force should work
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, cid, nil)
Expect(err).To(BeNil())
@@ -194,7 +194,7 @@ var _ = Describe("Podman containers ", func() {
It("podman stop a paused container by name", func() {
// Stopping a paused container by name should fail
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -207,7 +207,7 @@ var _ = Describe("Podman containers ", func() {
It("podman stop a paused container by id", func() {
// Stopping a paused container by id should fail
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, cid, nil)
Expect(err).To(BeNil())
@@ -220,7 +220,7 @@ var _ = Describe("Podman containers ", func() {
It("podman stop a running container by name", func() {
// Stopping a running container by name should work
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -234,7 +234,7 @@ var _ = Describe("Podman containers ", func() {
It("podman stop a running container by ID", func() {
// Stopping a running container by ID should work
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, cid, nil)
Expect(err).To(BeNil())
@@ -256,7 +256,7 @@ var _ = Describe("Podman containers ", func() {
Expect(code).To(BeNumerically("==", http.StatusNotFound))
errChan := make(chan error)
- _, err = bt.RunTopContainer(&name, nil, nil)
+ _, err = bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
go func() {
exitCode, err = containers.Wait(bt.conn, name, nil)
@@ -278,7 +278,7 @@ var _ = Describe("Podman containers ", func() {
running = define.ContainerStateRunning
)
errChan := make(chan error)
- _, err := bt.RunTopContainer(&name, nil, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
go func() {
exitCode, err = containers.Wait(bt.conn, name, new(containers.WaitOptions).WithCondition([]define.ContainerStatus{pause}))
@@ -317,7 +317,7 @@ var _ = Describe("Podman containers ", func() {
// a container that has no healthcheck should be a 409
var name = "top"
- bt.RunTopContainer(&name, bindings.PFalse, nil)
+ bt.RunTopContainer(&name, nil)
_, err = containers.RunHealthCheck(bt.conn, name, nil)
Expect(err).ToNot(BeNil())
code, _ = bindings.CheckResponseCode(err)
@@ -376,7 +376,7 @@ var _ = Describe("Podman containers ", func() {
It("podman top", func() {
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// By name
@@ -414,7 +414,7 @@ var _ = Describe("Podman containers ", func() {
It("podman container exists in local storage by name", func() {
// Container existence check by name should work
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
containerExists, err := containers.Exists(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -424,7 +424,7 @@ var _ = Describe("Podman containers ", func() {
It("podman container exists in local storage by ID", func() {
// Container existence check by ID should work
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
containerExists, err := containers.Exists(bt.conn, cid, nil)
Expect(err).To(BeNil())
@@ -434,7 +434,7 @@ var _ = Describe("Podman containers ", func() {
It("podman container exists in local storage by short ID", func() {
// Container existence check by short ID should work
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
containerExists, err := containers.Exists(bt.conn, cid[0:12], nil)
Expect(err).To(BeNil())
@@ -452,7 +452,7 @@ var _ = Describe("Podman containers ", func() {
It("podman kill a running container by name with SIGINT", func() {
// Killing a running container should work
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Kill(bt.conn, name, new(containers.KillOptions).WithSignal("SIGINT"))
Expect(err).To(BeNil())
@@ -463,7 +463,7 @@ var _ = Describe("Podman containers ", func() {
It("podman kill a running container by ID with SIGTERM", func() {
// Killing a running container by ID should work
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Kill(bt.conn, cid, new(containers.KillOptions).WithSignal("SIGTERM"))
Expect(err).To(BeNil())
@@ -474,7 +474,7 @@ var _ = Describe("Podman containers ", func() {
It("podman kill a running container by ID with SIGKILL", func() {
// Killing a running container by ID with TERM should work
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Kill(bt.conn, cid, new(containers.KillOptions).WithSignal("SIGKILL"))
Expect(err).To(BeNil())
@@ -483,7 +483,7 @@ var _ = Describe("Podman containers ", func() {
It("podman kill a running container by bogus signal", func() {
//Killing a running container by bogus signal should fail
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Kill(bt.conn, cid, new(containers.KillOptions).WithSignal("foobar"))
Expect(err).ToNot(BeNil())
@@ -495,9 +495,9 @@ var _ = Describe("Podman containers ", func() {
// Killing latest container should work
var name1 = "first"
var name2 = "second"
- _, err := bt.RunTopContainer(&name1, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name1, nil)
Expect(err).To(BeNil())
- _, err = bt.RunTopContainer(&name2, bindings.PFalse, nil)
+ _, err = bt.RunTopContainer(&name2, nil)
Expect(err).To(BeNil())
containerLatestList, err := containers.List(bt.conn, new(containers.ListOptions).WithLast(1))
Expect(err).To(BeNil())
@@ -526,7 +526,7 @@ var _ = Describe("Podman containers ", func() {
It("podman prune stopped containers", func() {
// Start and stop a container to enter in exited state.
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -541,7 +541,7 @@ var _ = Describe("Podman containers ", func() {
It("podman prune stopped containers with filters", func() {
// Start and stop a container to enter in exited state.
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -575,7 +575,7 @@ var _ = Describe("Podman containers ", func() {
It("podman prune running containers", func() {
// Start the container.
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Check if the container is running.
@@ -598,7 +598,7 @@ var _ = Describe("Podman containers ", func() {
It("podman inspect running container", func() {
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Inspecting running container should succeed
_, err = containers.Inspect(bt.conn, name, nil)
@@ -607,7 +607,7 @@ var _ = Describe("Podman containers ", func() {
It("podman inspect stopped container", func() {
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -618,7 +618,7 @@ var _ = Describe("Podman containers ", func() {
It("podman inspect running container with size", func() {
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
_, err = containers.Inspect(bt.conn, name, new(containers.InspectOptions).WithSize(true))
Expect(err).To(BeNil())
@@ -626,7 +626,7 @@ var _ = Describe("Podman containers ", func() {
It("podman inspect stopped container with size", func() {
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -643,7 +643,7 @@ var _ = Describe("Podman containers ", func() {
It("podman remove running container by name", func() {
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
err = containers.Remove(bt.conn, name, nil)
@@ -654,7 +654,7 @@ var _ = Describe("Podman containers ", func() {
It("podman remove running container by ID", func() {
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
err = containers.Remove(bt.conn, cid, nil)
@@ -665,7 +665,7 @@ var _ = Describe("Podman containers ", func() {
It("podman forcibly remove running container by name", func() {
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
err = containers.Remove(bt.conn, name, new(containers.RemoveOptions).WithForce(true))
@@ -676,7 +676,7 @@ var _ = Describe("Podman containers ", func() {
It("podman forcibly remove running container by ID", func() {
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
err = containers.Remove(bt.conn, cid, new(containers.RemoveOptions).WithForce(true))
@@ -687,7 +687,7 @@ var _ = Describe("Podman containers ", func() {
It("podman remove running container and volume by name", func() {
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
err = containers.Remove(bt.conn, name, new(containers.RemoveOptions).WithVolumes(true))
@@ -698,7 +698,7 @@ var _ = Describe("Podman containers ", func() {
It("podman remove running container and volume by ID", func() {
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
err = containers.Remove(bt.conn, cid, new(containers.RemoveOptions).WithVolumes(true))
@@ -709,7 +709,7 @@ var _ = Describe("Podman containers ", func() {
It("podman forcibly remove running container and volume by name", func() {
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
err = containers.Remove(bt.conn, name, new(containers.RemoveOptions).WithVolumes(true).WithForce(true))
@@ -720,7 +720,7 @@ var _ = Describe("Podman containers ", func() {
It("podman forcibly remove running container and volume by ID", func() {
var name = "top"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
// Removing running container should fail
err = containers.Remove(bt.conn, cid, new(containers.RemoveOptions).WithForce(true).WithVolumes(true))
@@ -732,9 +732,9 @@ var _ = Describe("Podman containers ", func() {
It("List containers with filters", func() {
var name = "top"
var name2 = "top2"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
- _, err = bt.RunTopContainer(&name2, bindings.PFalse, nil)
+ _, err = bt.RunTopContainer(&name2, nil)
Expect(err).To(BeNil())
s := specgen.NewSpecGenerator(alpine.name, false)
s.Terminal = true
@@ -753,7 +753,7 @@ var _ = Describe("Podman containers ", func() {
podName := "testpod"
ctrName := "testctr"
bt.Podcreate(&podName)
- _, err := bt.RunTopContainer(&ctrName, bindings.PTrue, &podName)
+ _, err := bt.RunTopContainer(&ctrName, &podName)
Expect(err).To(BeNil())
lastNum := 1
diff --git a/pkg/bindings/test/exec_test.go b/pkg/bindings/test/exec_test.go
index 7a21be77f..c10452eaf 100644
--- a/pkg/bindings/test/exec_test.go
+++ b/pkg/bindings/test/exec_test.go
@@ -4,7 +4,6 @@ import (
"time"
"github.com/containers/podman/v3/pkg/api/handlers"
- "github.com/containers/podman/v3/pkg/bindings"
"github.com/containers/podman/v3/pkg/bindings/containers"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -33,7 +32,7 @@ var _ = Describe("Podman containers exec", func() {
It("Podman exec create makes an exec session", func() {
name := "testCtr"
- cid, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ cid, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
execConfig := new(handlers.ExecCreateConfig)
@@ -53,7 +52,7 @@ var _ = Describe("Podman containers exec", func() {
It("Podman exec create with bad command fails", func() {
name := "testCtr"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
execConfig := new(handlers.ExecCreateConfig)
diff --git a/pkg/bindings/test/images_test.go b/pkg/bindings/test/images_test.go
index db51d1e68..688bf049f 100644
--- a/pkg/bindings/test/images_test.go
+++ b/pkg/bindings/test/images_test.go
@@ -101,7 +101,7 @@ var _ = Describe("Podman images", func() {
// Start a container with alpine image
var top string = "top"
- _, err = bt.RunTopContainer(&top, bindings.PFalse, nil)
+ _, err = bt.RunTopContainer(&top, nil)
Expect(err).To(BeNil())
// we should now have a container called "top" running
containerResponse, err := containers.Inspect(bt.conn, "top", nil)
diff --git a/pkg/bindings/test/info_test.go b/pkg/bindings/test/info_test.go
index 3ca4b99b3..f61e8c370 100644
--- a/pkg/bindings/test/info_test.go
+++ b/pkg/bindings/test/info_test.go
@@ -49,17 +49,17 @@ var _ = Describe("Podman info", func() {
_, err := containers.CreateWithSpec(bt.conn, s, nil)
Expect(err).To(BeNil())
- idPause, err := bt.RunTopContainer(nil, nil, nil)
+ idPause, err := bt.RunTopContainer(nil, nil)
Expect(err).To(BeNil())
err = containers.Pause(bt.conn, idPause, nil)
Expect(err).To(BeNil())
- idStop, err := bt.RunTopContainer(nil, nil, nil)
+ idStop, err := bt.RunTopContainer(nil, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, idStop, nil)
Expect(err).To(BeNil())
- _, err = bt.RunTopContainer(nil, nil, nil)
+ _, err = bt.RunTopContainer(nil, nil)
Expect(err).To(BeNil())
info, err := system.Info(bt.conn, nil)
diff --git a/pkg/bindings/test/pods_test.go b/pkg/bindings/test/pods_test.go
index 2b4eb05d3..b06ff31a2 100644
--- a/pkg/bindings/test/pods_test.go
+++ b/pkg/bindings/test/pods_test.go
@@ -63,7 +63,7 @@ var _ = Describe("Podman pods", func() {
Expect(err).To(BeNil())
// Adding an alpine container to the existing pod
- _, err = bt.RunTopContainer(nil, bindings.PTrue, &newpod)
+ _, err = bt.RunTopContainer(nil, &newpod)
Expect(err).To(BeNil())
podSummary, err = pods.List(bt.conn, nil)
// Verify no errors.
@@ -93,7 +93,7 @@ var _ = Describe("Podman pods", func() {
_, err = pods.Start(bt.conn, newpod, nil)
Expect(err).To(BeNil())
- _, err = bt.RunTopContainer(nil, bindings.PTrue, &newpod)
+ _, err = bt.RunTopContainer(nil, &newpod)
Expect(err).To(BeNil())
// Expected err with invalid filter params
@@ -179,7 +179,7 @@ var _ = Describe("Podman pods", func() {
Expect(code).To(BeNumerically("==", http.StatusNotFound))
// Adding an alpine container to the existing pod
- _, err = bt.RunTopContainer(nil, bindings.PTrue, &newpod)
+ _, err = bt.RunTopContainer(nil, &newpod)
Expect(err).To(BeNil())
// Binding needs to be modified to inspect the pod state.
diff --git a/pkg/bindings/test/system_test.go b/pkg/bindings/test/system_test.go
index a68a8099c..68e9d9301 100644
--- a/pkg/bindings/test/system_test.go
+++ b/pkg/bindings/test/system_test.go
@@ -4,7 +4,6 @@ import (
"sync"
"time"
- "github.com/containers/podman/v3/pkg/bindings"
"github.com/containers/podman/v3/pkg/bindings/containers"
"github.com/containers/podman/v3/pkg/bindings/pods"
"github.com/containers/podman/v3/pkg/bindings/system"
@@ -41,7 +40,7 @@ var _ = Describe("Podman system", func() {
It("podman events", func() {
var name = "top"
- _, err := bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err := bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
filters := make(map[string][]string)
@@ -72,7 +71,7 @@ var _ = Describe("Podman system", func() {
Expect(err).To(BeNil())
// Start and stop a container to enter in exited state.
var name = "top"
- _, err = bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err = bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil())
@@ -98,14 +97,14 @@ var _ = Describe("Podman system", func() {
// Start and stop a container to enter in exited state.
var name = "top"
- _, err = bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err = bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil())
// Start container and leave in running
var name2 = "top2"
- _, err = bt.RunTopContainer(&name2, bindings.PFalse, nil)
+ _, err = bt.RunTopContainer(&name2, nil)
Expect(err).To(BeNil())
// Adding an unused volume
@@ -132,14 +131,14 @@ var _ = Describe("Podman system", func() {
// Start and stop a container to enter in exited state.
var name = "top"
- _, err = bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err = bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil())
// Start second container and leave in running
var name2 = "top2"
- _, err = bt.RunTopContainer(&name2, bindings.PFalse, nil)
+ _, err = bt.RunTopContainer(&name2, nil)
Expect(err).To(BeNil())
// Adding an unused volume should work
@@ -167,14 +166,14 @@ var _ = Describe("Podman system", func() {
// Start and stop a container to enter in exited state.
var name = "top"
- _, err = bt.RunTopContainer(&name, bindings.PFalse, nil)
+ _, err = bt.RunTopContainer(&name, nil)
Expect(err).To(BeNil())
err = containers.Stop(bt.conn, name, nil)
Expect(err).To(BeNil())
// Start second container and leave in running
var name2 = "top2"
- _, err = bt.RunTopContainer(&name2, bindings.PFalse, nil)
+ _, err = bt.RunTopContainer(&name2, nil)
Expect(err).To(BeNil())
// Adding an unused volume should work
diff --git a/pkg/copy/fileinfo.go b/pkg/copy/fileinfo.go
index b95bcd90c..fb711311c 100644
--- a/pkg/copy/fileinfo.go
+++ b/pkg/copy/fileinfo.go
@@ -7,8 +7,8 @@ import (
"os"
"path/filepath"
"strings"
- "time"
+ "github.com/containers/podman/v3/libpod/define"
"github.com/pkg/errors"
)
@@ -22,14 +22,7 @@ var ErrENOENT = errors.New("No such file or directory")
// FileInfo describes a file or directory and is returned by
// (*CopyItem).Stat().
-type FileInfo struct {
- Name string `json:"name"`
- Size int64 `json:"size"`
- Mode os.FileMode `json:"mode"`
- ModTime time.Time `json:"mtime"`
- IsDir bool `json:"isDir"`
- LinkTarget string `json:"linkTarget"`
-}
+type FileInfo = define.FileInfo
// EncodeFileInfo serializes the specified FileInfo as a base64 encoded JSON
// payload. Intended for Docker compat.
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go
index ac965834a..7d074f89d 100644
--- a/pkg/domain/entities/containers.go
+++ b/pkg/domain/entities/containers.go
@@ -8,7 +8,6 @@ import (
"github.com/containers/image/v5/types"
"github.com/containers/podman/v3/libpod/define"
- "github.com/containers/podman/v3/pkg/copy"
"github.com/containers/podman/v3/pkg/specgen"
"github.com/cri-o/ocicni/pkg/ocicni"
)
@@ -145,7 +144,7 @@ type ContainerInspectReport struct {
}
type ContainerStatReport struct {
- copy.FileInfo
+ define.FileInfo
}
type CommitOptions struct {
diff --git a/pkg/domain/infra/abi/archive.go b/pkg/domain/infra/abi/archive.go
index 528771ee7..2ea63aa5e 100644
--- a/pkg/domain/infra/abi/archive.go
+++ b/pkg/domain/infra/abi/archive.go
@@ -3,72 +3,16 @@ package abi
import (
"context"
"io"
- "path/filepath"
- "strings"
- buildahCopiah "github.com/containers/buildah/copier"
- "github.com/containers/buildah/pkg/chrootuser"
- "github.com/containers/buildah/util"
- "github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/pkg/domain/entities"
- "github.com/containers/storage"
- "github.com/containers/storage/pkg/archive"
- "github.com/containers/storage/pkg/idtools"
- "github.com/opencontainers/runtime-spec/specs-go"
- "github.com/pkg/errors"
- "github.com/sirupsen/logrus"
)
-// NOTE: Only the parent directory of the container path must exist. The path
-// itself may be created while copying.
func (ic *ContainerEngine) ContainerCopyFromArchive(ctx context.Context, nameOrID string, containerPath string, reader io.Reader) (entities.ContainerCopyFunc, error) {
container, err := ic.Libpod.LookupContainer(nameOrID)
if err != nil {
return nil, err
}
-
- containerMountPoint, err := container.Mount()
- if err != nil {
- return nil, err
- }
-
- unmount := func() {
- if err := container.Unmount(false); err != nil {
- logrus.Errorf("Error unmounting container: %v", err)
- }
- }
-
- _, resolvedRoot, resolvedContainerPath, err := ic.containerStat(container, containerMountPoint, containerPath)
- if err != nil {
- unmount()
- return nil, err
- }
-
- decompressed, err := archive.DecompressStream(reader)
- if err != nil {
- unmount()
- return nil, err
- }
-
- idMappings, idPair, err := getIDMappingsAndPair(container, resolvedRoot)
- if err != nil {
- unmount()
- return nil, err
- }
-
- logrus.Debugf("Container copy *to* %q (resolved: %q) on container %q (ID: %s)", containerPath, resolvedContainerPath, container.Name(), container.ID())
-
- return func() error {
- defer unmount()
- defer decompressed.Close()
- putOptions := buildahCopiah.PutOptions{
- UIDMap: idMappings.UIDMap,
- GIDMap: idMappings.GIDMap,
- ChownDirs: idPair,
- ChownFiles: idPair,
- }
- return buildahCopiah.Put(resolvedRoot, resolvedContainerPath, putOptions, decompressed)
- }, nil
+ return container.CopyFromArchive(ctx, containerPath, reader)
}
func (ic *ContainerEngine) ContainerCopyToArchive(ctx context.Context, nameOrID string, containerPath string, writer io.Writer) (entities.ContainerCopyFunc, error) {
@@ -76,108 +20,5 @@ func (ic *ContainerEngine) ContainerCopyToArchive(ctx context.Context, nameOrID
if err != nil {
return nil, err
}
-
- containerMountPoint, err := container.Mount()
- if err != nil {
- return nil, err
- }
-
- unmount := func() {
- if err := container.Unmount(false); err != nil {
- logrus.Errorf("Error unmounting container: %v", err)
- }
- }
-
- // Make sure that "/" copies the *contents* of the mount point and not
- // the directory.
- if containerPath == "/" {
- containerPath = "/."
- }
-
- statInfo, resolvedRoot, resolvedContainerPath, err := ic.containerStat(container, containerMountPoint, containerPath)
- if err != nil {
- unmount()
- return nil, err
- }
-
- idMappings, idPair, err := getIDMappingsAndPair(container, resolvedRoot)
- if err != nil {
- unmount()
- return nil, err
- }
-
- logrus.Debugf("Container copy *from* %q (resolved: %q) on container %q (ID: %s)", containerPath, resolvedContainerPath, container.Name(), container.ID())
-
- return func() error {
- defer container.Unmount(false)
- getOptions := buildahCopiah.GetOptions{
- // Unless the specified points to ".", we want to copy the base directory.
- KeepDirectoryNames: statInfo.IsDir && filepath.Base(containerPath) != ".",
- UIDMap: idMappings.UIDMap,
- GIDMap: idMappings.GIDMap,
- ChownDirs: idPair,
- ChownFiles: idPair,
- }
- return buildahCopiah.Get(resolvedRoot, "", getOptions, []string{resolvedContainerPath}, writer)
- }, nil
-}
-
-// getIDMappingsAndPair returns the ID mappings for the container and the host
-// ID pair.
-func getIDMappingsAndPair(container *libpod.Container, containerMount string) (*storage.IDMappingOptions, *idtools.IDPair, error) {
- user, err := getContainerUser(container, containerMount)
- if err != nil {
- return nil, nil, err
- }
-
- idMappingOpts, err := container.IDMappings()
- if err != nil {
- return nil, nil, err
- }
-
- hostUID, hostGID, err := util.GetHostIDs(idtoolsToRuntimeSpec(idMappingOpts.UIDMap), idtoolsToRuntimeSpec(idMappingOpts.GIDMap), user.UID, user.GID)
- if err != nil {
- return nil, nil, err
- }
-
- idPair := idtools.IDPair{UID: int(hostUID), GID: int(hostGID)}
- return &idMappingOpts, &idPair, nil
-}
-
-// getContainerUser returns the specs.User of the container.
-func getContainerUser(container *libpod.Container, mountPoint string) (specs.User, error) {
- userspec := container.Config().User
-
- uid, gid, _, err := chrootuser.GetUser(mountPoint, userspec)
- u := specs.User{
- UID: uid,
- GID: gid,
- Username: userspec,
- }
-
- if !strings.Contains(userspec, ":") {
- groups, err2 := chrootuser.GetAdditionalGroupsForUser(mountPoint, uint64(u.UID))
- if err2 != nil {
- if errors.Cause(err2) != chrootuser.ErrNoSuchUser && err == nil {
- err = err2
- }
- } else {
- u.AdditionalGids = groups
- }
- }
-
- return u, err
-}
-
-// idtoolsToRuntimeSpec converts idtools ID mapping to the one of the runtime spec.
-func idtoolsToRuntimeSpec(idMaps []idtools.IDMap) (convertedIDMap []specs.LinuxIDMapping) {
- for _, idmap := range idMaps {
- tempIDMap := specs.LinuxIDMapping{
- ContainerID: uint32(idmap.ContainerID),
- HostID: uint32(idmap.HostID),
- Size: uint32(idmap.Size),
- }
- convertedIDMap = append(convertedIDMap, tempIDMap)
- }
- return convertedIDMap
+ return container.CopyToArchive(ctx, containerPath, writer)
}
diff --git a/pkg/domain/infra/abi/containers_stat.go b/pkg/domain/infra/abi/containers_stat.go
index 1baeb9178..98a23c70b 100644
--- a/pkg/domain/infra/abi/containers_stat.go
+++ b/pkg/domain/infra/abi/containers_stat.go
@@ -2,139 +2,20 @@ package abi
import (
"context"
- "os"
- "path/filepath"
- "strings"
- buildahCopiah "github.com/containers/buildah/copier"
- "github.com/containers/podman/v3/libpod"
- "github.com/containers/podman/v3/pkg/copy"
"github.com/containers/podman/v3/pkg/domain/entities"
- "github.com/pkg/errors"
- "github.com/sirupsen/logrus"
)
-func (ic *ContainerEngine) containerStat(container *libpod.Container, containerMountPoint string, containerPath string) (*entities.ContainerStatReport, string, string, error) {
- // Make sure that "/" copies the *contents* of the mount point and not
- // the directory.
- if containerPath == "/" {
- containerPath += "/."
- }
-
- // Now resolve the container's path. It may hit a volume, it may hit a
- // bind mount, it may be relative.
- resolvedRoot, resolvedContainerPath, err := container.ResolvePath(context.Background(), containerMountPoint, containerPath)
- if err != nil {
- return nil, "", "", err
- }
-
- statInfo, statInfoErr := secureStat(resolvedRoot, resolvedContainerPath)
- if statInfoErr != nil {
- // Not all errors from secureStat map to ErrNotExist, so we
- // have to look into the error string. Turning it into an
- // ENOENT let's the API handlers return the correct status code
- // which is crucial for the remote client.
- if os.IsNotExist(err) || strings.Contains(statInfoErr.Error(), "o such file or directory") {
- statInfoErr = copy.ErrENOENT
- }
- // If statInfo is nil, there's nothing we can do anymore. A
- // non-nil statInfo may indicate a symlink where we must have
- // a closer look.
- if statInfo == nil {
- return nil, "", "", statInfoErr
- }
- }
-
- // Now make sure that the info's LinkTarget is relative to the
- // container's mount.
- var absContainerPath string
-
- if statInfo.IsSymlink {
- // Evaluated symlinks are always relative to the container's mount point.
- absContainerPath = statInfo.ImmediateTarget
- } else if strings.HasPrefix(resolvedContainerPath, containerMountPoint) {
- // If the path is on the container's mount point, strip it off.
- absContainerPath = strings.TrimPrefix(resolvedContainerPath, containerMountPoint)
- absContainerPath = filepath.Join("/", absContainerPath)
- } else {
- // No symlink and not on the container's mount point, so let's
- // move it back to the original input. It must have evaluated
- // to a volume or bind mount but we cannot return host paths.
- absContainerPath = containerPath
- }
-
- // Now we need to make sure to preserve the base path as specified by
- // the user. The `filepath` packages likes to remove trailing slashes
- // and dots that are crucial to the copy logic.
- absContainerPath = copy.PreserveBasePath(containerPath, absContainerPath)
- resolvedContainerPath = copy.PreserveBasePath(containerPath, resolvedContainerPath)
-
- info := copy.FileInfo{
- IsDir: statInfo.IsDir,
- Name: filepath.Base(absContainerPath),
- Size: statInfo.Size,
- Mode: statInfo.Mode,
- ModTime: statInfo.ModTime,
- LinkTarget: absContainerPath,
- }
-
- return &entities.ContainerStatReport{FileInfo: info}, resolvedRoot, resolvedContainerPath, statInfoErr
-}
-
func (ic *ContainerEngine) ContainerStat(ctx context.Context, nameOrID string, containerPath string) (*entities.ContainerStatReport, error) {
container, err := ic.Libpod.LookupContainer(nameOrID)
if err != nil {
return nil, err
}
- containerMountPoint, err := container.Mount()
- if err != nil {
- return nil, err
- }
-
- defer func() {
- if err := container.Unmount(false); err != nil {
- logrus.Errorf("Error unmounting container: %v", err)
- }
- }()
-
- statReport, _, _, err := ic.containerStat(container, containerMountPoint, containerPath)
- return statReport, err
-}
-
-// secureStat extracts file info for path in a chroot'ed environment in root.
-func secureStat(root string, path string) (*buildahCopiah.StatForItem, error) {
- var glob string
- var err error
-
- // If root and path are equal, then dir must be empty and the glob must
- // be ".".
- if filepath.Clean(root) == filepath.Clean(path) {
- glob = "."
- } else {
- glob, err = filepath.Rel(root, path)
- if err != nil {
- return nil, err
- }
- }
-
- globStats, err := buildahCopiah.Stat(root, "", buildahCopiah.StatOptions{}, []string{glob})
- if err != nil {
- return nil, err
- }
-
- if len(globStats) != 1 {
- return nil, errors.Errorf("internal error: secureStat: expected 1 item but got %d", len(globStats))
- }
-
- stat, exists := globStats[0].Results[glob] // only one glob passed, so that's okay
- if !exists {
- return nil, copy.ErrENOENT
- }
+ info, err := container.Stat(ctx, containerPath)
- var statErr error
- if stat.Error != "" {
- statErr = errors.New(stat.Error)
+ if info != nil {
+ return &entities.ContainerStatReport{FileInfo: *info}, err
}
- return stat, statErr
+ return nil, err
}
diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go
index 562653403..ffd4856fe 100644
--- a/pkg/domain/infra/abi/images.go
+++ b/pkg/domain/infra/abi/images.go
@@ -583,8 +583,9 @@ func (ir *ImageEngine) Remove(ctx context.Context, images []string, opts entitie
report.Deleted = append(report.Deleted, results.Deleted)
report.Untagged = append(report.Untagged, results.Untagged...)
return nil
- case storage.ErrImageUnknown:
- // The image must have been removed already (see #6510).
+ case storage.ErrImageUnknown, storage.ErrLayerUnknown:
+ // The image must have been removed already (see #6510)
+ // or the storage is corrupted (see #9617).
report.Deleted = append(report.Deleted, img.ID())
report.Untagged = append(report.Untagged, img.ID())
return nil
diff --git a/pkg/domain/infra/abi/network.go b/pkg/domain/infra/abi/network.go
index 50a74032c..edde8ece6 100644
--- a/pkg/domain/infra/abi/network.go
+++ b/pkg/domain/infra/abi/network.go
@@ -96,7 +96,15 @@ func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, o
}
// We need to iterate containers looking to see if they belong to the given network
for _, c := range containers {
- if util.StringInSlice(name, c.Config().Networks) {
+ networks, _, err := c.Networks()
+ // if container vanished or network does not exist, go to next container
+ if errors.Is(err, define.ErrNoSuchNetwork) || errors.Is(err, define.ErrNoSuchCtr) {
+ continue
+ }
+ if err != nil {
+ return reports, err
+ }
+ if util.StringInSlice(name, networks) {
// if user passes force, we nuke containers and pods
if !options.Force {
// Without the force option, we return an error
diff --git a/pkg/specgen/generate/oci.go b/pkg/specgen/generate/oci.go
index 23a9ce831..eb4dbc944 100644
--- a/pkg/specgen/generate/oci.go
+++ b/pkg/specgen/generate/oci.go
@@ -2,12 +2,14 @@ package generate
import (
"context"
+ "path"
"strings"
"github.com/containers/common/pkg/config"
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/libpod/image"
+ "github.com/containers/podman/v3/pkg/cgroups"
"github.com/containers/podman/v3/pkg/rootless"
"github.com/containers/podman/v3/pkg/specgen"
spec "github.com/opencontainers/runtime-spec/specs-go"
@@ -157,8 +159,32 @@ func canMountSys(isRootless, isNewUserns bool, s *specgen.SpecGenerator) bool {
return true
}
+func getCGroupPermissons(unmask []string) string {
+ ro := "ro"
+ rw := "rw"
+ cgroup := "/sys/fs/cgroup"
+
+ cgroupv2, _ := cgroups.IsCgroup2UnifiedMode()
+ if !cgroupv2 {
+ return ro
+ }
+
+ if unmask != nil && unmask[0] == "ALL" {
+ return rw
+ }
+
+ for _, p := range unmask {
+ if path.Clean(p) == cgroup {
+ return rw
+ }
+ }
+ return ro
+}
+
+// SpecGenToOCI returns the base configuration for the container.
func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runtime, rtc *config.Config, newImage *image.Image, mounts []spec.Mount, pod *libpod.Pod, finalCmd []string) (*spec.Spec, error) {
- cgroupPerm := "ro"
+ cgroupPerm := getCGroupPermissons(s.Unmask)
+
g, err := generate.New("linux")
if err != nil {
return nil, err