61 Commits

Author SHA1 Message Date
80e56fa12b Added optional container restore statistics
This adds the parameter '--print-stats' to 'podman container restore'.
With '--print-stats' Podman will measure how long Podman itself, the OCI
runtime and CRIU requires to restore a checkpoint and print out these
information. CRIU already creates process restore statistics which are
just read in addition to the added measurements. In contrast to just
printing out the ID of the restored container, Podman will now print
out JSON:

 # podman container restore --latest --print-stats
 {
     "podman_restore_duration": 305871,
     "container_statistics": [
         {
             "Id": "47b02e1d474b5d5fe917825e91ac653efa757c91e5a81a368d771a78f6b5ed20",
             "runtime_restore_duration": 140614,
             "criu_statistics": {
                 "forking_time": 5,
                 "restore_time": 67672,
                 "pages_restored": 14
             }
         }
     ]
 }

The output contains 'podman_restore_duration' which contains the
number of microseconds Podman required to restore the checkpoint. The
output also includes 'runtime_restore_duration' which is the time
the runtime needed to restore that specific container. Each container
also includes 'criu_statistics' which displays the timing information
collected by CRIU.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-11-15 11:50:25 +00:00
6202e8102b Added optional container checkpointing statistics
This adds the parameter '--print-stats' to 'podman container checkpoint'.
With '--print-stats' Podman will measure how long Podman itself, the OCI
runtime and CRIU requires to create a checkpoint and print out these
information. CRIU already creates checkpointing statistics which are
just read in addition to the added measurements. In contrast to just
printing out the ID of the checkpointed container, Podman will now print
out JSON:

 # podman container checkpoint --latest --print-stats
 {
     "podman_checkpoint_duration": 360749,
     "container_statistics": [
         {
             "Id": "25244244bf2efbef30fb6857ddea8cb2e5489f07eb6659e20dda117f0c466808",
             "runtime_checkpoint_duration": 177222,
             "criu_statistics": {
                 "freezing_time": 100657,
                 "frozen_time": 60700,
                 "memdump_time": 8162,
                 "memwrite_time": 4224,
                 "pages_scanned": 20561,
                 "pages_written": 2129
             }
         }
     ]
 }

The output contains 'podman_checkpoint_duration' which contains the
number of microseconds Podman required to create the checkpoint. The
output also includes 'runtime_checkpoint_duration' which is the time
the runtime needed to checkpoint that specific container. Each container
also includes 'criu_statistics' which displays the timing information
collected by CRIU.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-11-15 11:50:24 +00:00
449cc7a5c2 Implement top streaming for containers and pods
* Implement API query parameter stream and delay for containers and
  pods top endpoints
* Update swagger with breaking changes
* Add python API tests for endpoints

Fixes #12115

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-11-02 08:11:14 -07:00
f87f27ddc8 Add /containers/stats response to API docs
Include the response schema for a succesful request in the
/containers/stats API documentation

Additionally remove http 409 from /libpod/containers/stats docs, the
documentation was copied from the deprecated stats endpoint, when a
container is unavailabe the endpoint returns an empty list and no 409.

Signed-off-by: Jelle van der Waa <jvanderwaa@redhat.com>
2021-09-10 15:15:35 +02:00
1150d1b0b8 Document default timeout for libpod API Container Restart
Signed-off-by: Jelle van der Waa <jvanderwaa@redhat.com>
2021-09-07 14:46:00 +02:00
0897946f60 [NO TESTS NEEDED] Clean up swagger
* Removed defined by unused responses
* Added missing body definitions
* Updated header input definitions

Outstanding issues:
* Supporting body ContainerConfig for /commit endpoint

Fixes #8577

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-08-19 07:57:54 -07:00
3a922cbc99 Merge pull request #11003 from pascomnet/f_stats
stats: add a interval parameter to cli and api stats streaming
2021-08-04 09:56:57 +00:00
9cc974c963 Only support containers stats using cgroups v2
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1988252

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-08-03 15:31:59 -07:00
cdbbd79155 stats: add a interval parameter to cli and api stream mode
podman stats polled by default in a 1 sec period.
This can put quite some load on a machine if you run many containers.

