Commit Graph

69 Commits

Author SHA1 Message Date
651ddd3560 Reduce CPU usage when --timeout=0
* Add second go routine for when a Timer is not needed.
* goimports updated some project files

Fixes 

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-03-18 10:27:25 -07:00
9ef5d28759 Merge pull request from baude/manifests
apiv2 addition of manifests
2020-03-17 16:00:05 +01:00
abbbeacd68 apiv2 addition of manifests
add endpoints for create, add, remove, inspect, and push.  this allows manifests to be managed through the restful interfaces.

also added go-bindings and tests

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-03-16 10:03:55 -05:00
2099643aa2 add apiv2 healthcheck code
reworking binding and endpoint to actually work.  added documentation in swagger for and various return code possibilities.  add a good start on tests though we need some other container functions not yet implemented for that.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-03-13 07:43:12 -05:00
216a6091d0 [CI:DOCS]Add libpod event endpoint
add an endpoint for events on the libpod side of the house.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-03-11 09:25:57 -05:00
a83a94b095 Merge pull request from vrothberg/update-systemd
update systemd & dbus dependencies
2020-03-10 19:31:14 +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
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
c8de26fb08 Merge pull request from baude/create
add default network for apiv2 create
2020-03-07 14:16:43 +01:00
8b5e2a6297 add default network for apiv2 create
during container creation, if no network is provided, we need to add a default value so the container can be later started.

use apiv2 container creation for RunTopContainer instead of an exec to the system podman. RunTopContainer now also returns the container id and an error.

added a libpod commit endpoint.

also, changed the use of the connections and bindings slightly to make it more convenient to write tests.

Fixes: 5366
Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-03-06 14:31:45 -06: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
1641ee6180 Merge pull request from edsantiago/apiv2_fixes
more swagger fixes
2020-03-02 23:52:28 +01:00
c3c334a323 more swagger fixes
Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-03-02 12:01:56 -07: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
306b44380f binding tests for volumes
add binding tests for volumes: inspect(get), create, remove, prune, and list

implement filters ability for volumes

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-27 13:11:42 -06:00
997e3c8863 Remove 1 sec delay
* Stop closing net.Listener() twice on interrupt
 * Do not report error if closing server twice

Fixes 

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-02-25 11:04:20 -07:00
a554e97adc Merge pull request 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  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
1d8437d3ca Swagger: fix one incorrect comment
PR  updated a bunch of entrypoints from {name} to {name:.*},
requiring matching changes to swagger comments. Looks like one
got missed due to the manual nature of this work.

Have I mentioned lately that manual maintenance of duplicate
information is not a great idea?

Discrepancy caught by my script, which I would really like to
look into getting into CI, but is gating on . (I would
actually not like to get this script into CI, I would prefer
to have the duplicate information be autogenerated from
the function calls themselves, but I seem to have lost
that battle)

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-02-19 16:21:11 -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 )
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
024ddda123 Update mux rules to allow slashes in image names
%2F escaping is also supported.
Return better response on bad search terms

Fixes 

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-02-18 09:38:37 -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
d08e0c728f apiv2: Enable filtering images by ID
It is more practical for API usage and also it is more in sync how
filtering of containers works.

Signed-off-by: Matej Marusak <mmarusak@redhat.com>
2020-02-17 18:44:46 +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 
Fixes 

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-02-17 10:29:32 -07:00
93358ef915 Refactor image tree for API usage
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-02-17 11:12:35 +01: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
1b290f995b Merge pull request from jwhonce/wip/swagger_endpoint
Add /swagger/ endpoint to serve swagger yaml to clients
2020-02-14 00:32:26 +01:00
be37d144e7 Merge pull request from baude/apiv2events
apiv2 stream events
2020-02-12 13:28:55 +01:00
4bdfeed5bf Merge pull request from edsantiago/apiv2_pod_status_codes
API v2: pods: fix two incorrect return codes
2020-02-11 22:22:55 +01:00
5b830cca90 apiv2 stream events
the events endpoint should be stream-based.  it also needed to be registered to answer and not produce 404s.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-11 15:00:41 -06:00
d34ce1320c Merge pull request from vrothberg/v2-libpod-image-endpoints
v2 api: /libpod/images/{import,load,pull}
2020-02-11 21:25:35 +01:00
bdccdd2265 API v2: pods: fix two incorrect return codes
1) /pods/<X>/exists - is documented to return 204, and that's
    the correct value, but until now it has been returning 200.

 2) /pods/create - return 409 (conflict), not 500, when pod
    already exists

Also: in WriteResponse(), if code is 204 (No Content) or 304
(Not Modified), emit the status code only but no content-type
headers nor content.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-02-11 10:50:23 -07: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
13187607e7 swagger: fix /libpod/images/{import,load,pull}
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-02-11 13:08:23 +01:00
185c82bc80 v2 api: /libpod/images/import
Implement the /libpod/images/import endpoint

