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

Move label-related logic into a separated package #163

Merged
merged 1 commit into from
Oct 18, 2020

Conversation

ktock
Copy link
Member

@ktock ktock commented Oct 17, 2020

Previous: #161
Related: moby/buildkit#1733

This commit separates labels-related logic from the filesystem core. This introduces a new package source(github.com/containerd/stargz-snapshotter/stargz/source) and defines a logic to convert snapshot labels into blob sources information source.Source.

type Source struct {
	// Hosts is a registry configuration where this blob is stored.
	Hosts docker.RegistryHosts

	// Name is an image reference which contains this blob.
	Name reference.Spec

	// Target is a descriptor of this blob.
	Target ocispec.Descriptor

	// Manifest is an image manifest which contains the blob. This will
	// be used by the filesystem to pre-resolve some layers contained in
	// the manifest.
	// Currently, only layer digests (Manifest.Layers.Digest) will be used.
	Manifest ocispec.Manifest
}

source package defines an interface of that converter (GetSources) , and contains the default implementation based on containerd.io/snapshot/remote/stargz... labels (which is previously embedded in the filesystem core).

type GetSources func(labels map[string]string) (source []Source, err error)

Now the filesystem uses source.GetSources for acquiring blob source information. By default, it uses the implementation by source package but it accepts any user-defined ones through a constructor option WithGetSources.

containerd-stargz-grpc uses the following source.GetSources implementations.

  • a parser of default labels containerd.io/snapshot/remote/stargz... (implemented in source package).
  • a parser of labels containerd.io/snapshot/cri... passed from CRI, which previously embedded in the filesystem core.

Another note comes with this change is that the filesystem is now agnostic about (source-related) labels. source.GetSources implementations aren't required to use these labels so they can provide blob source information leveraging other media instead of these labels (e.g. using manifest-like JSON data + content store).

if err == nil {
return src, nil
}
allErr = errors.Wrapf(allErr, "%v;", err)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. Fixed to use go-multierrror.

This commit separates labels-related logic from the filesystem core. This
introduces a new package `source` and defines a logic to convert snapshot labels
into blob sources information `source.Source`. `source` package defines an
interface of that converter (`source.GetSources func(labels map[string]string)
(source []Source, err error)`), and contains the default implementation based on
`containerd.io/snapshot/remote/stargz...` labels (which is previously embedded
in the filesystem core).

Now the filesystem uses `source.GetSources` for acquiring blob source
information. By default, it uses the implementation by `source` package but it
accepts any user-defined ones through a constructor option `WithGetSources`.

`containerd-stargz-grpc` uses the following `source.GetSources` implementations.
- a parser of default labels `containerd.io/snapshot/remote/stargz...`
  (implemented in `source` package).
- a parser of labels `containerd.io/snapshot/cri...` passed from CRI, which
  previously embedded in the filesystem core.

Another note comes with this change is that the filesystem is now agnostic about
(source-related) labels. `source.GetSources` implementations aren't required to
use these labels so they can provide blob source information leveraging other
media instead of these labels (e.g. using manifest-like JSON data + content
store).

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
@AkihiroSuda AkihiroSuda merged commit 1e0f150 into containerd:master Oct 18, 2020
@ktock ktock deleted the source branch October 19, 2020 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants