Commit Graph

82 Commits

Author SHA1 Message Date
Matt Heon ddea30e40e Add Compat API for Update
The Docker endpoint here is kind of a nightmare - accepts a full
Resources block, including a large number of scary things like
devices. But it only documents (and seems to use) a small subset
of those. This implements support for that subset. We can always
extend things to implement more later if we have a need.

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-04-17 08:23:51 -04:00
Matt Heon 72f1617fac Bump Go module to v5
Moving from Go module v4 to v5 prepares us for public releases.

Move done using gomove [1] as with the v3 and v4 moves.

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

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-02-08 09:35:39 -05:00
Ashley Cui a1c47f0299 Return nil health when inspecting containers without healthchecks
When inspecting a container that does not define any health check, the health field should return nil. This matches docker behavior.

Signed-off-by: Ashley Cui <acui@redhat.com>
2024-01-30 23:09:13 -05:00
renovate[bot] 3e6bfb6e99 Update module github.com/docker/docker to v25
[NO NEW TESTS NEEDED]

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2024-01-24 13:21:28 +01:00
Philip Dubé 522934d5cf Replace strings.SplitN with strings.Cut
Cut is a cleaner & more performant api relative to SplitN(_, _, 2) added in go 1.18

Previously applied this refactoring to buildah:
https://github.com/containers/buildah/pull/5239

Signed-off-by: Philip Dubé <philip@peerdb.io>
2024-01-11 13:50:15 +00:00
Brent Baude 78798cab00 Automatic code cleanups - JetBrains
A bunch of cleanups as suggested by linters/etc in JetBrains IDE.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2023-11-07 14:05:15 -06:00
Matej Vasek f33b01b731 fix: Docker API compatible bool deserialization
In Docker anything but "", "0", "no", "false", "none" (ignoring case) is considered to be true.

Signed-off-by: Matej Vasek <mvasek@redhat.com>
2023-08-14 15:09:14 +02:00
Valentin Rothberg f2794f9a82 API: kill: return 409 on invalid state
If the container isn't running, make sure to return 409 as specified in
the Docker API [1] and the Podman reference.

[1] https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerKill

Fixes: #19368
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-07-31 11:17:58 +02:00
Valentin Rothberg 811867249b container wait API: use string slice instead of state slice
Massage the internal APIs to use a string slice instead of a state slice
for passing wait conditions.  This paves the way for waiting on
non-state conditions such as "healthy".

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-06-23 09:26:30 +02:00
Valentin Rothberg c74bdae351 DB: make loading container states optional
Loading container states speed things up when listing all containers but
it comes with a price tag for many other call paths.  Hence, make
loading the state conditional to allow for keeping `podman ps` fast
without other commands regressing in performance.

[NO NEW TESTS NEEDED]

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-01-26 10:20:38 +01:00
Jakob Ahrer 97f63da67d
remove unmapped ports from inspect port bindings
Signed-off-by: Jakob Ahrer <jakob@ahrer.dev>
2022-12-15 23:18:50 +01:00
Josh Patterson 0e53c8c735 Merge remote-tracking branch 'upstream/main' into api_compat_containers 2022-08-29 15:48:02 -04:00
Josh Patterson aa197a65ff sort hc.Binds returned from compat api
Signed-off-by: Josh Patterson <josh.patterson@securityonionsolutions.com>
2022-08-17 14:39:32 -04:00
Josh Patterson 6411f57e78 api: return imageID instead of imageName, for "Image" when Podman API is queried
Signed-off-by: Josh Patterson <josh.patterson@securityonionsolutions.com>
2022-08-17 11:26:17 -04:00
openshift-ci[bot] 48c8923248
Merge pull request #14673 from idleroamer/fix-network-inspect-main
Fix network inspect compat API discrepancy
2022-07-07 11:55:30 +00:00
🤓 Mostafa Emami ee05bc0318 Fix network inspect compat API discrepancy
- containerInspect compat API expects field value PrefixLen
  instead of PrefixLength for type Address for SecondaryIPAddresses
- Add tests for network part of containerInspect compat api

Closes: containers#14674
Signed-off-by: 🤓 Mostafa Emami <mustafaemami@gmail.com>
2022-07-05 21:25:32 +02:00
Sascha Grunert 597de7a083
libpod/runtime: switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of
the deprecated github.com/pkg/errors package.

[NO NEW TESTS NEEDED]

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-04 15:39:00 +02:00
chesedo cc49146332 Docker compat returning unknown "initialized" for `status.status`
Some background for this PR is in discussion #14641. In short, ever so often a container inspect will return a `status.status` of `initialized` from the Docker compat socket.

From the discussion I found these lines which tries to fix a "configured" status to "created".
c936d1e611/pkg/api/handlers/compat/containers.go (L291-L294)

However, commit 141de86862 (Revamp Libpod state strings for Docker compat) removed the "configured" return value from the `String()` method called on line 291 above. Thus, making the `if` check redundant as it will never hit. But the same commit also introduces a return for "initialized" which this `if` should probably have been adapted for.

