Skip to content

Commit c786994

Browse files
committed
Update transfer configuration
Export transfer config fields. Determine differ based on platform or config. Get snapshotter from metadata store. Signed-off-by: Derek McGowan <[email protected]>
1 parent 800ec30 commit c786994

File tree

1 file changed

+77
-34
lines changed

1 file changed

+77
-34
lines changed

plugins/transfer/plugin.go

Lines changed: 77 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ import (
2121

2222
"github.com/containerd/containerd"
2323
"github.com/containerd/containerd/diff"
24+
"github.com/containerd/containerd/errdefs"
2425
"github.com/containerd/containerd/leases"
26+
"github.com/containerd/containerd/log"
2527
"github.com/containerd/containerd/metadata"
2628
"github.com/containerd/containerd/pkg/transfer/local"
2729
"github.com/containerd/containerd/pkg/unpack"
2830
"github.com/containerd/containerd/platforms"
2931
"github.com/containerd/containerd/plugin"
30-
"github.com/containerd/containerd/snapshots"
3132

3233
// Load packages with type registrations
3334
_ "github.com/containerd/containerd/pkg/transfer/archive"
@@ -43,7 +44,6 @@ func init() {
4344
Requires: []plugin.Type{
4445
plugin.LeasePlugin,
4546
plugin.MetadataPlugin,
46-
plugin.SnapshotPlugin,
4747
plugin.DiffPlugin,
4848
},
4949
Config: defaultConfig(),
@@ -59,68 +59,111 @@ func init() {
5959
return nil, err
6060
}
6161

62-
d, err := ic.Get(plugin.DiffPlugin)
63-
if err != nil {
64-
return nil, err
65-
}
66-
6762
// Set configuration based on default or user input
6863
var lc local.TransferConfig
69-
lc.MaxConcurrentDownloads = config.maxConcurrentDownloads
70-
lc.MaxConcurrentUploadedLayers = config.maxConcurrentUploadedLayers
71-
for _, uc := range config.unpackConfiguration {
72-
p, err := platforms.Parse(uc.platform)
64+
lc.MaxConcurrentDownloads = config.MaxConcurrentDownloads
65+
lc.MaxConcurrentUploadedLayers = config.MaxConcurrentUploadedLayers
66+
for _, uc := range config.UnpackConfiguration {
67+
p, err := platforms.Parse(uc.Platform)
7368
if err != nil {
74-
return nil, fmt.Errorf("%s: platform configuration %v invalid", plugin.TransferPlugin, uc.platform)
69+
return nil, fmt.Errorf("%s: platform configuration %v invalid", plugin.TransferPlugin, uc.Platform)
70+
}
71+
72+
sn := ms.Snapshotter(uc.Snapshotter)
73+
if sn == nil {
74+
return nil, fmt.Errorf("snapshotter %q not found: %w", uc.Snapshotter, errdefs.ErrNotFound)
7575
}
7676

77-
s, err := ic.GetByID(plugin.SnapshotPlugin, uc.snapshotter)
77+
diffPlugins, err := ic.GetByType(plugin.DiffPlugin)
7878
if err != nil {
79-
return nil, err
79+
return nil, fmt.Errorf("error loading diff plugins: %w", err)
80+
}
81+
var applier diff.Applier
82+
target := platforms.OnlyStrict(p)
83+
if uc.Differ != "" {
84+
plugin, ok := diffPlugins[uc.Differ]
85+
if !ok {
86+
return nil, fmt.Errorf("diff plugin %q: %w", uc.Differ, errdefs.ErrNotFound)
87+
}
88+
inst, err := plugin.Instance()
89+
if err != nil {
90+
return nil, fmt.Errorf("failed to get instance for diff plugin %q: %w", uc.Differ, err)
91+
}
92+
applier = inst.(diff.Applier)
93+
} else {
94+
for name, plugin := range diffPlugins {
95+
var matched bool
96+
for _, p := range plugin.Meta.Platforms {
97+
if target.Match(p) {
98+
matched = true
99+
}
100+
}
101+
if !matched {
102+
continue
103+
}
104+
if applier != nil {
105+
log.G(ic.Context).Warnf("multiple differs match for platform, set `differ` option to choose, skipping %q", name)
106+
continue
107+
}
108+
inst, err := plugin.Instance()
109+
if err != nil {
110+
return nil, fmt.Errorf("failed to get instance for diff plugin %q: %w", name, err)
111+
}
112+
applier = inst.(diff.Applier)
113+
}
114+
}
115+
if applier == nil {
116+
return nil, fmt.Errorf("no matching diff plugins: %w", errdefs.ErrNotFound)
80117
}
81118

82119
up := unpack.Platform{
83-
Platform: platforms.OnlyStrict(p),
84-
SnapshotterKey: uc.snapshotter,
85-
Snapshotter: s.(snapshots.Snapshotter),
86-
Applier: d.(diff.Applier),
120+
Platform: target,
121+
SnapshotterKey: uc.Snapshotter,
122+
Snapshotter: sn,
123+
Applier: applier,
87124
}
88125
lc.UnpackPlatforms = append(lc.UnpackPlatforms, up)
89126
}
90-
lc.RegistryConfigPath = config.registryConfigPath
127+
lc.RegistryConfigPath = config.RegistryConfigPath
91128

92129
return local.NewTransferService(l.(leases.Manager), ms.ContentStore(), metadata.NewImageStore(ms), &lc), nil
93130
},
94131
})
95132
}
96133

