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

Use paths written in DB instead if they differ from our defaults #1918

Merged
merged 15 commits into from
Dec 5, 2018

Conversation

mheon
Copy link
Member

@mheon mheon commented Dec 2, 2018

Finally have this in satisfying shape.

We encountered a regression a little over a week ago in Podman 0.11.x releases, where some directories' defaults changed for rootless. As we validate critical paths against the database, this caused a breaking change, requiring manual config file creation and editing (or deleting/recreating rootless container storage) to fix.

This resolves the breaking change by using the paths we validate against in the database if libpod would otherwise use default values (IE, the user has not explicitly overridden a setting). This ensures that changes to default paths will be respected for new installs, but existing installs will still continue working as expected. This also applies to the storage graph driver.

This cannot, however, fix situations where the libpod static directory's path changes - in which case we don't find the old DB, and cannot find the old paths. Libpod/Podman will function properly, but all containers/images from the old paths will be lost.

When we create a Libpod database, we store a number of runtime
configuration fields in it. If we can retrieve those, we can use
them to configure the runtime to match the DB instead of inbuilt
defaults, helping to ensure that we don't error in cases where
our compiled-in defaults changed.

Signed-off-by: Matthew Heon <mheon@redhat.com>
When we configure a runtime, we now will need to hit the DB early
on, so we can verify the paths we're going to use for c/storage are correct.

Signed-off-by: Matthew Heon <mheon@redhat.com>
Previously, we implicitly validated runtime configuration against
what was stored in the database as part of database init. Make
this an explicit step, so we can call it after the database has
been initialized. This will allow us to retrieve paths from the
database and use them to overwrite our defaults if they differ.

Signed-off-by: Matthew Heon <mheon@redhat.com>
To configure runtime fields from the database, we need to know
whether they were explicitly overwritten by the user (we don't
want to overwrite anything that was explicitly set). Store a
struct containing whether the variables we'll grab from the DB
were explicitly set by the user so we know what we can and can't
overwrite.

This determines whether libpod runtime and static dirs were set
via config file in a horribly hackish way (double TOML decode),
but I can't think of a better way, and it shouldn't be that
expensive as the libpod config is tiny.

Signed-off-by: Matthew Heon <mheon@redhat.com>
If the DB contains default paths, and the user has not explicitly
overridden them, use the paths in the DB over our own defaults.

The DB validates these paths, so it would error and prevent
operation if they did not match. As such, instead of erroring, we
can use the DB's paths instead of our own.

Signed-off-by: Matthew Heon <mheon@redhat.com>
Previous commits ensured that we would use database-configured
paths if not explicitly overridden.

However, our runtime generation did unconditionally override
storage config, which made this useless.

Move rootless storage configuration setup to libpod, and change
storage setup so we only override if a setting is explicitly
set, so we can still override what we want.

Signed-off-by: Matthew Heon <mheon@redhat.com>
We already create the locks directory as part of the libpod
runtime's init - no need to do it again as part of BoltDB's init.

Signed-off-by: Matthew Heon <mheon@redhat.com>
@mheon
Copy link
Member Author

mheon commented Dec 2, 2018

/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mheon

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 2, 2018
@mheon
Copy link
Member Author

mheon commented Dec 2, 2018

Tested this locally, and it seems to resolve the breaking change we saw in 0.11.1

Ensure we don't break the unit tests by creating a locks
directory (which, prior to the last commit, would be created by
BoltDB state init).

Signed-off-by: Matthew Heon <mheon@redhat.com>
Signed-off-by: Matthew Heon <mheon@redhat.com>
@@ -313,33 +313,31 @@ func getTomlStorage(storeOptions *storage.StoreOptions) *tomlConfig {
return config
}