Signed-off-by: Pieter Engelbrecht <pieter@shuttle.rs>
2022-06-28 15:50:45 +02:00
Jhon Honce 5b79cf15a0 Swagger refactor/cleanup
* Remove duplicate or unused types and constants
* Move all documetation-only models and responses into swagger package
* Remove all unecessary names, go-swagger will determine names from
  struct declarations
* Use Libpod suffix to differentiate between compat and libpod models
  and responses. Taken from swagger:operation declarations.
* Models and responses that start with lowercase are for swagger use
  only while uppercase are used "as is" in the code and swagger comments
* Used gofumpt on new code

```release-note

```

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2022-05-19 15:24:18 -07:00
Valentin Rothberg b22143267b linter: enable unconvert linter
Detects unneccessary type conversions and helps in keeping the code base
cleaner.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-05-19 13:59:15 +02:00
Paul Holzinger 51fbf3da9e
enable gocritic linter
The linter ensures a common code style.
- use switch/case instead of else if
- use if instead of switch/case for single case statement
- add space between comment and text
- detect the use of defer with os.Exit()
- use short form var += "..." instead of var = var + "..."
- detect problems with append()
```
newSlice := append(orgSlice, val)
```
  This could lead to nasty bugs because the orgSlice will be changed in
  place if it has enough capacity too hold the new elements. Thus we
  newSlice might not be a copy.

Of course most of the changes are just cosmetic and do not cause any
logic errors but I think it is a good idea to enforce a common style.
This should help maintainability.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-04-26 18:12:22 +02:00
Jakub Guzik 7938f32c53 Remove unused param and clean API handlers
This commit removes error message string from utils.Error in pkg/api.
Param was not used inside a function for quite a long time
[NO NEW TESTS NEEDED]

Signed-off-by: Jakub Guzik <jguzik@redhat.com>
2022-01-22 00:31:18 +01:00
Valentin Rothberg bd09b7aa79 bump go module to version 4
Automated for .go files via gomove [1]:
`gomove github.com/containers/podman/v3 github.com/containers/podman/v4`

Remaining files via vgrep [2]:
`vgrep github.com/containers/podman/v3`

[1] https://github.com/KSubedi/gomove
[2] https://github.com/vrothberg/vgrep

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2022-01-18 12:47:07 +01:00
Daniel J Walsh 8f2358eeaa
Add podman rm --depend
This option causes Podman to not only remove the specified containers
but all of the containers that depend on the specified
containers.
Fixes: https://github.com/containers/podman/issues/10360

Also ran codespell on the code

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-01-11 14:33:54 -05:00
Daniel J Walsh 0c6ae3ab26
Fix Container List API call to return mount info
We are hard coding mounts to return nil in compat API,
since we have the data, we should return it.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-01-04 10:56:03 -05:00
Oliver a2687783d4 prefix imageId with sha256: in containers list
test for compat API ImageId

Signed-off-by: Oliver Thallmair <oliver.thallmair@mailbox.org>
2021-12-29 00:26:12 +01:00
Daniel J Walsh 21c9dc3c40
Add --time out for podman * rm -f commands
Add --time flag to podman container rm
Add --time flag to podman pod rm
Add --time flag to podman volume rm
Add --time flag to podman network rm

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-10-04 07:07:56 -04:00
Paul Holzinger 1199733754
podman inspect add State.Health field for docker compat
podman inspect shows the healthcheck status in `.State.Healthcheck`,
docker uses `.State.Health`. To make sure docker scripts work we
should add the `Health` key. Because we do not want to display both keys
by default we only use the new `Health` key. This is a breaking change
for podman users but matches what docker does. To provide some form of
compatibility users can still use `--format {{.State.Healthcheck}}`. IT
is just not shown by default.

Fixes #11645

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-09-23 14:44:34 +02:00
Jelle van der Waa 9b04e17893 api: handle nil pointer dereference in rest endpoints
When `?all=garbage` is passed to an API endpoint schema validation fails
and err is nil. Wrapf uses err to create an error message causing a nil
pointer dereference.

Signed-off-by: Jelle van der Waa <jvanderwaa@redhat.com>
2021-09-15 09:14:34 +02:00
Jhon Honce deaf969243 Refacter API server emphasis on logging
* To aid in debugging log API request and response bodies at trace
  level. Events can be correlated using the X-Reference-Id.
* Server now echos X-Reference-Id from client if set, otherwise
  generates an unique id.
* Move logic for X-Reference-Id into middleware
* Change uses of Header.Add() to Set() when setting Content-Type
* Log API operations in Apache format using gorilla middleware
* Port server code to use BaseContext and ConnContext

Fixes #10053

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2021-09-10 15:07:25 -07:00
Milivoje Legenovic a210a22920 Compat API: Fix healthcheck status and healthcheck config
Fixes:

