X Tutup
Skip to content

Commit 8ebffec

Browse files
committed
Use map for stream processors
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
1 parent ea6c749 commit 8ebffec

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

docs/stream_processors.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ pipe's path set as the value of the environment variable `STREAM_PROCESSOR_PIPE`
2121
## Configuration
2222

2323
To configure stream processors for containerd, entries in the config file need to be made.
24-
The `stream_processors` field is an array so that users can chain together multiple processors
24+
The `stream_processors` field is a map so that users can chain together multiple processors
2525
to mutate content streams.
2626

2727
Processor Fields:
2828

29-
* `id` - ID of the processor, used for passing a specific payload to the processor.
29+
* Key - ID of the processor, used for passing a specific payload to the processor.
3030
* `accepts` - Accepted media-types for the processor that it can handle.
3131
* `returns` - The media-type that the processor returns.
3232
* `path` - Path to the processor binary.
3333
* `args` - Arguments passed to the processor binary.
3434

3535
```toml
36-
[[stream_processors]]
37-
id = "io.containerd.processor.v1.pigz"
36+
[stream_processors]
37+
[stream_processors."io.containerd.processor.v1.pigz"]
3838
accepts = ["application/vnd.docker.image.rootfs.diff.tar.gzip"]
3939
returns = "application/vnd.oci.image.layer.v1.tar"
4040
path = "unpigz"

services/server/config/config.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ type Config struct {
6363
// Imports are additional file path list to config files that can overwrite main config file fields
6464
Imports []string `toml:"imports"`
6565

66-
StreamProcessors []StreamProcessor `toml:"stream_processors"`
66+
StreamProcessors map[string]StreamProcessor `toml:"stream_processors"`
6767
}
6868

6969
// StreamProcessor provides configuration for diff content processors
7070
type StreamProcessor struct {
71-
// ID of the processor, also used to fetch the specific payload
72-
ID string `toml:"id"`
7371
// Accepts specific media-types
7472
Accepts []string `toml:"accepts"`
7573
// Returns the media-type

services/server/config/config_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ func TestLoadSingleConfig(t *testing.T) {
8686
data := `
8787
version = 2
8888
root = "/var/lib/containerd"
89+
90+
[stream_processors]
91+
[stream_processors."io.containerd.processor.v1.pigz"]
92+
accepts = ["application/vnd.docker.image.rootfs.diff.tar.gzip"]
93+
path = "unpigz"
8994
`
9095
tempDir, err := ioutil.TempDir("", "containerd_")
9196
assert.NilError(t, err)
@@ -100,6 +105,12 @@ root = "/var/lib/containerd"
100105
assert.NilError(t, err)
101106
assert.Equal(t, 2, out.Version)
102107
assert.Equal(t, "/var/lib/containerd", out.Root)
108+
assert.DeepEqual(t, map[string]StreamProcessor{
109+
"io.containerd.processor.v1.pigz": {
110+
Accepts: []string{"application/vnd.docker.image.rootfs.diff.tar.gzip"},
111+
Path: "unpigz",
112+
},
113+
}, out.StreamProcessors)
103114
}
104115

105116
func TestLoadConfigWithImports(t *testing.T) {

services/server/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
8989
if err != nil {
9090
return nil, err
9191
}
92-
for _, p := range config.StreamProcessors {
93-
diff.RegisterProcessor(diff.BinaryHandler(p.ID, p.Returns, p.Accepts, p.Path, p.Args))
92+
for id, p := range config.StreamProcessors {
93+
diff.RegisterProcessor(diff.BinaryHandler(id, p.Returns, p.Accepts, p.Path, p.Args))
9494
}
9595

9696
serverOpts := []grpc.ServerOption{

0 commit comments

Comments
 (0)
X Tutup