Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in

[error ContainerNotFound](#ContainerNotFound)

[error ErrCtrStopped](#ErrCtrStopped)

[error ErrorOccurred](#ErrorOccurred)

[error ImageNotFound](#ImageNotFound)
Expand Down Expand Up @@ -1978,6 +1980,9 @@ force [bool](https://godoc.org/builtin#bool)
### <a name="ContainerNotFound"></a>type ContainerNotFound

ContainerNotFound means the container could not be found by the provided name or ID in local storage.
### <a name="ErrCtrStopped"></a>type ErrCtrStopped

Container is already stopped
### <a name="ErrorOccurred"></a>type ErrorOccurred

ErrorOccurred is a generic error for an error that occurs during the execution. The actual error message
Expand Down
14 changes: 0 additions & 14 deletions cmd/podman/main_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
package main

import (
"os"

"github.com/containers/libpod/pkg/rootless"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

Expand All @@ -29,16 +25,6 @@ func profileOff(cmd *cobra.Command) error {
}

func setupRootless(cmd *cobra.Command, args []string) error {
if rootless.IsRootless() {
became, ret, err := rootless.BecomeRootInUserNS()
if err != nil {
logrus.Errorf(err.Error())
os.Exit(1)
}
if became {
os.Exit(ret)
}
}
return nil
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/podman/varlink/io.podman.varlink
Original file line number Diff line number Diff line change
Expand Up @@ -1254,4 +1254,7 @@ error ErrorOccurred (reason: string)
error RuntimeError (reason: string)

# The Podman endpoint requires that you use a streaming connection.
error WantsMoreRequired (reason: string)
error WantsMoreRequired (reason: string)

# Container is already stopped
error ErrCtrStopped (id: string)
2 changes: 0 additions & 2 deletions contrib/cirrus/rootless_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ then
exit 1
fi

export PODMAN_VARLINK_ADDRESS=unix:/tmp/podman-$(id -u)

echo "."
echo "Hello, my name is $USER and I live in $PWD can I be your friend?"

Expand Down
2 changes: 1 addition & 1 deletion libpod/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (err error) {
if os.IsNotExist(errors.Cause(err)) {
manager, err = lock.NewSHMLockManager(lockPath, runtime.config.NumLocks)
if err != nil {
return err
return errors.Wrapf(err, "failed to get new shm lock manager")
}
} else if errors.Cause(err) == syscall.ERANGE && runtime.doRenumber {
logrus.Debugf("Number of locks does not match - removing old locks")
Expand Down
20 changes: 15 additions & 5 deletions pkg/adapter/containers_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,25 @@ func (r *LocalRuntime) StopContainers(ctx context.Context, cli *cliconfig.StopVa

ids, err := iopodman.GetContainersByContext().Call(r.Conn, cli.All, cli.Latest, cli.InputArgs)
if err != nil {
return ok, failures, err
return ok, failures, TranslateError(err)
}

for _, id := range ids {
stopped, err := iopodman.StopContainer().Call(r.Conn, id, int64(cli.Timeout))
if err != nil {
if _, err := iopodman.StopContainer().Call(r.Conn, id, int64(cli.Timeout)); err != nil {
transError := TranslateError(err)
if errors.Cause(transError) == libpod.ErrCtrStopped {
ok = append(ok, id)
continue
}
if errors.Cause(transError) == libpod.ErrCtrStateInvalid && cli.All {
ok = append(ok, id)
continue
}
failures[id] = err
} else {
ok = append(ok, stopped)
// We should be using ID here because in varlink, only successful returns
// include the string id
ok = append(ok, id)
}
}
return ok, failures, nil
Expand Down Expand Up @@ -310,7 +320,7 @@ func (r *LocalRuntime) KillContainers(ctx context.Context, cli *cliconfig.KillVa
func (r *LocalRuntime) RemoveContainers(ctx context.Context, cli *cliconfig.RmValues) ([]string, map[string]error, error) {
ids, err := iopodman.GetContainersByContext().Call(r.Conn, cli.All, cli.Latest, cli.InputArgs)
if err != nil {
return nil, nil, err
return nil, nil, TranslateError(err)
}

var (
Expand Down
31 changes: 31 additions & 0 deletions pkg/adapter/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// +build remoteclient

package adapter

import (
iopodman "github.com/containers/libpod/cmd/podman/varlink"
"github.com/containers/libpod/libpod"
"github.com/pkg/errors"
)

// TranslateMapErrors translates the errors a typical podman output struct
// from varlink errors to libpod errors
func TranslateMapErrors(failures map[string]error) map[string]error {
for k, v := range failures {
failures[k] = TranslateError(v)
}
return failures
}

// TranslateError converts a single varlink error to a libpod error
func TranslateError(err error) error {
switch err.(type) {
case *iopodman.ContainerNotFound:
return errors.Wrap(libpod.ErrNoSuchCtr, err.Error())
case *iopodman.ErrCtrStopped:
return errors.Wrap(libpod.ErrCtrStopped, err.Error())
case *iopodman.InvalidState:
return errors.Wrap(libpod.ErrCtrStateInvalid, err.Error())
}
return err
}
7 changes: 1 addition & 6 deletions pkg/adapter/info_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ func (r RemoteRuntime) Info() ([]libpod.InfoData, error) {

registries := make(map[string]interface{})
insecureRegistries := make(map[string]interface{})
conn, err := r.Connect()
if err != nil {
return nil, err
}
defer conn.Close()
info, err := iopodman.GetInfo().Call(conn)
info, err := iopodman.GetInfo().Call(r.Conn)
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/adapter/pods_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,15 @@ func (r *LocalRuntime) StartPods(ctx context.Context, cli *cliconfig.PodStartVal

// CreatePod creates a pod for the remote client over a varlink connection
func (r *LocalRuntime) CreatePod(ctx context.Context, cli *cliconfig.PodCreateValues, labels map[string]string) (string, error) {
var share []string
if cli.Share != "" {
share = strings.Split(cli.Share, ",")
}
pc := iopodman.PodCreate{
Name: cli.Name,
CgroupParent: cli.CgroupParent,
Labels: labels,
Share: strings.Split(cli.Share, ","),
Share: share,
Infra: cli.Infra,
InfraCommand: cli.InfraCommand,
InfraImage: cli.InfraCommand,
Expand Down
17 changes: 15 additions & 2 deletions pkg/varlinkapi/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ func (i *LibpodAPI) GetContainersByContext(call iopodman.VarlinkCall, all, lates

ctrs, err := shortcuts.GetContainersByContext(all, latest, input, i.Runtime)
if err != nil {
if errors.Cause(err) == libpod.ErrNoSuchCtr {
return call.ReplyContainerNotFound("", err.Error())
}
return call.ReplyErrorOccurred(err.Error())
}

Expand Down Expand Up @@ -359,7 +362,11 @@ func (i *LibpodAPI) StartContainer(call iopodman.VarlinkCall, name string) error
if state == libpod.ContainerStateRunning || state == libpod.ContainerStatePaused {
return call.ReplyErrorOccurred("container is already running or paused")
}
if err := ctr.Start(getContext(), false); err != nil {
recursive := false
if ctr.PodID() != "" {
recursive = true
}
if err := ctr.Start(getContext(), recursive); err != nil {
return call.ReplyErrorOccurred(err.Error())
}
return call.ReplyStartContainer(ctr.ID())
Expand All @@ -386,7 +393,13 @@ func (i *LibpodAPI) StopContainer(call iopodman.VarlinkCall, name string, timeou
if err != nil {
return call.ReplyContainerNotFound(name, err.Error())
}
if err := ctr.StopWithTimeout(uint(timeout)); err != nil && err != libpod.ErrCtrStopped {
if err := ctr.StopWithTimeout(uint(timeout)); err != nil {
if errors.Cause(err) == libpod.ErrCtrStopped {
return call.ReplyErrCtrStopped(ctr.ID())
}
if errors.Cause(err) == libpod.ErrCtrStateInvalid {
return call.ReplyInvalidState(ctr.ID(), err.Error())
}
return call.ReplyErrorOccurred(err.Error())
}
return call.ReplyStopContainer(ctr.ID())
Expand Down
6 changes: 1 addition & 5 deletions pkg/varlinkapi/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"github.com/containers/libpod/pkg/adapter/shortcuts"
"github.com/containers/libpod/pkg/rootless"
"syscall"

"github.com/containers/libpod/cmd/podman/shared"
Expand Down Expand Up @@ -37,12 +36,9 @@ func (i *LibpodAPI) CreatePod(call iopodman.VarlinkCall, create iopodman.PodCrea
if !create.Infra {
return call.ReplyErrorOccurred("you must have an infra container to publish port bindings to the host")
}
if rootless.IsRootless() {
return call.ReplyErrorOccurred("rootless networking does not allow port binding to the host")
}
portBindings, err := shared.CreatePortBindings(create.Publish)
if err != nil {
return err
return call.ReplyErrorOccurred(err.Error())
}
options = append(options, libpod.WithInfraContainerPorts(portBindings))

Expand Down
7 changes: 6 additions & 1 deletion test/e2e/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,14 @@ func PodmanTestCreateUtil(tempDir string, remote bool) *PodmanTestIntegration {
}
if remote {
p.PodmanTest.RemotePodmanBinary = podmanRemoteBinary
uuid := stringid.GenerateNonCryptoID()
if !rootless.IsRootless() {
uuid := stringid.GenerateNonCryptoID()
p.VarlinkEndpoint = fmt.Sprintf("unix:/run/podman/io.podman-%s", uuid)
} else {
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
socket := fmt.Sprintf("io.podman-%s", uuid)
fqpath := filepath.Join(runtimeDir, socket)
p.VarlinkEndpoint = fmt.Sprintf("unix:%s", fqpath)
}
}

Expand Down
2 changes: 0 additions & 2 deletions test/e2e/create_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build !remoteclient

package integration

import (
Expand Down
3 changes: 1 addition & 2 deletions test/e2e/diff_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build !remoteclient

package integration

import (
Expand Down Expand Up @@ -63,6 +61,7 @@ var _ = Describe("Podman diff", func() {
})

It("podman diff container and committed image", func() {
SkipIfRemote()
session := podmanTest.Podman([]string{"run", "--name=diff-test", ALPINE, "touch", "/tmp/diff-test"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expand Down
1 change: 1 addition & 0 deletions test/e2e/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var _ = Describe("Podman Info", func() {
}
podmanTest = PodmanTestCreate(tempdir)
podmanTest.Setup()
podmanTest.DelayForVarlink()
})

AfterEach(func() {
Expand Down
2 changes: 0 additions & 2 deletions test/e2e/kill_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build !remoteclient

package integration

import (
Expand Down
Loading