Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/config: add CONTAINERS_CONF_OVERRIDE #1378

Merged

Conversation

vrothberg
Copy link
Member

Add yet another environment variable for loading containers.conf. When CONTAINERS_CONF_OVERRIDE is set, the specified config file will be loaded last - even when CONTAINERS_CONF is set.

This mechanism is needed to preserve system settings and other environment variables. Setting CONTAINERS_CONF will load only the specified config file and ignore all system and user paths. That makes testing hard as many Podman tests use CONTAINERS_CONF for testing.

The intended use of CONTAINERS_CONF_OVERRIDE is to set it during tests and point it to a specific configuration of Podman (e.g., netavark with sqlite backend).

Similar needs have popped up talking to users in the automotive and high-performance computing space. In a way, such a setting allows for specifying a specific "flavor" of Podman while preserving all existing settings on the system.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Mar 23, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vrothberg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vrothberg
Copy link
Member Author

Accompanying Podman PR: containers/podman#17895

@vrothberg
Copy link
Member Author

@edsantiago @rhatdan @mheon @baude this is how imagine it to look like. It will ultimately solve the shortcomings in testing and should also simplify gating tests which can now quite easily test the various of flavors of network and database backends etc.

@rhatdan
Copy link
Member

rhatdan commented Mar 23, 2023

Bikeshed, CONTAINERS_CONF_OVERRIDE environment name seems to match what CONTAINERS_CONF currently does.
CONTAINERS_CONF_SUPPLIMENT, CONTAINERS_CONF_ADD, CONTAINERS_CONF_D?

@vrothberg
Copy link
Member Author

Bikeshed, CONTAINERS_CONF_OVERRIDE environment name seems to match what CONTAINERS_CONF currently does. CONTAINERS_CONF_SUPPLIMENT, CONTAINERS_CONF_ADD, CONTAINERS_CONF_D?

I first had _ADD then I had _EXTRA but in the end I gravitated toward _OVERRIDE as I found it to best describe what it does: it overrides any other config, whether it's a system or user config or even CONTAINERS_CONF.

But I am not married to _OVERRIDE.

pkg/config/config.go Outdated Show resolved Hide resolved
@rhatdan
Copy link
Member

rhatdan commented Mar 23, 2023

I am fine with sticking with _OVERRIDE, since this is mainly for testing and is well documented.

@vrothberg vrothberg force-pushed the containers_conf_extra branch 2 times, most recently from b44e9c6 to 0df99c5 Compare March 23, 2023 10:31
defer os.Unsetenv("CONTAINERS_CONF_OVERRIDE")
config, err := NewConfig("")
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(config.Containers.ApparmorProfile).To(gomega.Equal("overridden-default"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's pretend that the OVERRIDE code breaks, and becomes equivalent to $CONTAINERS_CONF (i.e. ignoring existing conf). This test would happily pass.

Suggestion: include a test for a known-good setting, something that containers_override.conf does not explicitly set. (I don't know what environment this test runs in. It might be necessary to add this new check after line 929 below, something that is set in containers_default.conf). Left as exercise for the reader.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! I added a check for a value that only the default.conf sets 👍

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the naming is not perfect but I cannot think of anything better.

Add yet another environment variable for loading containers.conf.
When CONTAINERS_CONF_OVERRIDE is set, the specified config file
will be loaded last - even when CONTAINERS_CONF is set.

This mechanism is needed to preserve system settings and other
environment variables.  Setting CONTAINERS_CONF will load only
the specified config file and ignore all system and user paths.
That makes testing hard as many Podman tests use CONTAINERS_CONF
for testing.

The intended use of CONTAINERS_CONF_OVERRIDE is to set it during tests
and point it to a specific configuration of Podman (e.g., netavark with
sqlite backend).

Similar needs have popped up talking to users in the automotive and
high-performance computing space.  In a way, such a setting allows for
specifying a specific "flavor" of Podman while preserving all existing
settings on the system.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
@vrothberg vrothberg force-pushed the containers_conf_extra branch from 0df99c5 to 1665db7 Compare March 23, 2023 12:48
@vrothberg vrothberg marked this pull request as ready for review March 23, 2023 12:49
@vrothberg
Copy link
Member Author

Good to go from my end. @rhatdan @edsantiago feel free to merge.

@baude
Copy link
Member

baude commented Mar 23, 2023

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Mar 23, 2023
@openshift-merge-robot openshift-merge-robot merged commit 03a2cc0 into containers:main Mar 23, 2023
@vrothberg vrothberg deleted the containers_conf_extra branch March 23, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants