Commit Graph

176 Commits

Author SHA1 Message Date
Derek McGowan
7b08bcdb65
Add support for label storage in local content store
Allows running tests which require labels on the content store

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-31 12:59:52 -07:00
Derek McGowan
432670237c
Fix race in gc sweep
Removes extra goroutine and calls removal and scan in same thread

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-30 13:56:16 -07:00
Michael Crosby
e74c423f78 Fix races with concurrent GC
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-10-27 14:47:23 -04:00
Michael Crosby
b6e0c4f321 Fix go lint errors
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-10-25 15:26:44 -04:00
Michael Crosby
5fd0415985 Add comments and fix common lint issues
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-10-20 13:19:14 -04:00
Derek McGowan
923a5c873b
Update content store garbage collection
Use single instance of content store instead of
creating new one for each collection. Using new
instance and wrapping causes failures.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-18 15:30:12 -07:00
Derek McGowan
295cce278f
Use single instance of snapshot and content stores
Ensures that all callers and the garbage collector are using
the same lock instances to prevent cleanup of objects
during creation.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-16 11:57:50 -07:00
Derek McGowan
17471d5592
Metadata garbage collection
Marks and sweeps unreferenced objects.
Add snapshot cleanup to metadata.
Add content garbage collection

Add dirty flags for snapshotters and content store which
are set on deletion and used during the next garbage collection.
Cleanup content store backend when content metadata is removed.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-11 10:42:47 -07:00
Derek McGowan
e4defbcb6d
Add documentation for metadata database
Add documentation and explanation for migrations.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-06 13:33:07 -07:00
Derek McGowan
7f657ce3de
Add database migrations
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-05 16:35:58 -07:00
Derek McGowan
8d892a651b
Update metadata plugin initialization
Updates metadata plugin to require content and
snapshotter plugins be loaded and initializes with
those plugins, keeping the metadata database structure
static after initialization. Service plugins now only
require metadata plugin access snapshotter or content
stores through metadata, which was already required
behavior of the services.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-04 11:25:46 -07:00
Derek McGowan
2ab70f21ac
Add content and snapshot store references
Update database object to hold reference to the
data stores.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-04 11:16:22 -07:00
Derek McGowan
447a0a9452
Add children bucket to back reference snapshots
Adds back links from parent to children in order to prevent
deletion of a referenced snapshot in a namespace.
Avoid removing snapshot during metadata delete to
prevent shared namespaces from being mistakenly deleted.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-04 11:16:22 -07:00
Derek McGowan
56c1b79a4c
Create metadata db object
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-04 11:16:22 -07:00
Stephen Day
f6d88927d5 Merge pull request #1583 from stevvooe/image-storage-validation
metadata: validation and testing of image store
2017-10-03 16:48:38 -07:00
Stephen J Day
698b6d15f7
metadata: validation and testing of image store
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-10-03 16:34:00 -07:00
Michael Crosby
451421b615 Comment more packages to pass go lint
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-10-02 13:54:56 -04:00
Jess Valarezo
18c4322bb3 Labels are consistently validated across services
* The combined size of a key/value pair cannot exceed 4096 bytes

Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
2017-09-21 15:11:46 -07:00
Michael Crosby
d22160c28e Vendor typeurl package
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-09-19 09:43:55 -04:00
Stephen J Day
f7d31e2be4
api, metadata: use map type for Container.Extensions
To allow for updating extensions without collisions, we have moved to
using a map type that can be explicitly selected via the field path for
updates. This ensures that multiple parties can operate on their
extensions without stepping on each other's toes or incurring an
inordinate number of round trips.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-09-08 19:34:26 -07:00
Brian Goff
3552ce5688 Add field to Container for client-defined data
This field allows a client to store specialized information in the
container metadata rather than having to store this itself and keep
the data in sync with containerd.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2017-09-07 16:54:47 -04:00
Akihiro Suda
e30e0c8b75
api: RootFS -> SnapshotKey
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-09-06 15:22:19 -07:00
Kenfe-Mickaël Laventure
e1eeb0e0a2 Merge pull request #1475 from dmcgowan/content-commit-context
Add context to content commit
2017-09-06 11:04:31 -07:00
Derek McGowan
9613acb2ed
Add context to content commit
Content commit is updated to take in a context, allowing
content to be committed within the same context the writer
was in. This is useful when commit may be able to use more
context to complete the action rather than creating its own.
An example of this being useful is for the metadata implementation
of content, having a context allows tests to fully create
content in one database transaction by making use of the context.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-09-06 10:19:12 -07:00
Kenfe-Mickael Laventure
e0d8cb1366
Fix retrieval of container Runtime.Options field
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
2017-08-31 12:05:39 -07:00
Derek McGowan
98960f0493
Skip items removed during walk
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-08-23 14:43:56 -07:00
Derek McGowan
750771f6d0
Remove snapshot test suite as a parallel test runner
The testsuite alters global state by setting the umask, avoid
running the testsuite in parallel and move umask manipulation
to the test suite level to individual tests may run in parallel.

