Create config struct to take user input
Signed-off-by: Tony Fang <nhfang@amazon.com>
This commit is contained in:
@@ -17,9 +17,14 @@
|
||||
package transfer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/containerd/containerd"
|
||||
"github.com/containerd/containerd/leases"
|
||||
"github.com/containerd/containerd/metadata"
|
||||
"github.com/containerd/containerd/pkg/transfer/local"
|
||||
"github.com/containerd/containerd/pkg/unpack"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
|
||||
// Load packages with type registrations
|
||||
@@ -36,9 +41,9 @@ func init() {
|
||||
plugin.LeasePlugin,
|
||||
plugin.MetadataPlugin,
|
||||
},
|
||||
Config: local.DefaultConfig(),
|
||||
Config: defaultConfig(),
|
||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
config := ic.Config.(*local.TransferConfig)
|
||||
config := ic.Config.(*transferConfig)
|
||||
m, err := ic.Get(plugin.MetadataPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -49,7 +54,57 @@ func init() {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return local.NewTransferService(l.(leases.Manager), ms.ContentStore(), metadata.NewImageStore(ms), config), nil
|
||||
// Set configuration based on default or user input
|
||||
var lc local.TransferConfig
|
||||
lc.MaxConcurrentDownloads = config.maxConcurrentDownloads
|
||||
lc.MaxConcurrentUploadedLayers = config.maxConcurrentUploadedLayers
|
||||
for _, uc := range config.unpackConfiguration {
|
||||
p, err := platforms.Parse(uc.platform)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s: platform configuration %v invalid", plugin.TransferPlugin, uc.platform)
|
||||
}
|
||||
|
||||
up := unpack.Platform{
|
||||
Platform: platforms.OnlyStrict(p),
|
||||
SnapshotterKey: uc.snapshotter,
|
||||
}
|
||||
lc.UnpackPlatforms = append(lc.UnpackPlatforms, up)
|
||||
}
|
||||
lc.RegistryConfigPath = config.registryConfigPath
|
||||
|
||||
return local.NewTransferService(l.(leases.Manager), ms.ContentStore(), metadata.NewImageStore(ms), &lc), nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
type transferConfig struct {
|
||||
// maxConcurrentDownloads is the max concurrent content downloads for pull.
|
||||
maxConcurrentDownloads int `toml:"max_concurrent_downloads"`
|
||||
|
||||
// maxConcurrentUploadedLayers is the max concurrent uploads for push
|
||||
maxConcurrentUploadedLayers int `toml:"max_concurrent_uploaded_layers"`
|
||||
|
||||
// unpackConfiguration is used to read config from toml
|
||||
unpackConfiguration []unpackConfiguration `toml:"unpack_config"`
|
||||
|
||||
// registryConfigPath is a path to the root directory containing registry-specific configurations
|
||||
registryConfigPath string `toml:"config_path"`
|
||||
}
|
||||
|
||||
type unpackConfiguration struct {
|
||||
platform string
|
||||
snapshotter string
|
||||
}
|
||||
|
||||
func defaultConfig() *transferConfig {
|
||||
return &transferConfig{
|
||||
maxConcurrentDownloads: 3,
|
||||
maxConcurrentUploadedLayers: 3,
|
||||
unpackConfiguration: []unpackConfiguration{
|
||||
{
|
||||
platform: platforms.Format(platforms.DefaultSpec()),
|
||||
snapshotter: containerd.DefaultSnapshotter,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user