Commit Graph

144 Commits

Author SHA1 Message Date
Paul Holzinger 32003de258 pkg/config: fix verify getDefaultEnv test flake
Do not use Default() in unit tests, that caches the config in a global
var so it conflicts with other tests also calling it.

Now only the Reload test should test that. The Default() call got broken
by commit c2dee68766 because now the test only unsets the env after the
last Reload() call which should already use the actual default.

Fixes: c2dee68766 ("*_test.go: use t.TempDir, t.Setenv")

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-04-23 13:58:24 +02:00
Kir Kolyshkin a8b49e830a Use t.TempDir for tests
Instead of using os.MkdirTemp in tests, use t.TempDir.

In a few places where the parent directory is already create by t.TempDir,
replace os.MkdirTemp with os.Mkdir.

While at it, make sure to not a leak opened file descriptor returned by
os.CreateTemp.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-14 11:16:55 -07:00
Kir Kolyshkin c2dee68766 Use t.Setenv in tests
Using os.Setenv in tests is problematic, because the change is
process-wise and other tests running in parallel might be affected.
Also, a somewhat complicated cleanup is needed.

Both issues are solved by using t.Setenv.

This commit also uses t.TempDir, t.Cleanup, and t.Helper when it makes
sense.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-14 11:16:55 -07:00
Doug Rabson 2b75c29931 pkg/config: make Capabilities() a no-op stub on non-linux platforms
This fixes 'podman build' and 'buildah build' on non-linux platforms
where (*Config).Capabilities started throwing errors after the
pkg/capabilities package started using github.com/moby/sys/capability to
validate the capability lists.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2025-02-17 14:32:11 +00:00
George Joseph be77cc4e2d Allow Podman to send the container's hostname to Netavark
* Added ContainerHostname to NetworkOptions. Podman will set this
  and Netavark will read it.

* Added the `container_name_as_hostname` option to the
  CONTAINERS table in containers.conf.  Currently, if you don't
  explicitly set a hostname when creating a container, podman will
  set it to the short ID. If this option set to `true` and a
  hostname isn't explicitly set, podman will use the container's
  name, with characters not in the set `[0-9a-zA-Z.-]` removed,
  as the hostname instead of the short ID. Set to false by default
  to preserve existing behavior.

Signed-off-by: George Joseph <g.devel@wxy78.net>
2024-11-28 13:35:36 -07:00
Paul Holzinger f3f39c4c05 replace k8s.gcr.io with registry.k8s.io
We see issues in CI where we fail to pull from k8s.gcr.io. As k8s uses a
new registry URL migrate to that[1] and hope it fixes the issues.

[1] https://kubernetes.io/blog/2023/02/06/k8s-gcr-io-freeze-announcement/

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-06-18 11:37:12 +02:00
phoenix 3ca51acd6e Add configuration for podmansh
Adds a new configuration section `podmansh` to configure the shell,
container and the timeout for podmansh.

Signed-off-by: phoenix <felix.niederwanger@suse.com>
2024-05-22 13:32:15 +02:00
Paul Holzinger 37be881563 pkg/config: add new healthcheck_events field
Some users wish to turn of healthcheck events in Podman so add a config
option to allow that. The actual logic must live in Podman.

Link: https://issues.redhat.com/browse/RHEL-18987

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-04-17 16:23:45 +02:00
Daniel J Walsh 6ce9df9f83 Simplify PullPolicy handling
Add support for ifmissing

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-03-21 08:00:57 +01:00
Paul Holzinger 4a7a8a3496 lint: enable ginkgolinter
This linter creates better assertions in ginkgo tests.
Fixes were made with `ginkgolinter -fix ./...`.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-03-18 11:51:54 +01:00
Daniel J Walsh c580f4054c Config for Retry and RetryDelay for pulling images
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-02-20 14:43:17 -05:00
openshift-merge-bot[bot] de2048e605 Merge pull request #1826 from Luap99/connections
pkg/config: rework system connections and farm storage
2024-01-30 13:55:29 +00:00
openshift-merge-bot[bot] 98967283dc Merge pull request #1820 from mheon/no_bind_image_vols
Change default image volume mode to "anonymous"
2024-01-29 16:11:14 +00:00
Paul Holzinger 330f41d7a2 pkg/config: add new connections.conf file
podman systemd conenction and farm currently both write containers.conf
to store their settings. Each write removes comments from the user
config file and thus makes it not great to use.

The new approach is to have a seperate file connections.conf (json
format) to store both conenctions and farms for podman. We continue to
read containers.conf for the connections and farms as well and podman
can read both. This means we have a read only store in containers.conf
(manually added by users), they cannot be removed by the podman cli.

