Commit Graph

1209 Commits

Author SHA1 Message Date
Jan Rodák a1249425bd
Configure HealthCheck with `podman update`
New flags in a `podman update` can change the configuration of HealthCheck when the container is started, without having to restart or recreate the container.

This can help determine why a given container suddenly started failing HealthCheck without interfering with the services it provides. For example, reconfigure HealthCheck to keep logs longer than the usual last X results, store logs to other destinations, etc.

Fixes: https://issues.redhat.com/browse/RHEL-60561

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-11-19 19:44:14 +01:00
openshift-merge-bot[bot] f8ac02d44e
Merge pull request #24277 from mi4r/dev/mi4r/ImagesImportFix
api: Move close function in condition body
2024-11-07 13:18:24 +00:00
Tigran Sogomonian 9f5bbecb95 api: Add error check
Add error check during tmpfile close.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Tigran Sogomonian <tsogomonian@astralinux.ru>
2024-11-07 14:53:15 +03:00
Paul Holzinger 9a0c0b2eef
volume ls: fix race that caused it to fail
If volume ls was called while another volume was removed at the right
time it could have failed with "no such volume" as we did not ignore
such error during listing. As we list things and this no longer exists
the correct thing is to ignore the error and continue like we do with
containers, pods, etc...

This was pretty easy to reproduce with these two commands running in
different terminals:
while :; do bin/podman volume create test && bin/podman volume rm test || break; done
while :; do bin/podman volume ls || break ; done

I have a slight feeling that this might solve #23913 but I am not to
sure there so I am not adding a Fixes here.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-06 12:28:52 +01:00
Paul Holzinger e6d987882e
API: container logs flush status code
API clients expect the status code quickly otherwise they can time out.
If we do not flush we may not write the header immediately and only when
futher logs are send.

Fixes #23712

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-01 18:54:13 +01:00
Paul Holzinger 768ad8653a
rework event code to improve API errors
One of the problems with the Events() API was that you had to call it in
a new goroutine. This meant the the error returned by it had to be read
back via a second channel. This cuased other bugs in the past but here
the biggest problem is that basic errors such as invalid since/until
options were not directly returned to the caller.
It meant in the API we were not able to write http code 200 quickly
because we always waited for the first event or error from the
channels. This in turn made some clients not happy as they assume the
server hangs on time out if no such events are generated.

To fix this we resturcture the entire event flow. First we spawn the
goroutine inside the eventer Read() function so not all the callers have
to. Then we can return the basic error quickly without the goroutine.
The caller then checks the error like any normal function and the API
can use this one to decide which status code to return.
Second we now return errors/event in one channel then the callers can
decide to ignore or log them which makes it a bit more clear.

Fixes c46884aa93 ("podman events: check for an error after we finish reading events")
Fixes #23712

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-01 18:54:13 +01:00
openshift-merge-bot[bot] f4227e887c
Merge pull request #24275 from Luap99/wait-condition
libpod API: only return exit code without conditions
2024-10-22 10:53:12 +00:00
Paul Holzinger 768aaadca1
libpod API: only return exit code without conditions
The special handling to return the exit code after the container has
been removed should only be done if there are no special conditions
requested. If a user asked for running or nay other state returning the
exit code immediately with a success response is just wrong. We only
want to allow that so the remote client can fetch the exit code without
races.

Fixes b3829a2932 ("libpod API: make wait endpoint better against rm races")

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-10-15 18:31:36 +02:00
Tigran Sogomonian c05987ddd3 api: Replace close function in condition body
The close is replaced in the body of the error condition.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Tigran Sogomonian <tsogomonian@astralinux.ru>
2024-10-15 17:00:47 +03:00
Zachary Hanham feb46513f0 scp: add option types
Prior to this commit, many scp functions existed without option structs, which would make extending functionality (adding new options) impossible without breaking changes, or without adding redundant wrapper functions.

This commit adds in new option types for various scp related functions, and changes those functions' signatures to use the new options.

This commit also modifies the `ImageEngine.Scp()` function's interface to use the new opts.

The commit also renames the existing `ImageScpOptions` entity type to `ScpTransferImageOptions`. This is because the previous `ImageScpOptions` was inaccurate, as it is not the actual options for `ImageEngine.Scp()`. `ImageEngine.Scp()` should instead receive `ImageScpOptions`.

This commit should not change any behavior, however it will break the existing functions' signatures.

