Merge pull request #3033 from tonistiigi/runtime-platforms
runtime: allow specifying supported platforms with config
This commit is contained in:
commit
31438b61f9
@ -29,11 +29,19 @@ import (
|
|||||||
"github.com/containerd/containerd/metadata"
|
"github.com/containerd/containerd/metadata"
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
"github.com/containerd/containerd/namespaces"
|
"github.com/containerd/containerd/namespaces"
|
||||||
|
"github.com/containerd/containerd/platforms"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/runtime"
|
"github.com/containerd/containerd/runtime"
|
||||||
|
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
bolt "go.etcd.io/bbolt"
|
bolt "go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Config for the v2 runtime
|
||||||
|
type Config struct {
|
||||||
|
// Supported platforms
|
||||||
|
Platforms []string `toml:"platforms"`
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.RuntimePluginV2,
|
Type: plugin.RuntimePluginV2,
|
||||||
@ -41,8 +49,16 @@ func init() {
|
|||||||
Requires: []plugin.Type{
|
Requires: []plugin.Type{
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
},
|
},
|
||||||
|
Config: &Config{
|
||||||
|
Platforms: defaultPlatforms(),
|
||||||
|
},
|
||||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||||
ic.Meta.Platforms = supportedPlatforms()
|
supportedPlatforms, err := parsePlatforms(ic.Config.(*Config).Platforms)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ic.Meta.Platforms = supportedPlatforms
|
||||||
if err := os.MkdirAll(ic.Root, 0711); err != nil {
|
if err := os.MkdirAll(ic.Root, 0711); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -262,3 +278,15 @@ func (m *TaskManager) cleanupWorkDirs(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parsePlatforms(platformStr []string) ([]ocispec.Platform, error) {
|
||||||
|
p := make([]ocispec.Platform, len(platformStr))
|
||||||
|
for i, v := range platformStr {
|
||||||
|
parsed, err := platforms.Parse(v)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
p[i] = parsed
|
||||||
|
}
|
||||||
|
return p, nil
|
||||||
|
}
|
||||||
|
@ -20,9 +20,8 @@ package v2
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containerd/containerd/platforms"
|
"github.com/containerd/containerd/platforms"
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func supportedPlatforms() []ocispec.Platform {
|
func defaultPlatforms() []string {
|
||||||
return []ocispec.Platform{platforms.DefaultSpec()}
|
return []string{platforms.DefaultString()}
|
||||||
}
|
}
|
||||||
|
@ -20,15 +20,11 @@ package v2
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containerd/containerd/platforms"
|
"github.com/containerd/containerd/platforms"
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func supportedPlatforms() []ocispec.Platform {
|
func defaultPlatforms() []string {
|
||||||
return []ocispec.Platform{
|
return []string{
|
||||||
platforms.DefaultSpec(),
|
platforms.DefaultString(),
|
||||||
{
|
"linux/amd64",
|
||||||
OS: "linux",
|
|
||||||
Architecture: "amd64",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user