Commit graph

2029 commits

Author SHA1 Message Date
Matthew Heon 1fdfd52eeb Populate remaining unused fields in pod inspect
We were hard-coding two fields to false, instead of grabbing
their value from the pod config, which means that `pod inspect`
would print the wrong value always.

Fixes #6968

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-07-14 12:03:11 -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
Matthew Heon c4627b5846 Fix container and pod create commands for remote create
In `podman inspect` output for containers and pods, we include
the command that was used to create the container. This is also
used by `podman generate systemd --new` to generate unit files.

With remote podman, the generated create commands were incorrect
since we sourced directly from os.Args on the server side, which
was guaranteed to be `podman system service` (or some variant
thereof). The solution is to pass the command along in the
Specgen or PodSpecgen, where we can source it from the client's
os.Args.

This will still be VERY iffy for mixed local/remote use (doing a
`podman --remote run ...` on a remote client then a
`podman generate systemd --new` on the server on the same
container will not work, because the `--remote` flag will slip
in) but at the very least the output of `podman inspect` will be
correct. We can look into properly handling `--remote` (parsing
it out would be a little iffy) in a future PR.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-10 11:22:23 -04:00
Matthew Heon 4b784b377c Remove all instances of named return "err" from Libpod
This was inspired by https://github.com/cri-o/cri-o/pull/3934 and
much of the logic for it is contained there. However, in brief,
a named return called "err" can cause lots of code confusion and
encourages using the wrong err variable in defer statements,
which can make them work incorrectly. Using a separate name which
is not used elsewhere makes it very clear what the defer should
be doing.

As part of this, remove a large number of named returns that were
not used anywhere. Most of them were once needed, but are no
longer necessary after previous refactors (but were accidentally
retained).

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-09 13:54:47 -04:00
OpenShift Merge Robot bc3b3b373f
Merge pull request #6916 from vrothberg/logs-fixes
log API: add context to allow for cancelling
2020-07-09 17:05:47 +02:00
Valentin Rothberg 09dc77aedf log API: add context to allow for cancelling
Add a `context.Context` to the log APIs to allow for cancelling
streaming (e.g., via `podman logs -f`).  This fixes issues for
the remote API where some go routines of the server will continue
writing and produce nothing but heat and waste CPU cycles.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-09 15:13:07 +02:00
Qi Wang a1d6114177 Fix saving in oci format
- fix saving&loading oci format. Close #6544
- support loading using image name without "localhost/" prefix when reading from ociarchive/dir saved from this semantics

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-07-09 08:03:54 -04:00
OpenShift Merge Robot 54d16f3b5f
Merge pull request #6829 from rhatdan/keepid
Add username to /etc/passwd inside of container if --userns keep-id
2020-07-07 19:23:27 +02:00
Valentin Rothberg f4a2d25c0f fix race condition in libpod.GetEvents(...)
Fix a race that could cause read errors to be masked.  Masking such
errors is likely to report red herrings since users don't see that
reading failed for some reasons but that a given event could not be
found.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-07 16:22:22 +02:00
Daniel J Walsh 6c6670f12a
Add username to /etc/passwd inside of container if --userns keep-id
If I enter a continer with --userns keep-id, my UID will be present
inside of the container, but most likely my user will not be defined.

This patch will take information about the user and stick it into the
container.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-07 08:34:31 -04:00
Joseph Gooch 0b1c1ef461 Implement --sdnotify cmdline option to control sd-notify behavior
--sdnotify container|conmon|ignore
With "conmon", we send the MAINPID, and clear the NOTIFY_SOCKET so the OCI
runtime doesn't pass it into the container. We also advertise "ready" when the
OCI runtime finishes to advertise the service as ready.

With "container", we send the MAINPID, and leave the NOTIFY_SOCKET so the OCI
runtime passes it into the container for initialization, and let the container advertise further metadata.
This is the default, which is closest to the behavior podman has done in the past.