Tested manually with curl:
curl -X POST --data-binary "@image.tar" --header "Content-Type: application/x-tar"

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-02-10 13:18:50 +01:00
926c9f8fbb v2 api: /libpod/images/load
Implement the /libpod/images/load endpoint.

Tested manually with curl:
curl -X POST --data-binary "@image.tar" --header "Content-Type: application/x-tar"

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-02-10 13:18:48 +01:00
76e2a0c5d3 v2 api: /libpod/images/pull
Implement the /libpod/images/pull endpoint and correct the swagger docs.
The reference parameter is mandatory and must either be a
c/image/docker/reference or a reference to the "docker://" transport as
the pull endpoint is meant to only support pulling images from a
registry.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-02-10 12:36:45 +01:00
c0b14ee29a fix swagger docs and make sure docs validation runs
Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-05 14:16:25 -06:00
4bb55161e9 Add /swagger/ endpoint to serve swagger yaml to clients
The provided yaml file will describe the current Podman REST API.

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-02-04 16:39:54 -07:00
84381df810 swagger: v2: libpod/images/{import,load,pull}
Note: this commit is merely adding swagger documentation and the golang
stubs and types for the proposed endpoints.  The implementation will
follow in separate individual changes in the future.

The ultimate goal is to prevent the libpod API from exposing the rather
complex /images/create endpoint from Docker and split it into easier to
implement, use and comprehend endpoints with a more narrow focus.

 # Import

Add the v2 swagger documentation for the libpod/images/import endpoint.
Note that we have intend to have separate backend and not mix it up with
load since import allows for specifying a URL instead of a local
tarball.

 # Load

Complete the v2 swagger documentation for the libpod/images/load
endpoint.  Note that we are accounting for future plans to be able to
load multiple images from one oci/docker archive by returning an array
of image-load responses.

Also move the (incomplete) implementation of the generic endpoint to the
corresponding package and create a stub for the libpod handler, which
will be implemented once there's an agreement on the proposed API.

 # Pull

Add the v2 swagger documentation for the libpod/images/pull endpoint.
Similar to the load endpoint, we return an array since more than one
image can be pulled when the `all-tags` parameter is set.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-02-04 10:45:54 +01:00
54926d1b03 Merge pull request from baude/apiv2swaggerexec
[CI:DOCS]add apiv2 endpoints for exec
2020-02-04 01:39:45 -08:00
4d301c8c4f Update /_ping support
* Add swagger support and documentation
* Promote handler as there can only ever be one
* Update swagger tags

Between verbs and paths there are four endpoints for /_ping.  I've
attempted to document them well without four copies of the details.
Time will tell.

Clients will use the headers `Libpod-API-Version` and
`Libpod-Buildha-Version` to determine if they are connecting to a Podman
service or some other compatible engine.

Client calls GET(/_ping):
 * VARLINK engines will fail with error message
 * Compatible engines will return 200 without Libpod headers
 * Podman engines will return 200 and Libpod headers

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-02-03 11:57:54 -07:00
81296cba82 [CI:DOCS]add apiv2 endpoints for exec
add the openapi/swagger documentation for exec.  The subcommands added are create, inspect, resize, and start.

at the time of this writing, no structure is declared for the inspect response.  once the libpod work for this is complete, we can inherit and swaggerize it.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-03 12:40:01 -06:00
f1eaccedfa fix longname handling for bindings
the api needs to account for image input where the image is encoded as a fqd image name.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-01-31 08:38:25 -06:00
54587335be [CI:DOCS]Binding overhauls
Add binding for networks and begin documentation for binding methods for godoc.  Also, add major functions to their own subpackages so reduce the amount of of method confusion.  So instead of: bindings.ListImages(), we now do a [bindings].images.List().

Also, the connection is passed to each binding method via a context to allow for future growth.

Lastly, add first set of tests.  There are a couple of things to work out for rootless tests yet.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-01-28 08:42:18 -06:00
5da70b04dd APIv2 review corrections
The third pass of corrections for the APIv2.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-01-25 15:09:09 -06:00
81e59a742b Merge pull request from jwhonce/wip/filters
[CI:DOCS] Add query parameter converters for complex types
2020-01-24 06:56:55 -08:00
9634e7eef7 Add query parameter converters for complex types
* Add converter for URL query parameters of type map[string][]string
* Add converter for URL query parameters of type time.Time
* Added function to allocate and configure schema.Decoder for API use
* Updated API handlers to leverage new converters, and correct handler
  code for filter type

An encoding example for a client using filters:

  v := map[string][]string{
      "dangling": {"true"},
  }
  payload, err := jsoniter.MarshalToString(v)
  if err != nil {
    panic(err)
  }
  payload = "?filters=" + url.QueryEscape(payload)

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-01-23 16:32:00 -07:00
cf7be58b2c Review corrections pass
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