Added better error messaging and handling.

Removed reliance on testing object for handling cleanup failure.
When a cleanup error occurred, it would fail the test but the log
would get skipped. With this change the failure will show up for
the running test.

Update test unmounting to set the detach flag, avoiding races with
btrfs which may see the device as busy when attempting to unmount.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-08-22 16:29:17 -07:00
Stephen J Day
783ed05057
metadata: ensure correct updates on Container
This fixes a few bugs in the container store related to reading and
writing fields. Specifically, on update, the full field set wasn't being
returned to the caller, making it appear that the store was corrupted.
We now return the correctly updated field and store the missing field
that was omitted in the original implementation. In course, we also have
defined the update semantics of each field, as well as whether or not
they are required.

The big addition here is really the container metadata testsuite. It
covers listing, filtering, creates, updates and deletes in a vareity of
scenarios.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-08-18 14:43:00 -07:00
Stephen Day
72159bf4a4 Merge pull request #1325 from dmcgowan/diffid-labels
content: commit options
2017-08-14 15:17:37 -07:00
Michael Crosby
dbb63b636b Merge pull request #1346 from stevvooe/disallow-runtime-update
metadata: disallow changing the runtime of an existing container
2017-08-14 15:15:43 -04:00
Jess Valarezo
e5cf1471dc metadata: container spec nil check
Prevent panic from Marshal on a nil container spec

Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
2017-08-13 19:00:28 -07:00
Stephen J Day
d7689418ed
metadata: disallow changing the runtime of an existing container
This could render tasks for a container unresolvalbe. If there is a use
case for changing the runtime of a container, we should think it through
carefully.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-08-11 16:19:25 -07:00
Derek McGowan
dee8dc2cda
Add support for content labels on commit
Add commit options which allow for setting labels on commit.
Prevents potential race between garbage collector reading labels
after commit and labels getting set.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-08-11 14:15:20 -07:00
Derek McGowan
c4387a159e
Add content test suite run to client
Fix bugs in content deletion and upload status

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-08-11 14:08:34 -07:00
Stephen Day
e6ba48f25c Merge pull request #1257 from stevvooe/content-changes
content: remove Provider.Reader
2017-08-09 17:12:44 -07:00
Stephen J Day
8be340e37b
content: remove Provider.Reader
After some analysis, it was found that Content.Reader was generally
redudant to an io.ReaderAt. This change removes `Content.Reader` in
favor of a `Content.ReaderAt`. In general, `ReaderAt` can perform better
over interfaces with indeterminant latency because it avoids remote
state for reads. Where a reader is required, a helper is provided to
convert it into an `io.SectionReader`.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-08-09 14:32:28 -07:00
Derek McGowan
55c3711fab
Update snapshot metadata to support labels
Updates structure of snapshot metadata to add labels and
updates.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-08-02 16:28:41 -07:00
Derek McGowan
ad72036e58
Refactor common boltdb fields to subpackage
Moves label and timestamp bolt functions to subpackage
for use outside the metadata package without importing
metadata package.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-08-02 15:49:23 -07:00
Derek McGowan
da5c72c335 Run snapshot test suite for metadata and client
The snapshot test suite is designed to run against the snapshotter
interface, run the test suite for metadata and client implementations
of the snapshotter interface.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-25 10:47:45 -07:00
Stephen J Day
d0e396aa60
metadata: defer ingest lock to backend
Because the lock on an ingest ref being held regardless of whether a
writer was in use, resuming an existing ingest proved impossible. We now
defer writer locking to the content store backend, where the lock will
be released automatically on closing the writer or on restarting
containerd.

