Commit graph

40 commits

Author SHA1 Message Date
Paul Holzinger 495884b319
use libnetwork from c/common
The libpod/network packages were moved to c/common so that buildah can
use it as well. To prevent duplication use it in podman as well and
remove it from here.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-12 17:07:30 +01:00
Paul Holzinger 9ce6b64133
network db: add new strucutre to container create
Make sure we create new containers in the db with the correct structure.
Also remove some unneeded code for alias handling. We no longer need this
functions.

The specgen format has not been changed for now.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-12-14 15:23:39 +01:00
Paul Holzinger 5490be67b3
network db rewrite: migrate existing settings
The new network db structure stores everything in the networks bucket.
Previously some network settings were not written the the network bucket
and only stored in the container config.
Instead of the old format which used the container ID as value in the
networks buckets we now use the PerNetworkoptions struct there.

To migrate existing users we use the state.GetNetworks() function. If it
fails to read the new format it will automatically migrate the old
config format to the new one. This is allows a flawless migration path.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-12-14 15:23:20 +01:00
Matthew Heon 43e899c2ec Rewrite Rename backend in a more atomic fashion
Move the core of renaming logic into the DB. This guarantees a
lot more atomicity than we have right now (our current solution,
removing the container from the DB and re-creating it, is *VERY*
not atomic and prone to leaving a corrupted state behind if
things go wrong. Moving things into the DB allows us to remove
most, but not all, of this - there's still a potential scenario
where the c/storage rename fails but the Podman rename succeeds,
and we end up with a mismatched state.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2021-03-02 13:30:28 -05:00
Matthew Heon 8d56eb5342 Add support for network connect / disconnect to DB
Convert the existing network aliases set/remove code to network
connect and disconnect. We can no longer modify aliases for an
existing network, but we can add and remove entire networks. As
part of this, we need to add a new function to retrieve current
aliases the container is connected to (we had a table for this
as of the first aliases PR, but it was not externally exposed).

At the same time, remove all deconflicting logic for aliases.
Docker does absolutely no checks of this nature, and allows two
containers to have the same aliases, aliases that conflict with
container names, etc - it's just left to DNS to return all the
IP addresses, and presumably we round-robin from there? Most
tests for the existing code had to be removed because of this.

Convert all uses of the old container config.Networks field,
which previously included all networks in the container, to use
the new DB table. This ensures we actually get an up-to-date list
of in-use networks. Also, add network aliases to the output of
`podman inspect`.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-11-11 16:37:54 -05:00
Matthew Heon 844d540d04 Add tests for network aliases
As part of this, we need two new functions, for retrieving all
aliases for a network and removing all aliases for a network,
both required to test.

Also, rework handling for some things the tests discovered were
broken (notably conflicts between container name and existing
aliases).

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-11-03 16:26:42 -05:00
Matthew Heon 63efde15f1 Add a way to retrieve all network aliases for a ctr
The original interface only allowed retrieving aliases for a
specific network, not for all networks. This will allow aliases
to be retrieved for every network the container is present in,
in a single DB operation.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-10-27 15:50:03 -04:00
Matthew Heon 6af7e54463 Add network aliases for containers to DB
This adds the database backend for network aliases. Aliases are
additional names for a container that are used with the CNI
dnsname plugin - the container will be accessible by these names
in addition to its name. Aliases are allowed to change over time
as the container connects to and disconnects from networks.

Aliases are implemented as another bucket in the database to
register all aliases, plus two buckets for each container (one to
hold connected CNI networks, a second to hold its aliases). The
aliases are only unique per-network, to the global and
per-container aliases buckets have a sub-bucket for each CNI
network that has aliases, and the aliases are stored within that
sub-bucket. Aliases are formatted as alias (key) to container ID
(value) in both cases.

Three DB functions are defined for aliases: retrieving current
aliases for a given network, setting aliases for a given network,
and removing all aliases for a given network.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-10-27 14:17:41 -04:00
Matthew Heon 569854d634 Unconditionally retrieve pod names via API
The ListContainers API previously had a Pod parameter, which
determined if pod name was returned (but, notably, not Pod ID,
which was returned unconditionally). This was fairly confusing,
so we decided to deprecate/remove the parameter and return it
unconditionally.

To do this without serious performance implications, we need to
avoid expensive JSON decodes of pod configuration in the DB. The
way our Bolt tables are structured, retrieving name given ID is
actually quite cheap, but we did not expose this via the Libpod
API. Add a new GetName API to do this.

Fixes #7214

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-08-10 10:15:51 -04:00
Daniel J Walsh 4352d58549
Add support for containers.conf
vendor in c/common config pkg for containers.conf

Signed-off-by: Qi Wang qiwan@redhat.com
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-27 14:36:03 -04:00
Matthew Heon 118e78c5d6 Add structure for new exec session tracking to DB
As part of the rework of exec sessions, we need to address them
independently of containers. In the new API, we need to be able
to fetch them by their ID, regardless of what container they are
associated with. Unfortunately, our existing exec sessions are
tied to individual containers; there's no way to tell what
container a session belongs to and retrieve it without getting
every exec session for every container.

This adds a pointer to the container an exec session is
associated with to the database. The sessions themselves are
still stored in the container.

Exec-related APIs have been restructured to work with the new
database representation. The originally monolithic API has been
split into a number of smaller calls to allow more fine-grained
control of lifecycle. Support for legacy exec sessions has been
retained, but in a deprecated fashion; we should remove this in
a few releases.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-03-18 11:02:14 -04:00
Valentin Rothberg 11c282ab02 add libpod/config
Refactor the `RuntimeConfig` along with related code from libpod into
libpod/config.  Note that this is a first step of consolidating code
into more coherent packages to make the code more maintainable and less
prone to regressions on the long runs.

Some libpod definitions were moved to `libpod/define` to resolve
circular dependencies.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-10-31 17:42:37 +01:00
Marco Vedovati dacbc5beb2 rm: add containers eviction with rm --force
Add ability to evict a container when it becomes unusable. This may
happen when the host setup changes after a container creation, making it
impossible for that container to be used or removed.
Evicting a container is done using the `rm --force` command.

Signed-off-by: Marco Vedovati <mvedovati@suse.com>
2019-09-25 19:44:38 +02:00
Matthew Heon 046178e55f Add function for looking up volumes by partial name
This isn't included in Docker, but seems handy enough.

Use the new API for 'volume rm' and 'volume inspect'.

Fixes #3891

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-09-09 12:06:10 -04:00
Matthew Heon 5a8a71ed81 Add volume state
We need to be able to track the number of times a volume has been
mounted for tmpfs/nfs/etc volumes. As such, we need a mutable
state for volumes. Add one, with the expected update/save methods
in both states.

There is backwards compat here, in that older volumes without a
state will still be accepted.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-09-05 12:29:36 -04:00
Matthew Heon e563f41116 Re-add locks to volumes.
This will require a 'podman system renumber' after being applied
to get lock numbers for existing volumes.

Add the DB backend code for rewriting volume configs and use it
for updating lock numbers as part of 'system renumber'.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-08-28 11:35:00 -04:00
Matthew Heon d245c6df29 Switch Libpod over to new explicit named volumes
This swaps the previous handling (parse all volume mounts on the
container and look for ones that might refer to named volumes)
for the new, explicit named volume lists stored per-container.

It also deprecates force-removing volumes that are in use. I
don't know how we want to handle this yet, but leaving containers
that depend on a volume that no longer exists is definitely not
correct.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-04-04 12:26:29 -04:00
Matthew Heon d41d8d090e Validate VolumePath against DB configuration
If this doesn't match, we end up not being able to access named
volumes mounted into containers, which is bad. Use the same
validation that we use for other critical paths to ensure this
one also matches.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-02-26 09:37:00 -05:00
Matthew Heon a3dbb7a837 Add ability to rewrite pod configs in the database
Necessary for rewriting lock IDs as part of renumber.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-02-21 10:51:42 -05:00
Matthew Heon 84feff2e06 Add a function for overwriting container config
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-02-21 10:51:42 -05:00
umohnani8 4c70b8a94b Add "podman volume" command
Add support for podman volume and its subcommands.
The commands supported are:
	podman volume create
	podman volume inspect
	podman volume ls
	podman volume rm
	podman volume prune

This is a tool to manage volumes used by podman. For now it only handle
named volumes, but eventually it will handle all volumes used by podman.

Signed-off-by: umohnani8 <umohnani@redhat.com>
2018-12-06 10:17:16 +00:00
Matthew Heon ea13264958 Fix typo
Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-03 10:48:33 -05:00
Matthew Heon b104a45f35 Fix gofmt and lint
Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-02 16:53:15 -05:00
Matthew Heon 137e0948ae Make DB config validation an explicit step
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>
2018-12-02 13:38:36 -05:00
Matthew Heon 6e16702947 Add ability to retrieve runtime configuration from DB
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>
2018-12-02 13:38:36 -05:00
Matthew Heon 1db70cce34 Do not fetch pod and ctr State on retrieval in Bolt
It's not necessary to fill in state immediately, as we'll be
overwriting it on any API call accessing it thanks to
syncContainer(). It is also causing races when we fetch it
without holding the container lock (which syncContainer() does).
As such, just don't retrieve the state on initial pull from the
database with Bolt.

Also, refactor some Linux-specific netns handling functions out
of container_internal_linux.go into boltdb_linux.go.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #1186
Approved by: rhatdan
2018-07-31 14:19:50 +00:00
Matthew Heon 8f91678a49 Update documentation for the State interface
Include details on how namespaces interact with the
state.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2018-07-24 16:12:31 -04:00
Matthew Heon e838dcb4bf Add constraint that dependencies must be in the same ns
Dependency containers must be in the same namespace, to ensure
there are never problems resolving a dependency.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2018-07-24 16:12:31 -04:00
Jhon Honce 684b544e9c Spell check strings and comments
Signed-off-by: Jhon Honce <jhonce@redhat.com>

Closes: #831
Approved by: rhatdan
2018-05-25 08:45:15 +00:00
Matthew Heon 018d2c6b1d Add pod state
Add a mutable state to pods, and database backend sutable for
modifying and updating said state.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #784
Approved by: rhatdan
2018-05-17 23:10:12 +00:00
Matthew Heon dc6a99df4c Containers in a pod can only join namespaces in that pod
This solves some dependency problems in the state, and makes
sense from a design standpoint.

Containers not in a pod can still depend on the namespaces of
containers joined to a pod, which we might also want to change in
the future.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #184
Approved by: baude
2018-02-12 14:28:07 +00:00
Matthew Heon 6b7b4b03a8 Add pod removal code
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #268
Approved by: rhatdan
2018-02-09 15:01:34 +00:00
Matthew Heon 6214be07c2 Tear out pod containers map. Instead rely on state
This ensures that there is only one canonical place where
containers in a pod are stored, in the state itself.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #268
Approved by: rhatdan
2018-02-09 15:01:34 +00:00
Matthew Heon 65d643caeb Change handling for pods in libpod state
Add new functions to update pods and add/remove containers from them
Use these new functions in place of manually modifying pods

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #229
Approved by: rhatdan
2018-01-17 15:26:43 +00:00
Matthew Heon 13f004aec5 Add ability to retrieve a pod's container from the state
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #229
Approved by: rhatdan
2018-01-17 15:26:43 +00:00
Matthew Heon 20df2196f2 Add ability for states to track container dependencies
Also prevent containers with dependencies from being removed from
in memory states. SQLite already enforced this via FOREIGN KEY
constraints.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #220
Approved by: rhatdan
2018-01-16 14:58:06 +00:00
Matthew Heon b71cde19c8 Add ability to refresh state in DB
Also, ensure we always recreate runtime spec so our net namespace
paths will be correct

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2017-12-07 13:15:34 -05:00
Matthew Heon 763e372649 Wire SQL backed state into rest of libpod
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2017-11-18 12:58:48 -05:00
Matthew Heon c6fe4430b7 Compile-tested implementation of SQL-backed state
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2017-11-18 12:54:05 -05:00
Matthew Heon a031b83a09 Initial checkin from CRI-O repo
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2017-11-01 11:24:59 -04:00