Commit Graph

63 Commits

Author SHA1 Message Date
Akihiro Suda
d8b68e3ccc
Stop using math/rand.Read and rand.Seed (deprecated in Go 1.20)
From golangci-lint:

> SA1019: rand.Read has been deprecated since Go 1.20 because it
>shouldn't be used: For almost all use cases, crypto/rand.Read is more
>appropriate. (staticcheck)

> SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative
>has been available since Go 1.0: Programs that call Seed and then expect
>a specific sequence of results from the global random source (using
>functions such as Int) can be broken when a dependency changes how
>much it consumes from the global random source. To avoid such breakages,
>programs that need a specific result sequence should use
>NewRand(NewSource(seed)) to obtain a random generator that other
>packages cannot access. (staticcheck)

See also:

- https://pkg.go.dev/math/rand@go1.20#Read
- https://pkg.go.dev/math/rand@go1.20#Seed

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-02-16 03:50:23 +09:00
Derek McGowan
b550526ccd
Use cleanup.Background instead of context.Background for cleanup
Use the cleanup context to re-use values from the original context

Signed-off-by: Derek McGowan <derek@mcg.dev>
2023-01-04 11:22:24 -08:00
Maksym Pavlenko
3bc8fc4d30 Cleanup build constraints
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2022-12-08 09:36:20 -08:00
cosmoer
344431cdd4 fix: support simultaneous create diff for same parent snapshot
Signed-off-by: Qian Zhang <cosmoer@qq.com>
2022-07-24 09:34:54 +08:00
haoyun
bbe46b8c43 feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io>
Co-authored-by: zounengren <zouyee1989@gmail.com>
2022-01-07 10:27:03 +08:00
haoyun
c0d07094be feat: Errorf usage
Signed-off-by: haoyun <yun.hao@daocloud.io>
2021-12-13 14:31:53 +08:00
Eng Zer Jun
50da673592
refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated as of Go 1.16, see
https://golang.org/doc/go1.16#ioutil. This commit replaces the existing
io/ioutil functions with their new definitions in io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-09-21 09:50:38 +08:00
Akihiro Suda
d3aa7ee9f0
Run go fmt with Go 1.17
The new `go fmt` adds `//go:build` lines (https://golang.org/doc/go1.17#tools).

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-08-22 09:31:50 +09:00
Iceber Gu
4e8b2f309a
rootfs: fix the error handling of the createInitLayer
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2021-03-15 15:48:48 +08:00
Daniel Canter
a91c298d1d Optimize Windows and LCOW snapshotters to only create scratch layer on the final snapshot
For LCOW currently we copy (or create) the scratch.vhdx for every single snapshot
so there ends up being a sandbox.vhdx in every directory seemingly unnecessarily. With the default scratch
size of 20GB the size on disk is about 17MB so there's a 17MB overhead per layer plus the time to copy the
file with every snapshot. Only the final sandbox.vhdx is actually used so this would be a nice little
optimization.

For WCOW we essentially do the exact same except copy the blank vhdx from the base layer.

Signed-off-by: Daniel Canter <dcanter@microsoft.com>
2020-11-30 16:25:38 -08:00
Maksym Pavlenko
3be12fe1c0 Do not loose snapshotter options
Pass snapshotter options in recursive applyLayers calls.

Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
2020-03-02 13:48:41 -08:00
Wei Fu
09b184c15a rootfs: use new ctx to cleanup instead of canceled one
rootfs.CreateDiff might be canceled by context for some reason. Based on
this case, the defer function should use the new ctx to do cleanup
temporary snapshotter instead of the canceled one.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2019-08-27 11:27:34 +08:00
Michael Crosby
26b90619e2 Pass apply opts through rootfs/* code
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-08-07 18:35:55 +00:00
Dave Henderson
9a97ab34ce
Switching from crypto/rand to math/rand to avoid blocking
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
2018-07-11 16:24:51 -04:00
Derek McGowan
28caf9027e
Add recursive apply layer function
Update apply layers to recursive from the top layer.
Update apply layer to check for exists and apply single layer.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-05-07 15:50:04 -07:00
Tom Godkin
fc8bce59b9 Use user-specific temp directory if set
This allows non-privileged users to use containerd. This is part of a
larger track of work integrating containerd into Cloudfoundry's garden
with support for rootless.

[#156343575]

Signed-off-by: Claudia Beresford <cberesford@pivotal.io>
2018-05-04 10:27:58 +01:00
Kir Kolyshkin
bbe14f0a2e Switch from x/net/context to context
Since Go 1.7, context is a standard package, superceding the
"x/net/context". Since Go 1.9, the latter only provides a few type
aliases from the former. Therefore, it makes sense to switch to the
standard package.

This commit was generated by the following script (with a couple of
minor fixups to remove extra changes done by goimports):

	#!/bin/bash

	if [ $# -ge 1 ]; then
		FILES=$*
	else
		FILES=$(git ls-files \*.go | grep -vF ".pb.go" | grep -v
	^vendor/)
	fi

	for f in $FILES; do
		printf .
		sed -i -e 's|"golang.org/x/net/context"$|"context"|' $f
		goimports -w $f
		awk '	/^$/ {e=1; next;}
			/[[:space:]]"context"$/ {e=0;}
			{if (e) {print ""; e=0}; print;}' < $f > $f.new && \
				mv $f.new $f
		goimports -w $f
	done
	echo

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-04-24 14:33:34 -07:00
Kunal Kushwaha
b12c3215a0 Licence header added
Signed-off-by: Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
2018-02-19 10:32:26 +09:00
Derek McGowan
b763777288
diff: rename differ to comparer
Remove combined interface and split implementations.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-01-26 16:32:09 -08:00
Akihiro Suda
b580441f91
diff: resplit Applier from Differ
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2018-01-25 13:58:34 -08:00
Jess Valarezo
5bc0c43c73 rootfs: remove upper snapshot after use
Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
2018-01-02 21:23:35 -05:00
yason
4f1c0e067e improve error message
Signed-off-by: yason <yan.xuean@zte.com.cn>
2017-12-01 15:45:15 +08:00
Jess Valarezo
9885edfc44 rename snapshot->snapshots pkg
Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
2017-11-29 14:55:02 -08:00
Daniel Nephin
a05e5fd77a restore deferred cleanup in rootfs.init
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
2017-11-28 13:14:39 -05:00
Daniel Nephin
ee04cfa3f9 Add staticcheck linter
Fix issues with sync.Pool being passed an array and not a pointer.
See https://github.com/dominikh/go-tools/blob/master/cmd/staticcheck/docs/checks/SA6002

Add missing tests for content.Copy

Fix T.Fatal being called in a goroutine

Signed-off-by: Daniel Nephin <dnephin@gmail.com>
2017-11-28 13:05:30 -05:00
Derek McGowan
7884707c2f
Add reference labels to snapshots and content
Ensure all snapshots and content are referenced on commit and
protected from cleanup.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-11 10:42:47 -07:00
Derek McGowan
d9db1d112d
Refactor differ into separate package
Add differ options and package with interface.
Update optional values on diff interface to use options.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-11 10:02:29 -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
Derek McGowan
597d0d76ae
Support simultaneous unpacking of same layer
Prevent unpack failures due to id collision or the need to
wait for another process to finish unpacking. Always attempt
to unpack a layer and handle collisions on commit. Commit
collisions are easily handled as it could be considered the
same as a successful unpack.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-09-06 15:45:31 -07:00
Stephen J Day
4d8f7895e4
Revert "rootfs: remove unused functions"
This reverts commit 4e2337794c.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-09-06 11:00:21 -07:00
Stephen Day
72159bf4a4 Merge pull request #1325 from dmcgowan/diffid-labels
content: commit options
2017-08-14 15:17:37 -07:00
Akihiro Suda
4e2337794c rootfs: remove unused functions
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2017-08-12 07:08:28 +00:00
Derek McGowan
da34812db6
Update differ to support compressed archives
Differ is updated to set a label for the uncompressed hash
of compressed content. This allows compressed blobs to
be used and looked up for their uncompressed hashes.
Uses commit options to set labels.
Updates rootfs default to create compressed archives.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-08-11 14:19:04 -07:00
Derek McGowan
4f388e0e27
Add documentation to rootfs functions
Clarifies role of varies rootfs functions as well as their return values.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-12 13:59:17 -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
Derek McGowan
5b105f86ce
Fix rootfs error message extra format variable
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-06-29 16:16:26 -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
Tonis Tiigi
39d55cc498 Fix context package imports
Conflicting with definition of plugin.Differ

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2017-06-09 10:58:29 -07:00
Michael Crosby
d7af92e00c Move Mount into mount pkg
This moves both the Mount type and mountinfo into a single mount
package.

This also opens up the root of the repo to hold the containerd client
implementation.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-05-22 16:41:12 -07:00
Derek McGowan
3ae69c43d8
Add diff service implementation
Add snapshot subcommand to ctr for creating diffs of RW layers.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-05-16 13:48:53 -07:00
Derek McGowan
098ff94b24
Add snapshot and diff service
Remove rootfs service in place of snapshot service. Adds
diff service for extracting and creating diffs. Diff
creation is not yet implemented. This service allows
pulling or creating images without needing root access to
mount. Additionally in the future this will allow containerd
to ensure extractions happen safely in a chroot if needed.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-05-15 16:50:16 -07:00
Stephen Day
d0c7f13e39 Merge pull request #755 from miaoyq/avoid-creating-snapshots-repeatedly
Avoid creating snapshots repeatedly
2017-04-26 15:02:14 -05:00
Phil Estes
a12b20ebc4 Merge pull request #748 from miaoyq/del-tmpdir
Delete the temporary diractory at the end of the function "ApplyLayer"
2017-04-20 00:10:35 -05:00
Yanqiang Miao
df8ece5a41 Avoid creating snapshots repeatedly
Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
2017-04-20 12:59:33 +08:00
Yanqiang Miao
c5c6f36e83 Delete the temporary diractory at the end of the function
Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
2017-04-19 09:52:44 +08:00
Yanqiang Miao
d95e98d049 Remove the redundant type conversion
The type of ocispec.Descriptor.Digest is digest.Digest now,
so the type conversion is redundant.

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
2017-04-18 16:55:19 +08:00
Michael Crosby
4f2b443a27 Rewrite imports for new github org
This rewrites the Go imports after switching to the new github org.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-04-03 14:05:44 -07:00
Stephen Day
bb3fbded9c Merge pull request #632 from dmcgowan/rootfs-fixes
Fix rootfs digest computation
2017-03-16 12:04:49 -07:00
Akihiro Suda
6089c1525b new package: compression (ported from docker/pkg/archive)
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2017-03-16 05:29:27 +00:00
Derek McGowan
4492a2cee3
Fix rootfs digest computation
Compute digest from uncompressed archive.
Properly propagate error on unpack.
Rename dist cmd commands to match command name.

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
2017-03-15 17:17:25 -07:00