The "ignore" option removes NOTIFY_SOCKET from the environment, so neither podman nor
any child processes will talk to systemd.

This removes the need for hardcoded CID and PID files in the command line, and
the PIDFile directive, as the pid is advertised directly through sd-notify.

Signed-off-by: Joseph Gooch <mrwizard@dok.org>
2020-07-06 17:47:18 +00:00
OpenShift Merge Robot 9532509c50
Merge pull request #6836 from ashley-cui/tzlibpod
Add --tz flag to create, run
2020-07-06 13:28:20 -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
OpenShift Merge Robot 4351e33947
Merge pull request #6846 from mheon/fix_pod_errors
Print errors from individual containers in pods
2020-07-06 06:26:19 -04:00
Ashley Cui 9a1543caec Add --tz flag to create, run
--tz flag sets timezone inside container
Can be set to IANA timezone as well as `local` to match host machine

Signed-off-by: Ashley Cui <acui@redhat.com>
2020-07-02 13:30:59 -04:00
Matthew Heon e996bb583d Print errors from individual containers in pods
The infra/abi code for pods was written in a flawed way, assuming
that the map[string]error containing individual container errors
was only set when the global error for the pod function was nil;
that is not accurate, and we are actually *guaranteed* to set the
global error when any individual container errors. Thus, we'd
never actually include individual container errors, because the
infra code assumed that err being set meant everything failed and
no container operations were attempted.

We were originally setting the cause of the error to something
nonsensical ("container already exists"), so I made a new error
indicating that some containers in the pod failed. We can then
ignore that error when building the report on the pod operation
and actually return errors from individual containers.

Unfortunately, this exposed another weakness of the infra code,
which was discarding the container IDs. Errors from individual
containers are not guaranteed to identify which container they
came from, hence the use of map[string]error in the Pod API
functions. Rather than restructuring the structs we return from
pkg/infra, I just wrapped the returned errors with a message
including the ID of the container.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-02 12:59:10 -04:00
Matthew Heon 9e4cf6ca51 Fix system service panic from early hangup in events
We weren't actually halting the goroutine that sent events, so it
would continue sending even when the channel closed (the most
notable cause being early hangup - e.g. Control-c on a curl
session). Use a context to cancel the events goroutine and stop
sending events.

Fixes #6805

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-02 09:57:39 -04:00
OpenShift Merge Robot c2a0ccd394
Merge pull request #6747 from giuseppe/fix-user-volumes
container: move volume chown after spec generation
2020-06-30 12:01:40 -04:00
Giuseppe Scrivano b32172e20b
container: move volume chown after spec generation
move the chown for newly created volumes after the spec generation so
the correct UID/GID are known.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-29 17:58:50 +02:00
Giuseppe Scrivano 688cc0aee3
libpod: volume copyup honors namespace mappings
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-29 17:51:55 +02:00
OpenShift Merge Robot 6ac009d530
Merge pull request #6666 from giuseppe/conmon-delegate
podman: add new cgroup mode split
2020-06-29 10:53:41 -04:00
Giuseppe Scrivano 6ee5f740a4
podman: add new cgroup mode split
When running under systemd there is no need to create yet another
cgroup for the container.

With conmon-delegated the current cgroup will be split in two sub
cgroups:

- supervisor
- container

The supervisor cgroup will hold conmon and the podman process, while
the container cgroup is used by the OCI runtime (using the cgroupfs
backend).

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-25 17:16:12 +02:00
Matthew Heon d78e83f47d Add support for dangling filter to volumes
The dangling filter determine whether a volume is dangling - IE,
it has no containers attached using it. Unlike our other filters,
this one is a boolean - must be true or false, not arbitrary
values.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-24 15:12:56 -04:00
OpenShift Merge Robot b61e429f19
Merge pull request #6732 from mheon/fix_stopsignal_set
Set stop signal to 15 when not explicitly set
2020-06-24 13:02:43 -04:00
OpenShift Merge Robot 988fd27541
Merge pull request #6746 from vrothberg/untag
podman untag: error if tag doesn't exist
2020-06-24 12:19:42 -04:00
OpenShift Merge Robot 6bc5dcc282
Merge pull request #6729 from QiWang19/inspect-format
Reformat inspect network settings
2020-06-24 09:35:25 -04:00
Valentin Rothberg 1c6c12581c podman untag: error if tag doesn't exist
Throw an error if a specified tag does not exist.  Also make sure that
the user input is normalized as we already do for `podman tag`.

