summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-09-25 18:22:50 +0000
committerGitHub <noreply@github.com>2020-09-25 18:22:50 +0000
commitbb8e77d7f42ae361d11161239bd5c7ac6fa5d719 (patch)
treeb5baf2651f434559093921a4948b1924682d3b6a /pkg
parent17db9851d05544ef49f8bce0deec452a99aae2a9 (diff)
parent65f2f1a7639eb5bc12e6c522c111be18786870c9 (diff)
downloadpodman-bb8e77d7f42ae361d11161239bd5c7ac6fa5d719.tar.gz
podman-bb8e77d7f42ae361d11161239bd5c7ac6fa5d719.tar.bz2
podman-bb8e77d7f42ae361d11161239bd5c7ac6fa5d719.zip
Merge pull request #7785 from mheon/backports_211
Backports for v2.1.1
Diffstat (limited to 'pkg')
-rw-r--r--pkg/api/handlers/compat/containers.go25
-rw-r--r--pkg/api/handlers/compat/containers_create.go2
-rw-r--r--pkg/api/server/handler_api.go17
-rw-r--r--pkg/domain/infra/tunnel/containers.go62
-rw-r--r--pkg/domain/infra/tunnel/events.go32
-rw-r--r--pkg/domain/infra/tunnel/images.go7
6 files changed, 123 insertions, 22 deletions
diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go
index b1ef08cda..3a904ba87 100644
--- a/pkg/api/handlers/compat/containers.go
+++ b/pkg/api/handlers/compat/containers.go
@@ -17,6 +17,7 @@ import (
"github.com/docker/go-connections/nat"
"github.com/gorilla/schema"
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
)
func RemoveContainer(w http.ResponseWriter, r *http.Request) {
@@ -44,8 +45,25 @@ func RemoveContainer(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
name := utils.GetName(r)
con, err := runtime.LookupContainer(name)
- if err != nil {
- utils.ContainerNotFound(w, name, err)
+ if err != nil && errors.Cause(err) == define.ErrNoSuchCtr {
+ // Failed to get container. If force is specified, get the container's ID
+ // and evict it
+ if !query.Force {
+ utils.ContainerNotFound(w, name, err)
+ return
+ }
+
+ if _, err := runtime.EvictContainer(r.Context(), name, query.Vols); err != nil {
+ if errors.Cause(err) == define.ErrNoSuchCtr {
+ logrus.Debugf("Ignoring error (--allow-missing): %q", err)
+ w.WriteHeader(http.StatusNoContent)
+ return
+ }
+ logrus.Warn(errors.Wrapf(err, "Failed to evict container: %q", name))
+ utils.InternalServerError(w, err)
+ return
+ }
+ w.WriteHeader(http.StatusNoContent)
return
}
@@ -85,7 +103,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
utils.InternalServerError(w, err)
return
}
- if _, found := r.URL.Query()["limit"]; found && query.Limit != -1 {
+ if _, found := r.URL.Query()["limit"]; found && query.Limit > 0 {
last := query.Limit
if len(containers) > last {
containers = containers[len(containers)-last:]
@@ -175,6 +193,7 @@ func KillContainer(w http.ResponseWriter, r *http.Request) {
err = con.Kill(signal)
if err != nil {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrapf(err, "unable to kill Container %s", name))
+ return
}
// Docker waits for the container to stop if the signal is 0 or
diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go
index 93e4fe540..1d0b4c45d 100644
--- a/pkg/api/handlers/compat/containers_create.go
+++ b/pkg/api/handlers/compat/containers_create.go
@@ -210,7 +210,7 @@ func makeCreateConfig(ctx context.Context, containerConfig *config.Config, input
ImageID: newImage.ID(),
BuiltinImgVolumes: nil, // podman
ImageVolumeType: "", // podman
- Interactive: false,
+ Interactive: input.OpenStdin,
// IpcMode: input.HostConfig.IpcMode,
Labels: input.Labels,
LogDriver: input.HostConfig.LogConfig.Type, // is this correct
diff --git a/pkg/api/server/handler_api.go b/pkg/api/server/handler_api.go
index f2ce0301b..920811c51 100644
--- a/pkg/api/server/handler_api.go
+++ b/pkg/api/server/handler_api.go
@@ -34,15 +34,18 @@ func (s *APIServer) APIHandler(h http.HandlerFunc) http.HandlerFunc {
}
// TODO: Use r.ConnContext when ported to go 1.13
- c := context.WithValue(r.Context(), "decoder", s.Decoder) //nolint
- c = context.WithValue(c, "runtime", s.Runtime) //nolint
- c = context.WithValue(c, "shutdownFunc", s.Shutdown) //nolint
- c = context.WithValue(c, "idletracker", s.idleTracker) //nolint
+ c := context.WithValue(r.Context(), "decoder", s.Decoder) // nolint
+ c = context.WithValue(c, "runtime", s.Runtime) // nolint
+ c = context.WithValue(c, "shutdownFunc", s.Shutdown) // nolint
+ c = context.WithValue(c, "idletracker", s.idleTracker) // nolint
r = r.WithContext(c)
- v := utils.APIVersion[utils.CompatTree][utils.CurrentAPIVersion]
- w.Header().Set("API-Version", fmt.Sprintf("%d.%d", v.Major, v.Minor))
- w.Header().Set("Libpod-API-Version", utils.APIVersion[utils.LibpodTree][utils.CurrentAPIVersion].String())
+ cv := utils.APIVersion[utils.CompatTree][utils.CurrentAPIVersion]
+ w.Header().Set("API-Version", fmt.Sprintf("%d.%d", cv.Major, cv.Minor))
+
+ lv := utils.APIVersion[utils.LibpodTree][utils.CurrentAPIVersion].String()
+ w.Header().Set("Libpod-API-Version", lv)
+ w.Header().Set("Server", "Libpod/"+lv+" ("+runtime.GOOS+")")
h(w, r)
}
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go
index d0f90d900..7ea3b16a6 100644
--- a/pkg/domain/infra/tunnel/containers.go
+++ b/pkg/domain/infra/tunnel/containers.go
@@ -481,27 +481,67 @@ func startAndAttach(ic *ContainerEngine, name string, detachKeys *string, input,
func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []string, options entities.ContainerStartOptions) ([]*entities.ContainerStartReport, error) {
reports := []*entities.ContainerStartReport{}
- for _, name := range namesOrIds {
+ var exitCode = define.ExecErrorCodeGeneric
+ ctrs, err := getContainersByContext(ic.ClientCxt, false, false, namesOrIds)
+ if err != nil {
+ return nil, err
+ }
+ // There can only be one container if attach was used
+ for i, ctr := range ctrs {
+ name := ctr.ID
report := entities.ContainerStartReport{
Id: name,
- RawInput: name,
- ExitCode: 125,
+ RawInput: namesOrIds[i],
+ ExitCode: exitCode,
}
+ ctrRunning := ctr.State == define.ContainerStateRunning.String()
if options.Attach {
- report.Err = startAndAttach(ic, name, &options.DetachKeys, options.Stdin, options.Stdout, options.Stderr)
- if report.Err == nil {
- exitCode, err := containers.Wait(ic.ClientCxt, name, nil)
- if err == nil {
- report.ExitCode = int(exitCode)
+ err = startAndAttach(ic, name, &options.DetachKeys, options.Stdin, options.Stdout, options.Stderr)
+ if err == define.ErrDetach {
+ // User manually detached
+ // Exit cleanly immediately
+ report.Err = err
+ reports = append(reports, &report)
+ return reports, nil
+ }
+ if ctrRunning {
+ reports = append(reports, &report)
+ return reports, nil
+ }
+
+ if err != nil {
+ report.ExitCode = define.ExitCode(report.Err)
+ report.Err = err
+ reports = append(reports, &report)
+ return reports, errors.Wrapf(report.Err, "unable to start container %s", name)
+ }
+ exitCode, err := containers.Wait(ic.ClientCxt, name, nil)
+ if err == define.ErrNoSuchCtr {
+ // Check events
+ event, err := ic.GetLastContainerEvent(ctx, name, events.Exited)
+ if err != nil {
+ logrus.Errorf("Cannot get exit code: %v", err)
+ report.ExitCode = define.ExecErrorCodeNotFound
+ } else {
+ report.ExitCode = event.ContainerExitCode
}
} else {
- report.ExitCode = define.ExitCode(report.Err)
+ report.ExitCode = int(exitCode)
}
reports = append(reports, &report)
return reports, nil
}
- report.Err = containers.Start(ic.ClientCxt, name, &options.DetachKeys)
- report.ExitCode = define.ExitCode(report.Err)
+ // Start the container if it's not running already.
+ if !ctrRunning {
+ err = containers.Start(ic.ClientCxt, name, &options.DetachKeys)
+ if err != nil {
+ report.Err = errors.Wrapf(err, "unable to start container %q", name)
+ report.ExitCode = define.ExitCode(err)
+ reports = append(reports, &report)
+ continue
+ }
+ }
+ report.ExitCode = 0
reports = append(reports, &report)
}
return reports, nil
diff --git a/pkg/domain/infra/tunnel/events.go b/pkg/domain/infra/tunnel/events.go
index e6f4834b9..53bae6cef 100644
--- a/pkg/domain/infra/tunnel/events.go
+++ b/pkg/domain/infra/tunnel/events.go
@@ -2,8 +2,10 @@ package tunnel
import (
"context"
+ // "fmt"
"strings"
+ "github.com/containers/podman/v2/libpod/events"
"github.com/containers/podman/v2/pkg/bindings/system"
"github.com/containers/podman/v2/pkg/domain/entities"
"github.com/pkg/errors"
@@ -29,3 +31,33 @@ func (ic *ContainerEngine) Events(ctx context.Context, opts entities.EventsOptio
}()
return system.Events(ic.ClientCxt, binChan, nil, &opts.Since, &opts.Until, filters, &opts.Stream)
}
+
+// GetLastContainerEvent takes a container name or ID and an event status and returns
+// the last occurrence of the container event
+func (ic *ContainerEngine) GetLastContainerEvent(ctx context.Context, nameOrID string, containerEvent events.Status) (*events.Event, error) {
+ // check to make sure the event.Status is valid
+ if _, err := events.StringToStatus(containerEvent.String()); err != nil {
+ return nil, err
+ }
+ var event events.Event
+ return &event, nil
+
+ /*
+ FIXME: We need new bindings for this section
+ filters := []string{
+ fmt.Sprintf("container=%s", nameOrID),
+ fmt.Sprintf("event=%s", containerEvent),
+ "type=container",
+ }
+
+ containerEvents, err := system.GetEvents(ctx, entities.EventsOptions{Filter: filters})
+ if err != nil {
+ return nil, err
+ }
+ if len(containerEvents) < 1 {
+ return nil, errors.Wrapf(events.ErrEventNotFound, "%s not found", containerEvent.String())
+ }
+ // return the last element in the slice
+ return containerEvents[len(containerEvents)-1], nil
+ */
+}
diff --git a/pkg/domain/infra/tunnel/images.go b/pkg/domain/infra/tunnel/images.go
index 332a7c2eb..981884109 100644
--- a/pkg/domain/infra/tunnel/images.go
+++ b/pkg/domain/infra/tunnel/images.go
@@ -199,6 +199,13 @@ func (ir *ImageEngine) Load(ctx context.Context, opts entities.ImageLoadOptions)
return nil, err
}
defer f.Close()
+ fInfo, err := f.Stat()
+ if err != nil {
+ return nil, err
+ }
+ if fInfo.IsDir() {
+ return nil, errors.Errorf("remote client supports archives only but %q is a directory", opts.Input)
+ }
ref := opts.Name
if len(opts.Tag) > 0 {
ref += ":" + opts.Tag