97134
type transferConfig struct {
98-
// maxConcurrentDownloads is the max concurrent content downloads for pull.
99-
maxConcurrentDownloads int `toml:"max_concurrent_downloads"`
135+
// MaxConcurrentDownloads is the max concurrent content downloads for pull.
136+
MaxConcurrentDownloads int `toml:"max_concurrent_downloads"`
100137

101-
// maxConcurrentUploadedLayers is the max concurrent uploads for push
102-
maxConcurrentUploadedLayers int `toml:"max_concurrent_uploaded_layers"`
138+
// MaxConcurrentUploadedLayers is the max concurrent uploads for push
139+
MaxConcurrentUploadedLayers int `toml:"max_concurrent_uploaded_layers"`
103140

104-
// unpackConfiguration is used to read config from toml
105-
unpackConfiguration []unpackConfiguration `toml:"unpack_config"`
141+
// UnpackConfiguration is used to read config from toml
142+
UnpackConfiguration []unpackConfiguration `toml:"unpack_config"`
106143

107-
// registryConfigPath is a path to the root directory containing registry-specific configurations
108-
registryConfigPath string `toml:"config_path"`
144+
// RegistryConfigPath is a path to the root directory containing registry-specific configurations
145+
RegistryConfigPath string `toml:"config_path"`
109146
}
110147

111148
type unpackConfiguration struct {
112-
platform string
113-
snapshotter string
149+
// Platform is the target unpack platform to match
150+
Platform string `toml:"platform"`
151+
152+
// Snapshotter is the snapshotter to use to unpack
153+
Snapshotter string `toml:"snapshotter"`
154+
155+
// Differ is the diff plugin to be used for apply
156+
Differ string `toml:"differ"`
114157
}
115158

116159
func defaultConfig() *transferConfig {
117160
return &transferConfig{
118-
maxConcurrentDownloads: 3,
119-
maxConcurrentUploadedLayers: 3,
120-
unpackConfiguration: []unpackConfiguration{
161+
MaxConcurrentDownloads: 3,
162+
MaxConcurrentUploadedLayers: 3,
163+
UnpackConfiguration: []unpackConfiguration{
121164
{
122-
platform: platforms.Format(platforms.DefaultSpec()),
123-
snapshotter: containerd.DefaultSnapshotter,
165+
Platform: platforms.Format(platforms.DefaultSpec()),
166+
Snapshotter: containerd.DefaultSnapshotter,
124167
},
125168
},
126169
}

0 commit comments

Comments
 (0)