To prevent regressions, add a set of end-to-end and systemd tests.

Last but not least, update the docs and add bash completions.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-06-24 15:34:46 +02:00
Matthew Heon 7fe4c5204e Set stop signal to 15 when not explicitly set
When going through the output of `podman inspect` to try and
identify another issue, I noticed that Podman 2.0 was setting
StopSignal to 0 on containers by default. After chasing it
through the command line and SpecGen, I determined that we were
actually not setting a default in Libpod, which is strange
because I swear we used to do that. I re-added the disappeared
default and now all is well again.

Also, while I was looking for the bug in SpecGen, I found a bunch
of TODOs that have already been done. Eliminate the comments for
these.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-24 09:27:20 -04:00
Giuseppe Scrivano 370195cf78
libpod: specify mappings to the storage
specify the mappings in the container configuration to the storage
when creating the container so that the correct mappings can be
configured.

Regression introduced with Podman 2.0.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-24 11:26:49 +02:00
Qi Wang f586c006f8 Reformat inspect network settings
Reformat ports of inspect network settings to compatible with docker inspect. Close #5380

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-06-23 16:14:27 -04:00
OpenShift Merge Robot 9e37fd43e4
Merge pull request #6625 from QiWang19/fd
Add --preservefds to podman run
2020-06-23 10:00:21 +02:00
OpenShift Merge Robot 11dd5f51b6
Merge pull request #6702 from jgallucci32/follow-logs-poll
Stop following logs using timers
2020-06-22 18:10:06 +02:00
jgallucci32 8926e1f03b Use POLL_DURATION for timer
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-21 09:31:22 -07:00
jgallucci32 78dd4f2ecb Stop following logs using timers
This incorporates code from PR #6591 and #6614 but does not use
event channels to detect container state and rather uses timers
with a defined wait duration before calling t.StopAtEOF() to
ensure the last log entry is output before a container exits.

The polling interval is set to 250 milliseconds based on polling
interval defined in hpcloud/tail here:
https://github.com/hpcloud/tail/blob/v1.0.0/watch/polling.go#L117

Co-authored-by: Qi Wang <qiwan@redhat.com>
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-20 09:48:55 -07:00
Daniel J Walsh 5b3503c0a1
Add container name to the /etc/hosts within the container
This will allow containers that connect to the network namespace be
able to use the container name directly.

For example you can do something like

podman run -ti --name foobar fedora ping foobar

While we can do this with hostname now, this seems more natural.

Also if another container connects on the network to this container it
can do

podman run --network container:foobar fedora ping foobar

And connect to the original container,without having to discover the name.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-06-20 06:20:46 -04:00
OpenShift Merge Robot f403aa3baa
Merge pull request #6621 from vrothberg/bz-1846629
search: allow wildcards
2020-06-20 05:57:25 -04:00
Brent Baude f46664546a Poll on events for file reading
When multiple connections are monitoring events via the remote API, the inotify in the hpcloud library seems unable to consistently send events.  Switching from inotify to poll seems to clear this up.

Fixes: #6664

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-06-19 09:00:03 -05:00
Qi Wang f61a7f25a8 Add --preservefds to podman run
Add --preservefds to podman run. close https://github.com/containers/libpod/issues/6458

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-06-19 09:40:13 -04:00
Valentin Rothberg b05888a97d search: allow wildcards
Allow wildcards in the search term.  Note that not all registries
support wildcards and it may only work with v1 registries.

Note that searching implies figuring out if the specified search term
includes a registry.  If there's not registry detected, the search term
will be used against all configured "unqualified-serach-registries" in
the registries.conf.  The parsing logic considers a registry to be the
substring before the first slash `/`.

With these changes we now not only support wildcards but arbitrary
input; ultimately it's up to the registries to decide whether they
support given input or not.

Fixes: bugzilla.redhat.com/show_bug.cgi?id=1846629
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-06-19 14:47:36 +02:00
Matthew Heon b20619e5b0 Allow recursive dependency start with Init()
As part of APIv2 Attach, we need to be able to attach to freshly
created containers (in ContainerStateConfigured). This isn't
something Libpod is interested in supporting, so we use Init() to
get the container into ContainerStateCreated, in which attach is
possible. Problem: Init() will fail if dependencies are not
started, so a fresh container in a fresh pod will fail. The
simplest solution is to extend the existing recursive start code
from Start() to Init(), allowing dependency containers to be
started when we initialize the container (optionally, controlled
via bool).

Also, update some comments in container_api.go to make it more
clear how some of our major API calls work.

Fixes #6646

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-06-18 09:34:04 -04:00
OpenShift Merge Robot 7b00e49f65
Merge pull request #6560 from mheon/fix_exec_logdriver
Do not share container log driver for exec
2020-06-17 17:17:27 -04:00
OpenShift Merge Robot fd184fa4a1
Merge pull request #6522 from mheon/unless-stopped
Add support for the unless-stopped restart policy
2020-06-17 15:25:09 -04:00
jgallucci32 03e99c9b40 Revert #6591 to fix issue with failed tests
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-17 08:31:09 -07:00
Matthew Heon 6f1440a3ec Add support for the unless-stopped restart policy
We initially believed that implementing this required support for
restarting containers after reboot, but this is not the case.
The unless-stopped restart policy acts identically to the always
restart policy except in cases related to reboot (which we do not
support yet), but it does not require that support for us to
implement it.

Changes themselves are quite simple, we need a new restart policy
constant, we need to remove existing checks that block creation
of containers when unless-stopped was used, and we need to update
the manpages.

Fixes #6508

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-17 11:16:12 -04:00
Matthew Heon 0e171b7b33 Do not share container log driver for exec
When the container uses journald logging, we don't want to
automatically use the same driver for its exec sessions. If we do
we will pollute the journal (particularly in the case of
healthchecks) with large amounts of undesired logs. Instead,
force exec sessions logs to file for now; we can add a log-driver
flag later (we'll probably want to add a `podman logs` command
that reads exec session logs at the same time).

As part of this, add support for the new 'none' logs driver in
Conmon. It will be the default log driver for exec sessions, and
can be optionally selected for containers.

Great thanks to Joe Gooch (mrwizard@dok.org) for adding support
to Conmon for a null log driver, and wiring it in here.

Fixes #6555

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-17 11:11:46 -04:00
Daniel J Walsh fb4148bc41
Fix podman-remote images
Looks like we went too far with the linters.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-06-16 12:29:25 -04:00
OpenShift Merge Robot 8a42a32c71
Merge pull request #6591 from jgallucci32/patch-1
Merged request to fix -f to stop following logs
2020-06-15 13:57:13 -04:00
jgallucci32 6d9863e773 Remove redundant break in for loop.
Remove redundant `break` call in for loop.

Co-authored-by: Qi Wang <qiwan@redhat.com>
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-15 07:42:05 -07:00
Daniel J Walsh 200cfa41a4
Turn on More linters
- misspell
    - prealloc
    - unparam
    - nakedret

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-06-15 07:05:56 -04:00
jgallucci32 d514e3c097 Do not print error message when container does not exist
This fixes a condition when a container is removed while
following the logs and prints an error when the container
is removed forcefully.

Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-12 12:59:58 -07:00