This is a breaking chnage and will require many chnages in podman to
migrate to the new APIs added in this commit.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-01-29 17:05:03 +01:00
Paul Holzinger 21d3f3431f pkg/config: remove unnecessary stat on default paths
The current code has a small race it first stats the file and if it
exists it tries to read the file. Between this it is possible that the
file was removed and thus cause a fatal error when reading the config.
The better way is to simply read the file and ignore the ENOENT error
instead where we want this behavior. This avoids the need for the extra
stat syscalls. For CONTAINERS_CONF and modules we still need the hard
error if the file does not exists so we have to keep it there.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-01-29 16:28:06 +01:00
Paul Holzinger 745268b117 pkg/config: use containersConfEnv constant everywhere
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-01-29 16:28:06 +01:00
Vikas Goel 9b0147a1ae New global option interface_name in containers.conf
Add a new containers.conf attribute to define how to set interface name inside containers.

Relates to: containers/podman#21313

Signed-off-by: Vikas Goel <vikas.goel@gmail.com>
2024-01-25 07:11:33 -08:00
Matt Heon 1f16fa5f34 Change default image volume mode to "anonymous"
We have not supported type=bind image volumes since pre-1.0
Podman - we phased them out when we added support for actual
volumes. Also, our image volume valid modes checker did not even
allow the actual default (anonymous). This is technically a
breaking change, so it will go into Podman 5.0 - but I strongly
doubt anyone is actually using this field if no one has noticed
this issue before now.

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-01-24 09:42:06 -05:00
Lokesh Mandvekar af01fda323 containers.conf: add crun-vm as a runtime
Signed-off-by: Lokesh Mandvekar <lsm5@redhat.com>
2024-01-19 18:15:33 +05:30
Valentin Rothberg cd2797eb34 pkg/config: use NewSlice, Get and Set where possible
To improve the code and reduce memory allocations.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 10:04:20 +02:00
Valentin Rothberg e212082542 pkg/config: turn machine Volumes into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 5fb9ed7f84 pkg/config: turn NetavarkPluginDirs into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 67a73c7cc6 pkg/config: turn CNIPluginDirs into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 89b8572671 pkg/config: turn AddCompression into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg cad0135389 pkg/config: turn NetworkCmdOptions into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 8a06b6cb94 pkg/config: turn HelperBinariesDir into attributedstring.Slice
Also tag it as omitempty to fix the test.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg 12bde4bc00 pkg/config: turn Capabilities into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg bde9e751dc pkg/config: turn CgroupConf into attributedstring.Slice
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg b8c3014c2a pkg/config: turn devices into attributedstring.Slice
The tests are messy and should be turned into table-driven tests but I
do not have time at the moment.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-26 09:17:22 +02:00
Valentin Rothberg b103cb9e93 containers.conf: appendable string arrays, Part 1
Commit 395ba05c44 implemented a POC to allow for changing the behavior
when loading multiple container.conf files in sequence.  By default, the
TOML encoder will override existing data/fields with the one specified
in the loaded file.  The POC has demonstrated how this behavior can be
changed to append string slices instead of overriding/replacing them
entirely.

This change is the first step of integrating these appendable string
arrays into containers.conf and starts with enabling the `Env`,
`Mounts`, and `Volumes` fields in the `[Containers]` table.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-24 11:47:46 +02:00
Paul Holzinger 6a79383d51 pkg/config: use empty default for db_backend
Podman should default to sqlite for new installs, however to not break
upgrades we should detect if a boltdb database exists and use that in
such case. Now in order to distinguish between an explicitly set
"sqlite" and "boltdb" and nothing set we use an empty default.

With that podman can know if we really should use the default or if it
was configured for a db explicitly. The actual detection logic must be
implemented in podman as we only know the file locations there.

This commit also drops the unused StateType as this was not used at all.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-10-10 15:57:52 +02:00
Valentin Rothberg ac851d5930 containers.conf: add `privileged` field to containers table
As requested in containers/podman/issues/20000, add a `privileged` field
to the containers table in containers.conf.  I was hesitant to add such
a field at first (for security reasons) but I understand that such a
field can come in handy when using modules - certain workloads require a
privileged container.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-10-05 13:22:35 +02:00
Chetan Giradkar 819434a2ea Remove ActiveDestination method to move into podman
The method ActiveDestination was being used only by Podman and there seemed to code complications as the code is split in multiple parts. Hence, moved the code to Podman to make it more readable and efficient.