The default value is now 5 seconds.
You can change this interval with a new, optional, --interval, -i cli flag.
The api request got also a interval query parameter for the same purpose.

Additionally a unused const was removed.
Api and cli will fail the request if a 0 or negative value is passed in.

Signed-off-by: Thomas Weber <towe75@googlemail.com>
2021-07-27 07:20:47 +02:00
8f6a0243f4 podman diff accept two images or containers
First, make podman diff accept optionally a second argument. This allows
the user to specify a second image/container to compare the first with.
If it is not set the parent layer will be used as before.

Second, podman container diff should only use containers and podman
image diff should only use images. Previously, podman container diff
would use the image when both an image and container with this name
exists.

To make this work two new parameters have been added to the api. If they
are not used the previous behaviour is used. The same applies to the
bindings.

Fixes #10649

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-07-02 17:11:56 +02:00
1f73374acd remote: always send resize before the container starts
There is race condition in the remote client attach logic. Because the
resize api call was handled in an extra goroutine the container was
started before the resize call happend. To fix this we have to call
resize in the same goroutine as attach. When the first resize is done
start a goroutine to listen on SIGWINCH in the background and resize
again if the signal is received.

Fixes #9859

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-06-04 16:55:48 +02:00
2cc4535e1f added tests in python rest api
Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
2021-06-01 14:54:02 -04:00
6f6dad4048 Adjust libpod API Container Wait documentation to the code
Closes #9960

Signed-off-by: Pablo Correa Gómez <ablocorrea@hotmail.com>
2021-04-07 19:01:10 +02:00
51b23be38b [CI:DOCS] Polish swagger OpertionIDs
Renamed 4 IDs to be consistent with other endpoints.

Fixes #9951

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-04-06 10:10:54 -07:00
fa47b4f572 [CI:DOCS] Set all operation id to be compatibile
Libpod operation id's changed to better match compatibile id

Builds on https://github.com/containers/podman/pull/9123 and corrects
a duplicated ID.

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-04-05 19:54:30 -07:00
5cbda3b789 Move operationIds to swagger:operation line
Signed-off-by: Tom Deseyn <tom.deseyn@gmail.com>
2021-04-05 13:57:13 -07:00
1214b1a38b swagger: add operationIds that match with docker
Signed-off-by: Tom Deseyn <tom.deseyn@gmail.com>
2021-04-05 13:56:51 -07:00
dcabf6dd71 Remove resize race condition
Since podman-remote resize requests can come in at random times, this
generates a real potential for race conditions. We should only be
attempting to resize TTY on running containers, but the containers can
go from running to stopped at any time, and returning an error to the
caller is just causing noice.

This change will basically ignore requests to resize terminals if the
container is not running and return the caller to success.  All other
callers will still return failure.

Fixes: https://github.com/containers/podman/issues/9831

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-03-26 15:15:17 -04:00
5dded6fae7 bump go module to v3
We missed bumping the go module, so let's do it now :)

* Automated go code with github.com/sirkon/go-imports-rename
* Manually via `vgrep podman/v2` the rest

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-22 09:03:51 +01:00
caa0bc1576 [CI:DOCS] [NO TESTS NEEDED] Update swagger doc for libpod container wait
Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-02-18 18:09:21 +01:00
073f76c132 Switch podman stop/kill/wait handlers to use abi
Change API Handlers to use the same functions that the
local podman uses.

At the same time:

 implement remote API for --all and --ignore flags for podman stop
 implement remote API for --all flags for podman stop

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-01-29 14:04:44 -05:00
21cb3043fc podman-remote ps --external --pod --sort do not work.
Fixup the bindings and the handling of the --external --por and --sort
flags.

The --storage option was renamed --external, make sure we use
external up and down the stack.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-01-27 06:44:43 -05:00
997de2f8e9 Initial implementation of renaming containers
Basic theory: We remove the container, but *only from the DB*.
We leave it in c/storage, we leave the lock allocated, we leave
it running (if it is). Then we create an identical container with
an altered name, and add that back to the database. Theoretically
we now have a renamed container.