There are still cases where a writer can be abandoned but not closed,
leaving an active ingest, but this is extremely rare and can be resolved
with a daemon restart.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-07-24 12:20:34 -07:00
Derek McGowan
8e1591bd8b
Call upload status tests
Fix metadata status not returning correct reference string

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-24 10:11:35 -07:00
Derek McGowan
bb3c9c5927
Rename content/fs to content/local
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-24 10:11:35 -07:00
Derek McGowan
938f3185bd
Add content test suite
Add content test suite with test for writer.
Update fs and metadata implementations to use test suite.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-24 10:11:34 -07:00
Michael Crosby
89934640d8 Merge pull request #1174 from dmcgowan/refactor-committedat-createdat
Rename CommittedAt to CreatedAt in content interface
2017-07-12 17:11:02 -07:00
Derek McGowan
6d032b99f2
Rename CommittedAt to CreatedAt in content interface
Use "created at" terminology to be consistent with the rest
of the containerd interfaces.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-12 16:51:16 -07:00
Michael Crosby
39dd45ebc6 Merge pull request #1150 from dmcgowan/content-labels
Content labels
2017-07-12 16:47:48 -07:00
Derek McGowan
a78d0bdeac
Update the content interface to return info from update
Namespace keys used by client for uncompressed

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-12 16:22:13 -07:00
Stephen J Day
9e5bd5a2dc
namespaces, identifiers: split validation
After review, there are cases where having common requirements for
namespaces and identifiers creates contention between applications.  One
example is that it is nice to have namespaces comply with domain name
requirement, but that does not allow underscores, which are required for
certain identifiers.

The namespaces validation has been reverted to be in line with RFC 1035.
Existing identifiers has been modified to allow simply alpha-numeric
identifiers, while limiting adjacent separators.

We may follow up tweaks for the identifier charset but this split should
remove the hard decisions.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-07-12 14:46:47 -07:00
Derek McGowan
fba7463ed3
Add labels and fileters to content
Update list content command to support filters
Add label subcommand to content in dist tool to update labels
Add uncompressed label on unpack

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-12 13:59:17 -07:00
Stephen Day
d173454719 Merge pull request #1129 from dmcgowan/content-namespace
Namespace content
2017-07-11 16:07:34 -07:00
Stephen J Day
6fa9a0b2df
metadata: preserve createdat on update
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-07-11 12:06:29 -07:00
Derek McGowan
46deddf460
Update list statuses to use filters
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-11 12:05:36 -07:00
Derek McGowan
4322664b88
Update task service to use metadata content store
Address feedback and fix issues

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-11 11:11:10 -07:00
Derek McGowan
b6d58f63a8
Support for ingest namespacing
Move content status to list statuses and add single status
to interface.
Updates API to support list statuses and status
Updates snapshot key creation to be generic

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-11 11:11:10 -07:00
Derek McGowan
2c9004d431
Add namespace content store in metadata
Add a metadata store for content which enforces content is
only visible inside a given namespace.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-11 11:11:10 -07:00
Stephen J Day
7f4c4aecf7
images, containers: converge metadata API conventions
The primary feature we get with this PR is support for filters and
labels on the image metadata store. In the process of doing this, the
conventions for the API have been converged between containers and
images, providing a model for other services.

With images, `Put` (renamed to `Update` briefly) has been split into a
`Create` and `Update`, allowing one to control the behavior around these
operations. `Update` now includes support for masking fields at the
datastore-level across both the containers and image service. Filters
are now just string values to interpreted directly within the data
store. This should allow for some interesting future use cases in which
the datastore might use the syntax for more efficient query paths.

The containers service has been updated to follow these conventions as
closely as possible.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-07-11 10:45:12 -07:00
Ian Campbell
89c3e0141e Adding missing arguments to Wrapf
I noticed some "%q!!missing!!" in my logs and found:

