Use map for stream processors
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
parent
ea6c749e35
commit
8ebffecbc3
@ -21,20 +21,20 @@ pipe's path set as the value of the environment variable `STREAM_PROCESSOR_PIPE`
|
||||
## Configuration
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
* `returns` - The media-type that the processor returns.
|
||||
* `path` - Path to the processor binary.
|
||||
* `args` - Arguments passed to the processor binary.
|
||||
|
||||
```toml
|
||||
[[stream_processors]]
|
||||
id = "io.containerd.processor.v1.pigz"
|
||||
[stream_processors]
|
||||
[stream_processors."io.containerd.processor.v1.pigz"]
|
||||
accepts = ["application/vnd.docker.image.rootfs.diff.tar.gzip"]
|
||||
returns = "application/vnd.oci.image.layer.v1.tar"
|
||||
path = "unpigz"
|
||||
|
@ -63,13 +63,11 @@ type Config struct {
|
||||
// Imports are additional file path list to config files that can overwrite main config file fields
|
||||
Imports []string `toml:"imports"`
|
||||
|
||||
StreamProcessors []StreamProcessor `toml:"stream_processors"`
|
||||
StreamProcessors map[string]StreamProcessor `toml:"stream_processors"`
|
||||
}
|
||||
|
||||
// StreamProcessor provides configuration for diff content processors
|
||||
type StreamProcessor struct {
|
||||
// ID of the processor, also used to fetch the specific payload
|
||||
ID string `toml:"id"`
|
||||
// Accepts specific media-types
|
||||
Accepts []string `toml:"accepts"`
|
||||
// Returns the media-type
|
||||
|
@ -86,6 +86,11 @@ func TestLoadSingleConfig(t *testing.T) {
|
||||
data := `
|
||||
version = 2
|
||||
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_")
|
||||
assert.NilError(t, err)
|
||||
@ -100,6 +105,12 @@ root = "/var/lib/containerd"
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 2, out.Version)
|
||||
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) {
|
||||
|
@ -89,8 +89,8 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, p := range config.StreamProcessors {
|
||||
diff.RegisterProcessor(diff.BinaryHandler(p.ID, p.Returns, p.Accepts, p.Path, p.Args))
|
||||
for id, p := range config.StreamProcessors {
|
||||
diff.RegisterProcessor(diff.BinaryHandler(id, p.Returns, p.Accepts, p.Path, p.Args))
|
||||
}
|
||||
|
||||
serverOpts := []grpc.ServerOption{
|
||||
|
Loading…
Reference in New Issue
Block a user