The advantage of this approach is that it doesn't just apply to
rename - we can use this to make *any* configuration change to a
container that does not alter its container ID.

Potential problems are numerous. This process is *THOROUGHLY*
non-atomic at present - if you `kill -9` Podman mid-rename things
will be in a bad place, for example. Also, we can't rename
containers that can't be removed normally - IE, containers with
dependencies (pod infra containers, for example).

The largest potential improvement will be to move the majority of
the work into the DB, with a `RecreateContainer()` method - that
will add atomicity, and let us remove the container without
worrying about depencies and similar issues.

Potential problems: long-running processes that edit the DB and
may have an older version of the configuration around. Most
notable example is `podman run --rm` - the removal command needed
to be manually edited to avoid this one. This begins to get at
the heart of me not wanting to do this in the first place...

This provides CLI and API implementations for frontend, but no
tunnel implementation. It will be added in a future release (just
held back for time now - we need this in 3.0 and are running low
on time).

This is honestly kind of horrifying, but I think it will work.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2021-01-14 18:29:28 -05:00
c50c75419b add pod filter for ps
adds the ability to filter containers based on the filter "pod".  the
value can be a pod name or its full or partial id.

Fixes: #8512

Signed-off-by: baude <bbaude@redhat.com>
2020-12-22 09:40:39 -06:00
762b787fbf new endpoint: /libpod/containers/stats
Add a new endpoint for container stats allowing for batch operations on
more than one container.  The new endpoint deprecates the
single-container endpoint which will eventually be removed with the next
major release.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-09-24 14:09:55 +02:00
569854d634 Unconditionally retrieve pod names via API
The ListContainers API previously had a Pod parameter, which
determined if pod name was returned (but, notably, not Pod ID,
which was returned unconditionally). This was fairly confusing,
so we decided to deprecate/remove the parameter and return it
unconditionally.

To do this without serious performance implications, we need to
avoid expensive JSON decodes of pod configuration in the DB. The
way our Bolt tables are structured, retrieving name given ID is
actually quite cheap, but we did not expose this via the Libpod
API. Add a new GetName API to do this.

Fixes #7214

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-08-10 10:15:51 -04:00
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
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
6287a55852 V2 Implement terminal handling in bindings attach
* Add support for /exec/{id}/resize
* Add support for ErrSessionNotFound
* Resize container TTY as stdin changes size
* Refactor all resize functions into one handler

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-05-18 11:21:06 -07:00
ba26c763c5 swagger-check: new CI tool to cross-check swagger
New script cross-references r.Handle() and r.HandleFunc()
calls against the preceding '// swagger:operation' comments,
and exits failure (with descriptive error messages) if any
comments do not match the code.

This script should not be necessary: the swagger comments
should be autogenerated from the source code.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-04-14 11:27:44 -06:00
d8853429eb Merge pull request #5755 from mheon/fix_attach
Improve APIv2 support for Attach
2020-04-14 14:53:59 +02:00
d8d1aa49d2 v2podman add container init
add the ability to init a container both local and remote

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-04-13 19:51:20 -05:00
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
8ae28a55ac V2 podman diff(changes) support
* Ported CLI command
* Added API endpoint
* Added bindings
* Updated swagger (TODO: n endpoints, one handler)

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-04-07 09:39:46 -07:00
8a16674722 podmanv2 checkpoint and restore
add the ability to checkpoint and restore containers on v2podman

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-04-03 09:32:06 -05:00
bb39051616 podmanv2 export
add ability to export a container to a tarball

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-04-01 16:02:53 -05:00
edec8ccf3f swagger: top: remove "Docker" from the identifiers
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-03-28 17:32:27 +01:00
31112e4b08 Refactor handler packages
To help with packaging, the handlers in pkg/api/handlers are now found
in pkg/api/handler/compat.

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-03-10 08:03:41 -07:00
89b083f8b4 Register handlers without version to align with docker API
Signed-off-by: Steve Taylor <steven@taylormuff.co.uk>
2020-03-05 22:28:22 +00:00
0904873100 rework apiv2 wait endpoint|binding
added the ability to wait on a condition (stopped, running, paused...) for a container.  if a condition is not provided, wait will default to the stopped condition which uses the original wait code paths.  if the condition is stopped, the container exit code will be returned.

