Commit graph

41 commits

Author SHA1 Message Date
Daniel J Walsh 831d7fb0d7
Stop excessive wrapping of errors
Most of the builtin golang functions like os.Stat and
os.Open report errors including the file system object
path. We should not wrap these errors and put the file path
in a second time, causing stuttering of errors when they
get presented to the user.

This patch tries to cleanup a bunch of these errors.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-30 05:34:04 -04:00
Matthew Heon 2ea9dac5e1 Send HTTP Hijack headers after successful attach
Our previous flow was to perform a hijack before passing a
connection into Libpod, and then Libpod would attach to the
container's attach socket and begin forwarding traffic.

A problem emerges: we write the attach header as soon as the
attach complete. As soon as we write the header, the client
assumes that all is ready, and sends a Start request. This Start
may be processed *before* we successfully finish attaching,
causing us to lose output.

The solution is to handle hijacking inside Libpod. Unfortunately,
this requires a downright extensive refactor of the Attach and
HTTP Exec StartAndAttach code. I think the result is an
improvement in some places (a lot more errors will be handled
with a proper HTTP error code, before the hijack occurs) but
other parts, like the relocation of printing container logs, are
just *bad*. Still, we need this fixed now to get CI back into
good shape...

Fixes #7195

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-08-27 12:50:22 -04:00
Daniel J Walsh a5e37ad280
Switch all references to github.com/containers/libpod -> podman
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-28 08:23:45 -04:00
Matthew Heon 1ad7042a34 Preserve passwd on container restart
We added code to create a `/etc/passwd` file that we bind-mount
into the container in some cases (most notably,
`--userns=keep-id` containers). This, unfortunately, was not
persistent, so user-added users would be dropped on container
restart. Changing where we store the file should fix this.

Further, we want to ensure that lookups of users in the container
use the right /etc/passwd if we replaced it. There was already
logic to do this, but it only worked for user-added mounts; it's
easy enough to alter it to use our mounts as well.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-15 10:25:46 -04:00
Matthew Heon 41457b5a28 Include infra container information in pod inspect
We had a field for this in the inspect data, but it was never
being populated. Because of this, `podman pod inspect` stopped
showing port bindings (and other infra container settings). Add
code to populate the infra container inspect data, and add a test
to ensure we don't regress again.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-07-14 12:03:11 -04:00
Valentin Rothberg 8489dc4345 move go module to v2
With the advent of Podman 2.0.0 we crossed the magical barrier of go
modules.  While we were able to continue importing all packages inside
of the project, the project could not be vendored anymore from the
outside.

Move the go module to new major version and change all imports to
`github.com/containers/libpod/v2`.  The renaming of the imports
was done via `gomove` [1].

[1] https://github.com/KSubedi/gomove

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-06 15:50:12 +02:00
Jhon Honce b6113e2b9e WIP V2 attach bindings and test
* Add ErrLostSync to report lost of sync when de-mux'ing stream
* Add logus.SetLevel(logrus.DebugLevel) when `go test -v` given
* Add context to debugging messages

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-05-13 11:49:17 -07:00
baude b5a235df90 v2 podman stats
Signed-off-by: baude <bbaude@redhat.com>
2020-05-05 08:46:51 -05:00
Matthew Heon 71f14bd792 Improve APIv2 support for Attach
A few major fixes here:
- Support for attaching to Configured containers, to match Docker
  behavior.
- Support for stream parameter has been improved (we now properly
  handle cases where it is not set).
- Initial support for logs parameter has been added.
- Setting attach streams when the container has a terminal is now
  supported.
- Errors are properly reported once the hijack has begun.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-04-13 14:08:01 -04:00
Daniel J Walsh 4352d58549
Add support for containers.conf
vendor in c/common config pkg for containers.conf

Signed-off-by: Qi Wang qiwan@redhat.com
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-27 14:36:03 -04:00
Matthew Heon ac47e80b07 Add an API for Attach over HTTP API
The new APIv2 branch provides an HTTP-based remote API to Podman.
The requirements of this are, unfortunately, incompatible with
the existing Attach API. For non-terminal attach, we need append
a header to what was copied from the container, to multiplex
STDOUT and STDERR; to do this with the old API, we'd need to copy
into an intermediate buffer first, to handle the headers.

To avoid this, provide a new API to handle all aspects of
terminal and non-terminal attach, including closing the hijacked
HTTP connection. This might be a bit too specific, but for now,
it seems to be the simplest approach.

At the same time, add a Resize endpoint. This needs to be a
separate endpoint, so our existing channel approach does not work
here.