Signed-off-by: Chetan Giradkar <cgiradka@redhat.com>
2023-09-20 13:29:52 +01:00
Aditya R 359ff162d0 containers.conf: add field for AddCompression to Engine table
Allows users to set default value of `AddCompression` to Engine table so
users can use https://github.com/containers/buildah/pull/4912 by
default.

Closes: https://github.com/containers/buildah/pull/4912#issuecomment-1661105029

Signed-off-by: Aditya R <arajan@redhat.com>
2023-08-24 17:10:06 +05:30
Valentin Rothberg 961863eab1 pkg/config: tests: do not load default config before each test
It's wasteful and `sut` was not a name I would now understand. Change
the tests that need a default config.  The diff also shows that the
tests would benefit a lot from a rewrite into a table-driven form but I
do not want to shave the entire Yak.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-08-14 09:40:27 +02:00
Valentin Rothberg e00d7e3560 pkg/config: unexport DefaultConfig
It has no external user and should not be exported to avoid any API
misuse; built-in defaults are an implementation detail.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-08-14 09:40:27 +02:00
OpenShift Merge Robot 8694484524 Merge pull request #1586 from umohnani8/farms
Add Farms to config
2023-08-05 04:34:23 +02:00
Urvashi Mohnani a489f0261c Update system connection to add to farm
A new --farm flag is being added to podman system connection
add so that when a new connection is added it can be added to a new
or existing farm. Update the code here to be able to do that.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2023-08-03 09:53:55 -04:00
Urvashi Mohnani 42a36d1ba1 Add Farms TOML table
Add two new fields Farms and DefaultFarm to the Config
to be used by the new podman buildfarm command.

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2023-08-03 09:53:48 -04:00
Daniel J Walsh cdb801ec18 We don't want TERM environment turned on by default
This should only be done in container-engines that are using a
terminal.

Reverts: https://github.com/containers/common/pull/267

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-07-31 11:33:28 -04:00
Daniel J Walsh 19a6a187a9 Allow mounts to be specified in containers.conf
We want to allow HPC Customers and others to specify mounts
inside of containers.conf, so that they can have a default
list of mounts into all of thier containers.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-07-25 15:06:08 -04:00
Doug Rabson 478419732a Change default image volume mode to "nullfs" on FreeBSD
This fixes a regression in
https://github.com/containers/podman/pull/19241 which quite reasonably
assumed that the default image volume mode from pkg/config was correct.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2023-07-17 14:58:23 +01:00
Lokesh Mandvekar 4bb9e26054 containers.conf: Add `podmansh_timeout`
Ref: https://github.com/containers/podman/pull/19140#discussion_r1254435823

Signed-off-by: Lokesh Mandvekar <lsm5@fedoraproject.org>
2023-07-14 15:19:11 -04:00
Giuseppe Scrivano 518758c4c7 config: add CompressionLevel to containers.conf
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-06-21 12:05:52 +02:00
Doug Rabson 5daab4a8cf pkg/config: override DefaultInitPath for FreeBSD
FreeBSD packages typically install files under /usr/local on FreeBSD.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2023-06-12 16:00:37 +01:00
Doug Rabson d68f132c74 pkg/config: fix unit tests for FreeBSD
This just disables the capabilities test - everything else already
passed.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2023-06-12 15:11:50 +01:00
Daniel J Walsh a370cfad72 Add some fixes for CompressionFormat
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-05-30 17:32:27 -04:00
Daniel J Walsh ed8be0d003 Add support for confined SELinux users
The original SELinux support in Docker and Podman does not follow the
default SELinux rules for how label transitions are supposed to be
handled. Containers always switch their user and role to
system_u:system_r, rather then maintain the collers user and role.
For example
unconfined_u:unconfined_r:container_t:s0:c1,c2

Advanced SELinux administrators want to confine users but still allow
them to create containers from their role, but not allow them to launch
a privileged container like spc_t.

This means if a user running as
container_user_u:container_user_r:container_user_t:s0

Ran a container they would get

container_user_u:container_user_r:container_t:s0:c1,c2

If they run a privileged container they would run it with:

container_user_u:container_user_r:container_user_t:s0

If they want to force the label they would get an error

podman run --security-opt label=type:spc_t ...

Should fail. Because the container_user_r can not run with the spc_t.

SELinux rules would also prevent the user from forcing system_u user and
the sytem_r role.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-05-03 15:00:26 -04:00
Paul Holzinger 7966ad46e4 pkg/config: add netavark_plugin_dirs fields
Add config field to specify the location for the netavark plugins.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-04-04 18:20:12 +02:00
Urvashi Mohnani 386adadc84 Add kube_generate_type defaults
Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2023-04-03 18:12:37 -04:00