- Do not show healthcheck status if not available or if container
  status is "created" (Docker behaviour)
- Show healthcheck configuration if present (Config.Healthcheck)

Tests:

- Ensure State.Health is not present if container status is "created"
- Ensure Config.Healthcheck is present and values correct
- Ensure State.Health is present if container started

Signed-off-by: Milivoje Legenovic <m.legenovic@gmail.com>
2021-08-03 15:38:04 +02:00
cdoern 6ecdf4c389 Health Check is not handled in the compat LibpodToContainerJSON
Added parsing and handling for the healthCheck status within containers.go. Also modified tests

fixes #10457

Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
2021-06-23 13:16:19 -04:00
Matej Vasek dd98e70302 fix: use UTC Time Stamps in response JSON
Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-05-10 11:21:14 +02:00
Paul Holzinger f185666da8 compat api: Networks must be empty instead of null
The compat endpoint for container inspect must return {} instead of null
for NetworkSettings.Networks.

Fixes #9837

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-05-04 11:25:12 +02:00
SoMuchForSubtlety 2df5c6383f Fix removal race condition in ListContainers
It is possible that a container is removed between fetching the
initial list of containers and the second access during conversion.

Closes #10120

[NO TESTS NEEDED]

Signed-off-by: Jakob Ahrer <jakob@ahrer.dev>
2021-04-23 10:14:19 +02:00
Jakub Guzik 907b34c46f Fix containers list/prune http api filter behaviour
The problem described in #9711 and followed by #9758 affects
containers as well. When user provides wrong filter input, error
message should occur, not fallback to full list/prune command.
This change fixes the issue. Additionally, there are error message
fixes for docker http api compat.

Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
2021-03-20 22:56:01 +01:00
Daniel J Walsh f1eb8e8162
Removing a non existing container API should return 404
Currently we were overwrapping error returned from removal
of a non existing container.

$ podman rm bogus -f
Error: failed to evict container: "": failed to find container "bogus" in state: no container with name or ID bogus found: no such container

Removal of wraps gets us to.

./bin/podman rm bogus -f
Error: no container with name or ID "bogus" found: no such container

Finally also added quotes around container name to help make it standout
when you get an error, currently it gets lost in the error.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-03-10 04:08:29 -05:00
baude 8f2192922d Add network summary to compat ps
The compatibility endpoint for listing containers should have the
summarized network configuration with it.

Fixes: #9529

Signed-off-by: baude <bbaude@redhat.com>
2021-03-03 08:16:58 -06:00
Milivoje Legenovic 8b7caa6d04 Compat api containers/json Ports field is null
Fixes #9553

Signed-off-by: Milivoje Legenovic <m.legenovic@gmail.com>
2021-03-02 02:50:41 +01:00
Valentin Rothberg 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
Matej Vasek 4a219aa234 Implement Docker wait conditions
Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-02-03 22:10:27 +01:00
Daniel J Walsh d87f54fbba
Fix invalid wait condition on kill
When using the compatability tests on kill, the kill
function goes into an infinite wait loop taking all of the CPU.

This change will use the correct wait function and exit properly.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-02-03 07:56:13 -05:00
OpenShift Merge Robot 81a3ba36ae
Merge pull request #9051 from rhatdan/rm
Switch podman stop/kill/wait handlers to use abi
2021-02-01 08:47:54 -05:00
Milivoje Legenovic 51c11fea8b Endpoint that lists containers does not return correct Status value
Eclipse and Intellij Docker plugin determines the state of the
container via the Status field, returned from /containers/json call.
Podman always returns empty string, and because of that, both IDEs
show the wrong state of the container.

Signed-off-by: Milivoje Legenovic <m.legenovic@gmail.com>
2021-01-31 21:06:39 +01:00
Daniel J Walsh 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
Daniel J Walsh 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
OpenShift Merge Robot 55982295dd
Merge pull request #9036 from baude/composelog
Set log driver for compatibility containers
2021-01-21 05:48:38 -05:00
baude f430467453 Set log driver for compatability containers
when using the compatibility api to create containers, now reflect the
use of k8s-file as json-file so that clients, which are
unaware of k8s-file, can work.  specifically, if the container is using
k8s-file as the log driver, we change the log type in container
inspection to json-file.  These terms are used interchangably in other
locations in libpod/podman.

this fixes log messages in compose as well.

[NO TESTS NEEDED]

Signed-off-by: baude <bbaude@redhat.com>
2021-01-20 13:07:31 -06:00
Daniel J Walsh e7df73efad
Fix handling of container remove
I found several problems with container remove

podman-remote rm --all
Was not handled

podman-remote rm --ignore
Was not handled

Return better errors when attempting to remove an --external container.
Currently we return the container does not exists, as opposed to container
is an external container that is being used.

This patch also consolidates the tunnel code to use the same code for
removing the container, as the local API, removing duplication of code
and potential problems.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-01-20 07:37:13 -05:00
Matthew Heon 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