Signed-off-by: Zachary Hanham <z.hanham00@gmail.com>
2024-10-14 21:46:55 -04:00
Paul Holzinger b3829a2932
libpod API: make wait endpoint better against rm races
In the common scenario of podman-remote run --rm the API is required to
attach + start + wait to get exit code. This has the problem that the
wait call races against the container removal from the cleanup process
so it may not get the exit code back. However we keep the exit code
around for longer than the container so  we can just look it up in the
endpoint. Of course this only works when we get a full id as param but
podman-remote will do that.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-10-08 18:03:15 +02:00
openshift-merge-bot[bot] 30a25a0d3d
Merge pull request #24135 from Luap99/vendor
vendor: update c/common and buildah
2024-10-04 13:14:43 +00:00
Ed Santiago 043b82ef59
Fixes for vendoring Buildah
This commit was automatically cherry-picked
by buildah-vendor-treadmill v0.3
from the buildah vendor treadmill PR, #13808

  * Fix conflict caused by Ed's local-registry PR in buildah
  * Wire in "new" --retry and --retry-delay, these existed for longer
    but where non functional.

Signed-off-by: Ed Santiago <santiago@redhat.com>
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-10-02 18:38:38 +02:00
Matt Heon edc3dc5e11 Add ExposedPorts to Inspect's ContainerConfig
A field we missed versus Docker. Matches the format of our
existing Ports list in the NetworkConfig, but only includes
exposed ports (and maps these to struct{}, as they never go to
real ports on the host).