// GetDefaultStoreOptions returns the storage ops for containers
func GetDefaultStoreOptions() (storage.StoreOptions, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the reason for having this function here is that pkg/util is vendored inside buildah and GetDefaultStoreOptions is used there as well. Do you think it makes sense if we leave it?

Anyway, should not be too difficult to reimplement in Buildah if it is dropped

Copy link
Member

Choose a reason for hiding this comment

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

+1 to a Buildah dependency on this. Great catch @giuseppe

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure - I saw no more internal users, so I modified it to suit our uses, but if Buildah is vendoring it I can revert the changes

libpod/state.go Outdated
// validate runtime configuration.
GetDBConfig() (*DBConfig, error)

// ValidateDBConfig ralidates the config in the given Runtime struct
Copy link
Member

Choose a reason for hiding this comment

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

s|ralidates|validates|

return err
}

if err := validateDBAgainstConfig(configBkt, "run root",
rt.config.StorageConfig.RunRoot, runRoot,
if err := validateDBAgainstConfig(configBkt, "storage temporary directory",
Copy link
Member

Choose a reason for hiding this comment

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

Is this an appropriate description?

@@ -74,31 +79,31 @@ func checkRuntimeConfig(db *bolt.DB, rt *Runtime) error {
return err
}

if err := validateDBAgainstConfig(configBkt, "static dir",
rt.config.StaticDir, staticDir, ""); err != nil {
if err := validateDBAgainstConfig(configBkt, "libpod root directory",
Copy link
Member

Choose a reason for hiding this comment

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

I think it would make sense to have static in this description somehow still.

When validating fields against the DB, report more verbosely the
name of the field being validated if it fails. Specifically, add
the name used in config files, so people will actually know what
to change it errors happen.

Signed-off-by: Matthew Heon <mheon@redhat.com>
Signed-off-by: Matthew Heon <mheon@redhat.com>
Ensure that the directory where we will create the Podman db
exists prior to creating the database - otherwise creating the DB
will fail.

Signed-off-by: Matthew Heon <mheon@redhat.com>
@mheon
Copy link
Member Author

mheon commented Dec 3, 2018

/retest

@mheon
Copy link
Member Author

mheon commented Dec 3, 2018

/retry

@mheon
Copy link
Member Author

mheon commented Dec 3, 2018

Alright. Not sure what's going on with the tests here, but they're passing locally, and Cirrus seems to be working after a retest...

@rhatdan
Copy link
Member

rhatdan commented Dec 3, 2018

I see
error creating libpod runtime: database storage temporary directory (runroot) /run/145827784 does not match our storage temporary directory (runroot) /tmp/podman_test462651597/crio-run: database configuration mismatch
in logs?

@mheon
Copy link
Member Author

mheon commented Dec 3, 2018

/retest

@mheon
Copy link
Member Author

mheon commented Dec 3, 2018

Hm. It looks like the user-set tmp dir is not overriding in the rootless case...

When graphroot is set by the user, we should set libpod's static
directory to a subdirectory of that by default, to duplicate
previous behavior.

Signed-off-by: Matthew Heon <mheon@redhat.com>
We don't need this for anything more than rootless work in Libpod
now, but Buildah still uses it as it was originally written, so
leave it intact as part of our API.

Signed-off-by: Matthew Heon <mheon@redhat.com>
Instead of storing the runtime's file lock dir in the BoltDB
state, refer to the runtime inside the Bolt state instead, and
use the path stored in the runtime.

This is necessary since we moved DB initialization very far up in
runtime init, before the locks dir is properly initialized (and
it must happen before the locks dir can be created, as we use the
DB to retrieve the proper path for the locks dir now).

Signed-off-by: Matthew Heon <mheon@redhat.com>
@mheon
Copy link
Member Author

mheon commented Dec 4, 2018

bot, retest this please

@mheon
Copy link
Member Author

mheon commented Dec 4, 2018

@rhatdan @baude @vrothberg @TomSweeneyRedHat @umohnani8 I think the tests are finally green - mind reviewing?

Copy link
Member

@baude baude left a comment

Choose a reason for hiding this comment

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

lgtm

@vrothberg
Copy link
Member

LGTM but as I'm not very familiar with the DB code, I prefer someone else to merge :^)

@giuseppe
Copy link
Member

giuseppe commented Dec 5, 2018

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 5, 2018
@openshift-merge-robot openshift-merge-robot merged commit 50e754c into containers:master Dec 5, 2018
This was referenced Dec 5, 2018
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 27, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants