33 Commits

Author SHA1 Message Date
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
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
f4e873c4e1 auto updates
Add support to auto-update containers running in systemd units as
generated with `podman generate systemd --new`.

`podman auto-update` looks up containers with a specified
"io.containers.autoupdate" label (i.e., the auto-update policy).

If the label is present and set to "image", Podman reaches out to the
corresponding registry to check if the image has been updated.  We
consider an image to be updated if the digest in the local storage is
different than the one of the remote image.  If an image must be
updated, Podman pulls it down and restarts the container.  Note that the
restarting sequence relies on systemd.

At container-creation time, Podman looks up the "PODMAN_SYSTEMD_UNIT"
environment variables and stores it verbatim in the container's label.
This variable is now set by all systemd units generated by
`podman-generate-systemd` and is set to `%n` (i.e., the name of systemd
unit starting the container).  This data is then being used in the
auto-update sequence to instruct systemd (via DBUS) to restart the unit
and hence to restart the container.

Note that this implementation of auto-updates relies on systemd and
requires a fully-qualified image reference to be used to create the
container.  This enforcement is necessary to know which image to
actually check and pull.  If we used an image ID, we would not know
which image to check/pull anymore.

Fixes: #3575
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-03-17 17:18:56 +01:00
450361fc64 update systemd & dbus dependencies
Update the outdated systemd and dbus dependencies which are now provided
as go modules.  This will further tighten our dependencies and releases
and pave the way for the upcoming auto-update feature.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-03-10 18:34:55 +01:00
67165b7675 make lint: enable gocritic
`gocritic` is a powerful linter that helps in preventing certain kinds
of errors as well as enforcing a coding style.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-13 14:27:02 +01:00
8d928d525f codespell: spelling corrections
Signed-off-by: Dmitry Smirnov <onlyjob@member.fsf.org>
2019-11-13 08:15:00 +11:00
276d68c8f5 events: make sure the write channel is always closed
in case of errors, the channel is not closed, blocking the reader
indefinitely.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1767663

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-11-06 17:14:44 +01:00
bbfc80c579 performance fix for podman events with large journalds
in the case where the host has a large journald, iterating the journal
without using a Match is very poor performance.  this might be a
temporary fix while we figure out why the systemd library does not seem to
behave properly.

Signed-off-by: baude <bbaude@redhat.com>
2019-08-14 09:30:12 -05:00
62e8c328d8 Small optimization - only store exit code when nonzero
JSON optimizes it out in that case anyways, so don't waste cycles
doing an Itoa (and Atoi on the decode side).

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-08-12 19:05:44 -04:00
d3a433181d Fix container exit code with Journald backend
We weren't actually storing this, so we'd lose the exit code for
containers run with --rm or force-removed while running if the
journald backend for events was in use.

Fixes #3795

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-08-12 19:05:44 -04:00
62a04f2b03 systemd library conflict with seektail and addmatch
it looks like the core-os systemd library has some issue when using
seektail and add match.  this patch works around that shortcoming for
the time being.

Fixes: #3616
Signed-off-by: baude <bbaude@redhat.com>
2019-08-06 14:58:26 -05:00
fff496436e Merge pull request #3171 from QiWang19/events_json
podman events format json
2019-08-05 16:11:42 +02:00
63eef5a234 add eventlogger to info
to help with future debugging, we now display the type of event logger
being used inside podman info -> host.

Signed-off-by: baude <bbaude@redhat.com>
2019-08-02 20:05:27 -05:00
0ad374af6a podman events format json
Enable podman events to format the output as jsonline

Signed-off-by: Qi Wang <qiwan@redhat.com>
2019-08-02 11:47:43 -04:00
8da24f2f7d Use "none" instead of "null" for the null eventer
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-08-01 15:01:54 -04:00
cc63aff571 System events are valid, don't error on them
The logfile driver was not aware that system events existed.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-07-31 17:28:42 -04:00
cdd5639d56 Expose Null eventer and allow its use in the Podman CLI
We need this specifically for tests, but others may find it
useful if they don't explicitly need events and don't want the
performance implications of using them.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-07-31 17:28:42 -04:00
8e8d1ac193 Add a flag to set events logger type
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-07-31 17:28:42 -04:00
a78c885397 golangci-lint pass number 2
clean up and prepare to migrate to the golangci-linter

Signed-off-by: baude <bbaude@redhat.com>
2019-07-11 09:13:06 -05:00
d252100c94 get last container event
an internal change in libpod will soon required the ability to lookup
the last container event using the continer name or id and the type of
event.  this pr is in preperation for that need.

Signed-off-by: baude <bbaude@redhat.com>
2019-07-07 08:54:20 -05:00
7a58c6601b set default event logger based on build tags
once the default event logger was removed from libpod.conf, we need to
set the default based on whether the systemd build tag is used or not.

Signed-off-by: baude <bbaude@redhat.com>
2019-05-14 16:17:11 -05:00
d1fc3fc702 Add systemd build tag
If the systemd development files are not present on the system which
builds podman, then `podman events` will error on runtime creation.
Beside this, a warning will be printed when compiling podman.

This commit mainly exists because projects which depend on libpod
would not need the podman event support and therefore do not need to
rely on the systemd headers.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2019-05-13 14:00:27 +02:00
4d348d7839 Fix 'restart' event in journald
Ensure that we can decode the restart event with the new journald
events.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-05-03 10:43:14 -04:00
cafb68e301 Add a restart event, and make one during restart policy
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-05-03 10:36:16 -04:00
e05af78329 Do not hard fail on non-decodable events
Signed-off-by: Matthew Heon <mheon@redhat.com>
2019-04-26 10:50:57 -04:00
04d6ff0582 Add System event type and renumber, refresh events
Also, re-add locking to file eventer Write() to protect against
concurrent events.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2019-04-25 16:23:09 -04:00
7bf7c177ab journald event logging
add the ability for podman to read and write events to journald instead
of just a logfile.  This can be controlled in libpod.conf with the
`events_logger` attribute of `journald` or `file`.  The default will be
set to `journald`.

Signed-off-by: baude <bbaude@redhat.com>
2019-04-24 16:00:04 -05:00
e435931544 Merge pull request #2801 from mheon/remove_wait_event
Remove wait event
2019-03-29 15:10:04 -07:00
99318b0894 Remove wait event
It's not necessary to log an event for a read-only operation like
wait.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-03-29 14:50:43 -04:00
8108801247 Add locking to ensure events file is concurrency-safe
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-03-29 12:51:37 -04:00
e730fc6093 Add "died" event
We have a new event for container 'Exited' which has been renamed to
'died'.

also removed the stream bool from the varlink endpoint for events
because it can be determined by the varlink more value.

Signed-off-by: baude <bbaude@redhat.com>
2019-03-25 10:28:50 -05:00
3b5805d521 Add event on container death
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-03-13 10:18:51 -04:00
ca1e76ff63 Add event logging to libpod, even display to podman
In lipod, we now log major events that occurr.  These events
can be displayed using the `podman events` command. Each
event contains:

* Type (container, image, volume, pod...)
* Status (create, rm, stop, kill, ....)
* Timestamp in RFC3339Nano format
* Name (if applicable)
* Image (if applicable)

The format of the event and the varlink endpoint are to not
be considered stable until cockpit has done its enablement.

Signed-off-by: baude <bbaude@redhat.com>
2019-03-11 15:08:59 -05:00