Fixes https://issues.redhat.com/browse/RHEL-60382

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-10-01 07:54:52 -04:00
fixomatic-ctrl 1dd90dbe20
feat(libpod): support kube play tar content-type (#24015)
feat(libpod): support kube play tar content-type

Signed-off-by: fixomatic-ctrl <180758136+fixomatic-ctrl@users.noreply.github.com>
2024-09-27 15:40:55 +02:00
Jan Rodák de856dab99
Add --health-max-log-count, --health-max-log-size, --health-log-destination flags
These flags can affect the output of the HealtCheck log. Currently, when a container is configured with HealthCheck, the output from the HealthCheck command is only logged to the container status file, which is accessible via `podman inspect`.
It is also limited to the last five executions and the first 500 characters per execution.

This makes debugging past problems very difficult, since the only information available about the failure of the HealthCheck command is the generic `healthcheck service failed` record.

- The `--health-log-destination` flag sets the destination of the HealthCheck log.
  - `none`: (default behavior) `HealthCheckResults` are stored in overlay containers. (For example: `$runroot/healthcheck.log`)
  - `directory`: creates a log file named `<container-ID>-healthcheck.log` with JSON `HealthCheckResults` in the specified directory.
  - `events_logger`: The log will be written with logging mechanism set by events_loggeri. It also saves the log to a default directory, for performance on a system with a large number of logs.

- The `--health-max-log-count` flag sets the maximum number of attempts in the HealthCheck log file.
  - A value of `0` indicates an infinite number of attempts in the log file.
  - The default value is `5` attempts in the log file.
- The `--health-max-log-size` flag sets the maximum length of the log stored.
  - A value of `0` indicates an infinite log length.
  - The default value is `500` log characters.

Add --health-max-log-count flag

Signed-off-by: Jan Rodák <hony.com@seznam.cz>

Add --health-max-log-size flag

Signed-off-by: Jan Rodák <hony.com@seznam.cz>

Add --health-log-destination flag

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-09-25 14:01:35 +02:00
openshift-merge-bot[bot] 62c101651f
Merge pull request #23857 from rhatdan/run
Remove containers/common/pkg/config from pkg/util
2024-09-17 20:31:28 +00:00
Matt Heon e04668c8ca Match output of Compat Top API to Docker
We were only splitting on tabs, not spaces, so we returned just a
single line most of the time, not an array of the fields in the
output of `ps`. Unfortunately, some of these fields are allowed
to contain spaces themselves, which makes things complicated, but
we got lucky in that Docker took the simplest possible solution
and just assumed that only one field would contain spaces and it
would always be the last one, which is easy enough to duplicate
on our end.

Fixes #23981

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-09-17 11:34:22 -04:00
Daniel J Walsh eb396705c6
Remove containers/common/pkg/config from pkg/util
Probably has to wait for V6

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-09-06 07:45:04 -04:00
flouthoc 901f621daa
prune: support clearing build cache using CleanCacheMount
`podman builder prune` and `podman image prune` should also support
cleaning build cache using buildah's public `CleanCacheMount` API.

Reference: https://docs.docker.com/reference/cli/docker/builder/prune/
Context: https://github.com/containers/podman/discussions/15612#discussioncomment-10532721
Context: https://github.com/containers/buildah/pull/4490

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2024-09-05 10:40:07 -07:00
Paul Holzinger bf74797c69
fix races in the HTTP attach API
This is very similar to commit 3280da0500, we cannot check the state
then unlock to then lock again and do the action. Everything must
happen under one lock. To fix this move the code into the HTTPAttach
function in libpod. The locking here is a bit weird because attach
blocks for the lifetime of attach which can be very long so we must
unlock before performing the attach.

Fixes #23757

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-08-27 15:00:08 +02:00
Matt Heon 458ba5a8af Fix `podman stop` and `podman run --rmi`
This started off as an attempt to make `podman stop` on a
container started with `--rm` actually remove the container,
instead of just cleaning it up and waiting for the cleanup
process to finish the removal.

In the process, I realized that `podman run --rmi` was rather
broken. It was only done as part of the Podman CLI, not the
cleanup process (meaning it only worked with attached containers)
and the way it was wired meant that I was fairly confident that
it wouldn't work if I did a `podman stop` on an attached
container run with `--rmi`. I rewired it to use the same
mechanism that `podman run --rm` uses, so it should be a lot more
durable now, and I also wired it into `podman inspect` so you can
tell that a container will remove its image.

Tests have been added for the changes to `podman run --rmi`. No
tests for `stop` on a `run --rm` container as that would be racy.

Fixes #22852
Fixes RHEL-39513

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-08-20 09:51:18 -04:00
Paul Holzinger 942f789a88
set !remote build tags where needed
The new golangci-lint version 1.60.1 has problems with typecheck when
linting remote files. We have certain pakcages that should never be
inlcuded in remote but the typecheck tries to compile all of them but
this never works and it seems to ignore the exclude files we gave it.

To fix this the proper way is to mark all packages we only use locally
with !remote tags. This is a bit ugly but more correct. I also moved the
DecodeChanges() code around as it is called from the client so the
handles package which should only be remote doesn't really fit anyway.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-08-19 11:41:28 +02:00
Daniel J Walsh a06a7d7ba8
Should not force conversion of manifest type to DockerV2ListMediaType
Fixes: https://github.com/containers/podman/issues/23163

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-08-07 06:07:46 -04:00
tomsweeneyredhat b8a9b184af Add --compat-volumes option to build and farm build
Add the `--compat-volumes option from Buildah v1.37 into
Podman in preparation of Podman v5.2

Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
2024-07-30 18:26:13 -04:00
Paul Holzinger 1b91df012d
pkg/api: do not leak config pointers into specgen
The value of the pointer might be changed while creating the container
causing unexpected side effects.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-07-29 15:12:55 +02:00
openshift-merge-bot[bot] 34d93d6502
Merge pull request #23321 from rhatdan/build
More information for podman --remote build and running out of space.
2024-07-24 20:48:52 +00:00
Giuseppe Scrivano f70976a7e2
api: honor the userns for the infra container
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-07-24 13:36:13 +02:00
Daniel J Walsh 7768cf235e
Run codespell on source
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-07-23 07:28:23 -04:00
Daniel J Walsh 174190132c
More information for podman --remote build and running out of space.
Users do not realize that the entire context directory is being copied
into the podman machine when doing a podman --remote build.

Adding information about the context directory might help them
understand this.

Improves: https://github.com/containers/podman/issues/23287

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-07-22 08:13:09 -04:00
openshift-merge-bot[bot] 2f673aa8f7
Merge pull request #23258 from Luap99/start-error
fix race conditions in start/attach logic
2024-07-15 12:11:56 +00:00
Paul Holzinger 3280da0500
fix race conditions in start/attach logic
The current code did something like this:
lock()
getState()
unlock()

if state != running
  lock()
  getState() == running -> error
  unlock()

This of course is wrong because between the first unlock() and second
lock() call another process could have modified the state. This meant
that sometimes you would get a weird error on start because the internal
setup errored as the container was already running.

In general any state check without holding the lock is incorrect and
will result in race conditions. As such refactor the code to combine
both StartAndAttach and Attach() into one function that can handle both.
With that we can move the running check into the locked code.

Also use typed error for this specific error case then the callers can
check and ignore the specific error when needed. This also allows us to
fix races in the compat API that did a similar racy state check.

This commit changes slightly how we output the result, previously a
start on already running container would never print the id/name of the
container which is confusing and sort of breaks idempotence. Now it will
include the output except when --all is used. Then it only reports the
ids that were actually started.

Fixes #23246

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-07-12 15:11:34 +02:00
Paul Holzinger e24367aa14
update to docker 27
Fixes compile issues with new docker changes, then fix all the new
depreciation warnings.
Also there seem to be larger pre-existing problems with the
/containers/json API output as the HostConfig field seems to be missing
but I don't have time to deal with that currently.

Note this does not include changes for the new docker API 1.46.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-07-12 14:00:29 +02:00
Paul Holzinger a3d5842746
build API: accept platform comma separated
The docker API uses only a single arg for platform and multiple
platforms are given as comma separated list.

Fixes #22071

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-06-25 18:48:59 +02:00
Paul Holzinger e404976d1b
remote API: fix pod top error reporting
Do not return 200 status code before we know if there will be an error.
Delay writing the status code until we send the first response. That way
we can set an error code inside the loop when we get a error on the
first try, i.e. because an invalid descriptor was used.

Fixes #22986

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-06-24 13:47:01 +02:00
Paul Holzinger 29ecf5984c
libpod API: return proper error status code for pod start
When we failed to do anything we should return 500, the 409 code has a
special meaing to the client as it uses a different error format. As
such the remote client was not able to unmarshal the error correctly and
just returned an empty string.

Fixes #22989

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-06-24 13:46:55 +02:00
Nalin Dahyabhai fec58a4571 Add `podman system check` for checking storage consistency
Add a `podman system check` that performs consistency checks on local
storage, optionally removing damaged items so that they can be
recreated.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-06-04 10:00:37 -04:00
Daniel J Walsh 4adb5cbbff
Fail earlier when no containers exist in stats
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-05-29 06:38:56 -04:00
jkwiatko b45364254f working name of pod on start and stop
Signed-off-by: jkwiatko <jkwiatkoski@protonmail.com>
2024-05-25 19:40:21 -04:00
openshift-merge-bot[bot] cc79d5e82e
Merge pull request #22700 from Luap99/libpod-inspect-API-v4
remote API: restore v4 payload in container inspect
2024-05-22 12:32:29 +00:00
Daniel J Walsh 6408a05927
Return StatusNotFound when multiple volumes matching occurs
Fixes #22616

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-05-15 06:21:14 -04:00
Nalin Dahyabhai c46884aa93 `podman events`: check for an error after we finish reading events
The function that's handing us events will return an error after closing
the channel over which it's sending events, and its caller (in its own
goroutine) will then send that error over another channel.

The logic that started the goroutine is likely to notice that the events
channel is closed before noticing that the error channel has a result
for it to read, so any error that would have been communicated would be
lost.

When we finish reading events, check if the reader returned an error
before telling our caller that there was no error.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-05-14 13:18:51 -04:00
Paul Holzinger bcb7edfded
remote API: restore v4 payload in container inspect
The v5 API made a breaking change for podman inspect, this means that
an old client could not longer parse the result from the new 5.X server.
The other way around new client and old server already worked.

As it turned out there were several users that run into this, one case
to hit this is using an old 4.X podman machine wich now pulls a newer
coreos with podman 5.0. But there are also other users running into it.
In order to keep the API working we now have a version check and return
the old v4 compatible payload so the old remote client can still work
against a newer server thus removing any major breaking change for an
old client.

Fixes #22657

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-05-14 17:56:20 +02:00
WxNzEMof 7bfac4f349 Don't panic if a runtime was configured without paths
Signed-off-by: WxNzEMof <143541718+WxNzEMof@users.noreply.github.com>
2024-05-08 12:44:38 +00:00
openshift-merge-bot[bot] c2cadfb5c5
Merge pull request #22322 from mheon/update_the_config
Make `podman update` changes persistent
2024-04-22 07:50:48 +00:00
Giuseppe Scrivano bd00c6fef9
pkg/api: use fileutils.(Le|E)xists
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-19 09:52:14 +02:00
Matt Heon 482ef7bfcf Add support for updating restart policy
This is something Docker does, and we did not do until now. Most
difficult/annoying part was the REST API, where I did not really
want to modify the struct being sent, so I made the new restart
policy parameters query parameters instead.

Testing was also a bit annoying, because testing restart policy
always is.

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-04-17 08:23:51 -04:00
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
Brent Baude 08a49389c8 Add os, arch, and ismanifest to libpod image list
when listing images through the restful service, consumers want to know
if the image they are listing is a manifest or not because the libpod
endpoint returns both images and manifest lists.

in addition, we now add `arch` and `os` as fields in the libpod endpoint
for image listing as well.

Fixes: #22184
Fixes: #22185

Signed-off-by: Brent Baude <bbaude@redhat.com>
2024-04-11 08:46:37 -05:00
Paul Holzinger 999d6c0750
fix "concurrent map writes" in network ls compat endpoint
Not sure why this only triggers now but this code was broken for a
while. It is racy as reported on the issue but because it changes the
actual map part of the network backend it means it can also alter the
behavior of the network which is very bad.

Fixes #22330

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-04-10 18:41:20 +02:00