Use map for stream processors

Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
Maksym Pavlenko 2019-08-23 15:31:37 -07:00
parent ea6c749e35
commit 8ebffecbc3
4 changed files with 18 additions and 9 deletions

View File

@ -21,20 +21,20 @@ pipe's path set as the value of the environment variable `STREAM_PROCESSOR_PIPE`
## Configuration ## Configuration
To configure stream processors for containerd, entries in the config file need to be made. To configure stream processors for containerd, entries in the config file need to be made.
The `stream_processors` field is an array so that users can chain together multiple processors The `stream_processors` field is a map so that users can chain together multiple processors
to mutate content streams. to mutate content streams.
Processor Fields: Processor Fields:
* `id` - ID of the processor, used for passing a specific payload to the processor. * Key - ID of the processor, used for passing a specific payload to the processor.
* `accepts` - Accepted media-types for the processor that it can handle. * `accepts` - Accepted media-types for the processor that it can handle.
* `returns` - The media-type that the processor returns. * `returns` - The media-type that the processor returns.
* `path` - Path to the processor binary. * `path` - Path to the processor binary.
* `args` - Arguments passed to the processor binary. * `args` - Arguments passed to the processor binary.
```toml ```toml
[[stream_processors]] [stream_processors]
id = "io.containerd.processor.v1.pigz" [stream_processors."io.containerd.processor.v1.pigz"]
accepts = ["application/vnd.docker.image.rootfs.diff.tar.gzip"] accepts = ["application/vnd.docker.image.rootfs.diff.tar.gzip"]
returns = "application/vnd.oci.image.layer.v1.tar" returns = "application/vnd.oci.image.layer.v1.tar"
path = "unpigz" path = "unpigz"

View File

@ -63,13 +63,11 @@ type Config struct {
// Imports are additional file path list to config files that can overwrite main config file fields // Imports are additional file path list to config files that can overwrite main config file fields
Imports []string `toml:"imports"` Imports []string `toml:"imports"`
StreamProcessors []StreamProcessor `toml:"stream_processors"` StreamProcessors map[string]StreamProcessor `toml:"stream_processors"`
} }
// StreamProcessor provides configuration for diff content processors // StreamProcessor provides configuration for diff content processors
type StreamProcessor struct { type StreamProcessor struct {
// ID of the processor, also used to fetch the specific payload
ID string `toml:"id"`
// Accepts specific media-types // Accepts specific media-types
Accepts []string `toml:"accepts"` Accepts []string `toml:"accepts"`
// Returns the media-type // Returns the media-type

View File

@ -86,6 +86,11 @@ func TestLoadSingleConfig(t *testing.T) {
data := ` data := `
version = 2 version = 2
root = "/var/lib/containerd" root = "/var/lib/containerd"
[stream_processors]
[stream_processors."io.containerd.processor.v1.pigz"]
accepts = ["application/vnd.docker.image.rootfs.diff.tar.gzip"]
path = "unpigz"
` `
tempDir, err := ioutil.TempDir("", "containerd_") tempDir, err := ioutil.TempDir("", "containerd_")
assert.NilError(t, err) assert.NilError(t, err)
@ -100,6 +105,12 @@ root = "/var/lib/containerd"
assert.NilError(t, err) assert.NilError(t, err)
assert.Equal(t, 2, out.Version) assert.Equal(t, 2, out.Version)
assert.Equal(t, "/var/lib/containerd", out.Root) assert.Equal(t, "/var/lib/containerd", out.Root)
assert.DeepEqual(t, map[string]StreamProcessor{
"io.containerd.processor.v1.pigz": {
Accepts: []string{"application/vnd.docker.image.rootfs.diff.tar.gzip"},
Path: "unpigz",
},
}, out.StreamProcessors)
} }
func TestLoadConfigWithImports(t *testing.T) { func TestLoadConfigWithImports(t *testing.T) {

View File

@ -89,8 +89,8 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, p := range config.StreamProcessors { for id, p := range config.StreamProcessors {
diff.RegisterProcessor(diff.BinaryHandler(p.ID, p.Returns, p.Accepts, p.Path, p.Args)) diff.RegisterProcessor(diff.BinaryHandler(id, p.Returns, p.Accepts, p.Path, p.Args))
} }
serverOpts := []grpc.ServerOption{ serverOpts := []grpc.ServerOption{