$ git grep 'f(.*, ".*%q.*")'
metadata/containers.go:         return containers.Container{}, errors.Wrapf(errdefs.ErrNotFound, "bucket name %q")
metadata/containers.go:                 err = errors.Wrapf(errdefs.ErrAlreadyExists, "content %q")
metadata/namespaces.go:                 return errors.Wrapf(errdefs.ErrAlreadyExists, "namespace %q")

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
2017-07-07 16:00:19 +01:00
Michael Crosby
a60511d5aa Use typeurl package for spec types
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-07-05 15:37:26 -07:00
Michael Crosby
3448c6bafb Merge pull request #1113 from dmcgowan/snapshot-namespaces
Snapshot namespaces
2017-06-30 16:36:40 -07:00
Stephen J Day
396d89e423
cmd/ctr, service/containers: implement container filter
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-06-30 11:49:16 -07:00
Derek McGowan
4ba4f3a1d5
Add namespaced snapshotter implementation
The namespaced snapshotter wraps an existing snapshotter and
enforces namespace.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-06-29 16:16:26 -07:00
Michael Crosby
96dbb08ec4 Change runtime options to *Any
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-06-29 15:35:13 -07:00
Stephen J Day
a4fadc596b
errdefs: centralize error handling
Now that we have most of the services required for use with containerd,
it was found that common patterns were used throughout services. By
defining a central `errdefs` package, we ensure that services will map
errors to and from grpc consistently and cleanly. One can decorate an
error with as much context as necessary, using `pkg/errors` and still
have the error mapped correctly via grpc.

We make a few sacrifices. At this point, the common errors we use across
the repository all map directly to grpc error codes. While this seems
positively crazy, it actually works out quite well. The error conditions
that were specific weren't super necessary and the ones that were
necessary now simply have better context information. We lose the
ability to add new codes, but this constraint may not be a bad thing.

Effectively, as long as one uses the errors defined in `errdefs`, the
error class will be mapped correctly across the grpc boundary and
everything will be good. If you don't use those definitions, the error
maps to "unknown" and the error message is preserved.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-06-29 15:00:47 -07:00
Stephen J Day
70815af652
identifiers: use common package for identifier validation
A few days ago, we added validation for namespaces. We've decided to
expand these naming rules to include containers. To facilitate this, a
common package `identifiers` now provides a common validation area.
These rules will be extended to apply to task identifiers, snapshot keys
and other areas where user-provided identifiers may be used.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-06-23 16:46:45 -07:00
Stephen J Day
5380585e21
namespaces: enforce a character set for namespaces
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-06-21 17:31:25 -07:00
Michael Crosby
ab8311b494 Merge pull request #1053 from stevvooe/expand-container-runtime-bucket
metadata: expand container runtime into bucket
2017-06-21 17:22:26 -07:00
Stephen J Day
ea44901921
metadata: expand container runtime into bucket
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-06-21 16:22:56 -07:00
Phil Estes
fb311ef2ec
Error handler cleanup
Cleanup per additional comments in PR #992.

Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
2017-06-21 15:47:23 -07:00
Michael Crosby
94eafaab60 Update GRPC for consistency
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-06-21 13:34:24 -07:00
Phil Estes
e10a9aff7d
Use error interfaces for content/metadata
These interfaces allow us to preserve both the checking of error "cause"
as well as messages returned from the gRPC API so that the client gets
full error reason instead of a default "metadata: not found" in the case
of a missing image.

Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
2017-06-14 15:55:08 -04:00
Stephen J Day
6414c68b16
metadata: properly namespace containers storage
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-06-07 17:58:40 -07:00
Stephen J Day
af2718b01f
namespaces: support within containerd
To support multi-tenancy, containerd allows the collection of metadata
and runtime objects within a heirarchical storage primitive known as
namespaces. Data cannot be shared across these namespaces, unless
allowed by the service. This allows multiple sets of containers to
managed without interaction between the clients that management. This
means that different users, such as SwarmKit, K8s, Docker and others can
use containerd without coordination. Through labels, one may use
namespaces as a tool for cleanly organizing the use of containerd
containers, including the metadata storage for higher level features,
such as ACLs.

Namespaces

Namespaces cross-cut all containerd operations and are communicated via
context, either within the Go context or via GRPC headers. As a general
rule, no features are tied to namespace, other than organization. This
will be maintained into the future. They are created as a side-effect of
operating on them or may be created manually. Namespaces can be labeled
for organization. They cannot be deleted unless the namespace is empty,
although we may want to make it so one can clean up the entirety of
containerd by deleting a namespace.

Most users will interface with namespaces by setting in the
context or via the `CONTAINERD_NAMESPACE` environment variable, but the
experience is mostly left to the client. For `ctr` and `dist`, we have
defined a "default" namespace that will be created up on use, but there
is nothing special about it. As part of this PR we have plumbed this
behavior through all commands, cleaning up context management along the
way.

Namespaces in Action

Namespaces can be managed with the `ctr namespaces` subcommand. They
can be created, labeled and destroyed.

A few commands can demonstrate the power of namespaces for use with
images. First, lets create a namespace:

```
$ ctr namespaces create foo mylabel=bar
$ ctr namespaces ls
NAME LABELS
foo  mylabel=bar
```

We can see that we have a namespace `foo` and it has a label. Let's pull
an image:

```
$ dist pull docker.io/library/redis:latest
docker.io/library/redis:latest: resolved       |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:548a75066f3f280eb017a6ccda34c561ccf4f25459ef8e36d6ea582b6af1decf: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:d45bc46b48e45e8c72c41aedd2a173bcc7f1ea4084a8fcfc5251b1da2a09c0b6: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:5b690bc4eaa6434456ceaccf9b3e42229bd2691869ba439e515b28fe1a66c009: done           |++++++++++++++++++++++++++++++++++++++|
config-sha256:a858478874d144f6bfc03ae2d4598e2942fc9994159f2872e39fae88d45bd847: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:4cdd94354d2a873333a205a02dbb853dd763c73600e0cf64f60b4bd7ab694875: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:10a267c67f423630f3afe5e04bbbc93d578861ddcc54283526222f3ad5e895b9: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:c54584150374aa94b9f7c3fbd743adcff5adead7a3cf7207b0e51551ac4a5517: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:d1f9221193a65eaf1b0afc4f1d4fbb7f0f209369d2696e1c07671668e150ed2b: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:71c1f30d820f0457df186531dc4478967d075ba449bd3168a3e82137a47daf03: done           |++++++++++++++++++++++++++++++++++++++|
elapsed: 0.9 s total:   0.0 B (0.0 B/s)
INFO[0000] unpacking rootfs
INFO[0000] Unpacked chain id: sha256:41719840acf0f89e761f4a97c6074b6e2c6c25e3830fcb39301496b5d36f9b51
```

Now, let's list the image:

```
$ dist images ls
REF                            TYPE  DIGEST SIZE
docker.io/library/redis:latest application/vnd.docker.distribution.manifest.v2+json sha256:548a75066f3f280eb017a6ccda34c561ccf4f25459ef8e36d6ea582b6af1decf 72.7 MiB
```

That looks normal. Let's list the images for the `foo` namespace and see
this in action:

```
$ CONTAINERD_NAMESPACE=foo dist images ls
REF TYPE DIGEST SIZE
```

Look at that! Nothing was pulled in the namespace `foo`. Let's do the
same pull:

```
$ CONTAINERD_NAMESPACE=foo dist pull docker.io/library/redis:latest
docker.io/library/redis:latest: resolved       |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:548a75066f3f280eb017a6ccda34c561ccf4f25459ef8e36d6ea582b6af1decf: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:d45bc46b48e45e8c72c41aedd2a173bcc7f1ea4084a8fcfc5251b1da2a09c0b6: done           |++++++++++++++++++++++++++++++++++++++|
config-sha256:a858478874d144f6bfc03ae2d4598e2942fc9994159f2872e39fae88d45bd847: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:4cdd94354d2a873333a205a02dbb853dd763c73600e0cf64f60b4bd7ab694875: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:c54584150374aa94b9f7c3fbd743adcff5adead7a3cf7207b0e51551ac4a5517: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:71c1f30d820f0457df186531dc4478967d075ba449bd3168a3e82137a47daf03: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:d1f9221193a65eaf1b0afc4f1d4fbb7f0f209369d2696e1c07671668e150ed2b: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:10a267c67f423630f3afe5e04bbbc93d578861ddcc54283526222f3ad5e895b9: done           |++++++++++++++++++++++++++++++++++++++|
layer-sha256:5b690bc4eaa6434456ceaccf9b3e42229bd2691869ba439e515b28fe1a66c009: done           |++++++++++++++++++++++++++++++++++++++|
elapsed: 0.8 s total:   0.0 B (0.0 B/s)
INFO[0000] unpacking rootfs
INFO[0000] Unpacked chain id: sha256:41719840acf0f89e761f4a97c6074b6e2c6c25e3830fcb39301496b5d36f9b51
```