I wanted to rework the rest of attach at the same time (some
parts of it, particularly how we start the Attach session and how
we do resizing, are (in my opinion) handled much better here.
That may still be on the table, but I wanted to avoid breaking
existing APIs in this already massive change.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-01-16 13:49:21 -05:00
Matthew Heon 25cc43c376 Add ContainerStateRemoving
When Libpod removes a container, there is the possibility that
removal will not fully succeed. The most notable problems are
storage issues, where the container cannot be removed from
c/storage.

When this occurs, we were faced with a choice. We can keep the
container in the state, appearing in `podman ps` and available for
other API operations, but likely unable to do any of them as it's
been partially removed. Or we can remove it very early and clean
up after it's already gone. We have, until now, used the second
approach.

The problem that arises is intermittent problems removing
storage. We end up removing a container, failing to remove its
storage, and ending up with a container permanently stuck in
c/storage that we can't remove with the normal Podman CLI, can't
use the name of, and generally can't interact with. A notable
cause is when Podman is hit by a SIGKILL midway through removal,
which can consistently cause `podman rm` to fail to remove
storage.

We now add a new state for containers that are in the process of
being removed, ContainerStateRemoving. We set this at the
beginning of the removal process. It notifies Podman that the
container cannot be used anymore, but preserves it in the DB
until it is fully removed. This will allow Remove to be run on
these containers again, which should successfully remove storage
if it fails.

Fixes #3906

Signed-off-by: Matthew Heon <mheon@redhat.com>
2019-11-19 15:38:03 -05:00
Daniel J Walsh 65ed819932
Set SELinux labels based on the security context in the kube.yaml
If the kube.yaml specifieds the SELinux type or Level, we need the container
to be launched with the correct label.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-11-05 04:09:01 -05:00
Valentin Rothberg 11c282ab02 add libpod/config
Refactor the `RuntimeConfig` along with related code from libpod into
libpod/config.  Note that this is a first step of consolidating code
into more coherent packages to make the code more maintainable and less
prone to regressions on the long runs.

Some libpod definitions were moved to `libpod/define` to resolve
circular dependencies.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-10-31 17:42:37 +01:00
Daniel J Walsh 66c126d6de Set default seccomp.json file for podman play kube
Currently podman play kube is not using the system default seccomp.json file.
This PR will use the default or override location for podman play.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-10-29 13:43:45 -04:00
Daniel J Walsh b2b284111e
Return information about mount_program (fuse-overlayfs)
We want to get podman info to tell us about the version of
the mount program to help us diagnose issues users are having.

Also if in rootless mode and slirp4netns is installed reveal package
info on slirp4netns.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-09-06 07:32:42 -04:00
Giuseppe Scrivano 8e337aff5a
libpod: avoid polling container status
use the inotify backend to be notified on the container exit instead
of polling continuosly the runtime.  Polling the runtime slowns
significantly down the podman execution time for short lived
processes:

$ time bin/podman run --rm -ti fedora true

real	0m0.324s
user	0m0.088s
sys	0m0.064s

from:

$ time podman run --rm -ti fedora true

real	0m4.199s
user	0m5.339s
sys	0m0.344s

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-09-04 19:55:54 +02:00
baude 1d36501f96 code cleanup
clean up code identified as problematic by golands inspection

Signed-off-by: baude <bbaude@redhat.com>
2019-07-08 09:18:11 -05:00
baude 8561b99644 libpod removal from main (phase 2)
this is phase 2 for the removal of libpod from main.

Signed-off-by: baude <bbaude@redhat.com>
2019-06-27 07:56:24 -05:00
baude dd81a44ccf remove libpod from main
the compilation demands of having libpod in main is a burden for the
remote client compilations.  to combat this, we should move the use of
libpod structs, vars, constants, and functions into the adapter code
where it will only be compiled by the local client.

this should result in cleaner code organization and smaller binaries. it
should also help if we ever need to compile the remote client on
non-Linux operating systems natively (not cross-compiled).

Signed-off-by: baude <bbaude@redhat.com>
2019-06-25 13:51:24 -05:00
Giuseppe Scrivano 57e781462c
util: fix race condition in WaitForFile
enable polling also when using inotify.  It is generally useful to
have it as under high load inotify can lose notifications.  It also
solves a race condition where the file is created while the watcher
is configured and it'd wait until the timeout and fail.

Closes: https://github.com/containers/libpod/issues/2942

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-05-20 19:40:15 +02:00
Matthew Heon 5ed62991dc Remove ulele/deepcopier in favor of JSON deep copy
We have a very high performance JSON library that doesn't need to
perform code generation. Let's use it instead of our questionably
performant, reflection-dependent deep copy library.

Most changes because some functions can now return errors.

Also converts cmd/podman to use jsoniter, instead of pkg/json,
for increased performance.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-03-27 20:00:31 -04:00
Miloslav Trmač b70f8b3884 Fix build on non-Linux
Unrelated to the rest of the PR.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2018-12-06 23:31:54 +01:00
Giuseppe Scrivano fc3047322a
util: use fsnotify to wait for file
prefer a fsnotify watcher to polling the file, we take advantage of
inotify on Linux and react more promptly to the PID file being
created.

If the watcher cannot be created, then fallback to the old polling
mechanism.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-11-28 10:53:41 +01:00
Giuseppe Scrivano 070ce0c855
exec: don't wait for pidfile when the runtime exited
don't wait for the timeout to expire if the runtime process exited.
I've noticed podman to hang on exit and keeping the container lock
taken when the OCI runtime already exited.

Additionally, it reduces the waiting time as we won't hit the 25
milliseconds waiting time in the worst case.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-11-27 12:34:11 +01:00
Giuseppe Scrivano dfc689efc9
create: fix writing cidfile when using rootless
prevent opening the same file twice, since we re-exec podman in
rootless mode.  While at it, also solve a possible race between the
check for the file and writing to it.  Another process could have
created the file in the meanwhile and we would just end up overwriting
it.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-10-23 22:13:17 +02:00
baude 14473270d7 Add ability for ubuntu to be tested
unfortunately the papr CI system cannot test ubuntu as a VM; therefore,
this PR still keeps travis.  but it does include fixes that will be required
for running on modern versions of ubuntu.

Signed-off-by: baude <bbaude@redhat.com>
2018-10-03 12:45:37 -05:00
haircommander 4c00dc66df Refactor error checking in With*NSFromPod options
Signed-off-by: haircommander <pehunt@redhat.com>

Closes: #1187
Approved by: mheon
2018-08-23 18:16:28 +00:00
Matthew Heon 74cf870792 Fix build on non-Linux OSes
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #1266
Approved by: baude
2018-08-15 18:07:04 +00:00
Matthew Heon 0998808a75 Create pod CGroups when using the systemd cgroup driver
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #1266
Approved by: baude
2018-08-15 18:07:04 +00:00
Daniel J Walsh 92e9d7891e We need to sort mounts so that one mount does not over mount another.
Currently we add mounts from images, volumes and internal.
We can accidently over mount an existing mount.  This patch sorts the mounts
to make sure a parent directory is always mounted before its content.

Had to change the default propagation on image volume mounts from shared
to private to stop mount points from leaking out of the container.

Also switched from using some docker/docker/pkg to container/storage/pkg
to remove some dependencies on Docker.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #1243
Approved by: mheon
2018-08-10 21:18:19 +00:00
baude f7c8dd5836 Stage 4 Image cleanup
Cull funcs from runtime_img.go which are no longer needed.  Also, fix any remaining
spots that use the old image technique.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #532
Approved by: mheon
2018-03-23 15:35:37 +00:00
baude b85b217f55 Stage3 Image Library
This represents the stage3 implementation for the image library.  At this point, we
are moving the image-centric functions to pkg/image including migration of args and
object-oriented references.  This is a not a one-for-one migration of funcs and some
funcs will need to continue to reside in runtime_img as they are overly specific to
libpod and probably not useful to others.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #484
Approved by: baude
2018-03-14 20:21:31 +00:00
Matthew Heon 8b87a17f56 Add tracking for exec session IDs
Exec sessions now have an ID generated and assigned to their PID
and stored in the database state. This allows us to track what
exec sessions are currently active.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #412
Approved by: baude
2018-03-01 21:17:51 +00:00
umohnani8 3d395767d8 Implement --image-volumes for create and run
--image-volumes tells podman what to do with the image volumes in the image config
There are 3 options: bind, tmpfs, and ignore
bind puts the volume contents in /var/lib/containers/storage/container-id/volumes/vol-dir
and bind mounts it into the container at /vol-dir
tmpfs mounts /vol-dir as a tmps into the container
ignore doesn't mount the image volumes onto the container

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #377
Approved by: rhatdan
2018-02-22 15:14:00 +00:00
baude 9adcb85929 podman run container id to file
podman run --cidfile /tmp/foo writes the container's id
to a file.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #205
Approved by: rhatdan
2018-01-11 21:27:26 +00:00
baude 9cc0c8ae14 kpod stats
Move kpod stats to the libpod backend.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #113
Approved by: baude
2017-12-13 21:15:09 +00:00
Suraj Deshmukh 7eb4772694 remove unused functions and variables
Signed-off-by: Suraj Deshmukh <surajd.service@gmail.com>

Closes: #71
Approved by: rhatdan
2017-11-28 14:30:12 +00:00
TomSweeneyRedHat d43f786728 Add docker transport to push image before final failure
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Closes: #42
Approved by: rhatdan
2017-11-28 12:53:25 +00:00
baude 5cfd7a313f Address run/create performance issues
Fixed the logic where we observed different performance
results when running an image by its fqname vs a shortname. In
the case of the latter, we resolve the name without using the
network.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #37
Approved by: rhatdan
2017-11-14 21:14:13 +00:00
baude 8cf07b2ad1 libpod create and run
patched version of the same code that went into crio

Signed-off-by: baude <bbaude@redhat.com>
2017-11-01 14:19:19 -05:00