also, correct a mux issue we discovered.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-28 09:36:53 -06:00
a554e97adc Merge pull request #5236 from marusak/filter_by_id
apiv2: Image filtering and fixup docs
2020-02-21 12:17:38 -05:00
63a2fec6cb Swagger: yet more fixes
PR #5204 added /libpod/containers/create but with the wrong
swagger comment. Fix that.

Also fix some other inconsistencies: missing 'libpod' prefix,
missing 'Container' suffix, and change 'ContainerCreate'
to 'CreateContainer'; all of these changes preserve consistency
with both the invoked function as well as the overall naming
conventions used in this module.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-02-20 12:21:52 -07:00
d65ff6b3ec apiv2 container create using specgen
this uses the specgen structure to create containers rather than the outdated createconfig.  right now, only the apiv2 create is wired up.  eventually the cli will also have to be done.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-19 15:20:15 -06:00
2a411bcbfa Swagger: fix inconsistencies (try #2)
As I've mentioned once or twice, hand-maintained swagger docs
are evil. This commit attempts to fix:

  * Inconsistent methods (swagger says POST but code signature
    says GET)

  * Inconsistent capitalization

  * Typos ("Mounter", "pood")

  * Completely wrong paths (/inspect vs /json)

  * Missing .Method() registrations

  * Missing /libpod in some /volumes paths

  * Incorrect method declaration: /libpod/containers/.../kill
    was correct (POST) in swagger but wrong in the code itself
    (http.MethodGet). Correct the latter to MethodPost

This is two hours' work, even with a script I have that
tries to cross-check everything.

Swagger docs should not be human-maintained.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-02-18 11:07:07 -07:00
b6e0692466 apiv2: Fixup /containers/json filters documentation
Mention what is the input format plus put literals into quotation marks
for better readability (plus it seems that some tags were not rendered).

Signed-off-by: Matej Marusak <mmarusak@redhat.com>
2020-02-17 18:54:50 +01:00
c0c44ae8a3 Fix handler and systemd activation errors
On panic from handler: log warning and stack trace, report
InternalServerError to client

When using `podman system service` make determining the listening endpoint deterministic.

  // When determining _*THE*_ listening endpoint --
  // 1) User input wins always
  // 2) systemd socket activation
  // 3) rootless honors XDG_RUNTIME_DIR
  // 4) if varlink -- adapter.DefaultVarlinkAddress
  // 5) lastly adapter.DefaultAPIAddress

Fixes #5150
Fixes #5151

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-02-17 10:29:32 -07:00
b1034eabe3 apiv2 libpod container logs
wire up containers logs for libpod side of the house, same as compat.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-14 10:18:17 -06:00
ddffc865f3 Rewire ListContainers for APIv2 libpod
consumers of the api remarked how they would prefer a more strongly typed data structure from list containers oon the libpod side of things.  for example, events should be consumable and consistent timestamps.  also, for the sake of compatibility, it is helpful to have the json named atttributes for Id to not be ID.

listcontainers on the libpod side no longer strongly uses the the ps cli to obtain information but we do benefit from turning on the ability to list the last X containers, something CLI does not have yet. we also flipped the bit on defaulting to truncated output in the return.

thanks to the efforts of the cockpit team to help us here.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-11 08:14:28 -06:00
5da70b04dd APIv2 review corrections #3
The third pass of corrections for the APIv2.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-01-25 15:09:09 -06:00
cf7be58b2c Review corrections pass #2
Add API review comments to correct documentation and endpoints.  Also, add a libpode prune method to reduce code duplication.  Only used right now for the API but when the remote client is wired, we will switch over there too.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-01-23 11:58:26 -06:00