Wow, that was very snappy! Looks like we pulled that image into out
namespace but didn't have to download any new data because we are
sharing storage. Let's take a peak at the images we have in `foo`:

```
$ CONTAINERD_NAMESPACE=foo dist images ls
REF                            TYPE DIGEST SIZE
docker.io/library/redis:latest application/vnd.docker.distribution.manifest.v2+json sha256:548a75066f3f280eb017a6ccda34c561ccf4f25459ef8e36d6ea582b6af1decf 72.7 MiB
```

Now, let's remove that image from `foo`:

```
$ CONTAINERD_NAMESPACE=foo dist images rm
docker.io/library/redis:latest
```

Looks like it is gone:

```
$ CONTAINERD_NAMESPACE=foo dist images ls
REF TYPE DIGEST SIZE
```

But, as we can see, it is present in the `default` namespace:

```
$ dist images ls
REF                            TYPE DIGEST SIZE
docker.io/library/redis:latest application/vnd.docker.distribution.manifest.v2+json sha256:548a75066f3f280eb017a6ccda34c561ccf4f25459ef8e36d6ea582b6af1decf 72.7 MiB
```

What happened here? We can tell by listing the namespaces to get a
better understanding:

```
$ ctr namespaces ls
NAME    LABELS
default
foo     mylabel=bar
```

From the above, we can see that the `default` namespace was created with
the standard commands without the environment variable set. Isolating
the set of shared images while sharing the data that matters.

Since we removed the images for namespace `foo`, we can remove it now:

```
$ ctr namespaces rm foo
foo
```

However, when we try to remove the `default` namespace, we get an error:

```
$ ctr namespaces rm default
ctr: unable to delete default: rpc error: code = FailedPrecondition desc = namespace default must be empty
```

This is because we require that namespaces be empty when removed.

Caveats

- While most metadata objects are namespaced, containers and tasks may
exhibit some issues. We still need to move runtimes to namespaces and
the container metadata storage may not be fully worked out.
- Still need to migrate content store to metadata storage and namespace
the content store such that some data storage (ie images).
- Specifics of snapshot driver's relation to namespace needs to be
worked out in detail.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-06-06 13:50:33 -07:00
Derek McGowan
3e0c50c2c9 Merge pull request #954 from ijc25/copy-bolt-db-slices
Copy byte slices contained in bolt db objects
2017-06-06 11:21:02 -07:00
Ian Campbell
961e12b736 Copy container.Spec when reading.
In `execution.Create()` I was seeing `opts.Spec` unexpectedly becoming a slice
full of nulls instead of the expected data (often this occurred at the
`s.mu.Lock()`)

https://github.com/boltdb/bolt#caveats--limitations says:

> Byte slices returned from Bolt are only valid during a transaction. Once the
> transaction has been committed or rolled back then the memory they point to
> can be reused by a new page or can be unmapped from virtual memory and you'll
> see an unexpected fault address panic when accessing it.

Since `opts.Spec` = `container.Spec` where the latter is a byte slice returned
from Bolt we must copy it. The best place to do this is when reading, so that
callers need not worry about this.

I also checked metadata/*.go for similar issues and found no others.

Signed-off-by: Ian Campbell <ian.campbell@docker.com>
2017-06-06 11:26:51 +01:00
Kunal Kushwaha
0008ac7f3d Timestamp added to container object.
Fix for #912

Signed-off-by: Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
2017-06-05 14:30:49 +09:00
Stephen J Day
7c14cbc091
metadata: merge storage into package
The implementations for the storage of metadata have been merged into a
single metadata package where they can share storage primitives and
techniques. The is a requisite for the addition of namespaces, which
will require a coordinated layout for records to be organized by
namespace.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-05-26 17:16:13 -07:00