Skip to content

Commit b553a12

Browse files
committed
runtime: allow specifying supported platforms with config
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 58dc067 commit b553a12

3 files changed

Lines changed: 35 additions & 12 deletions

File tree

runtime/v2/manager.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,36 @@ import (
2929
"github.com/containerd/containerd/metadata"
3030
"github.com/containerd/containerd/mount"
3131
"github.com/containerd/containerd/namespaces"
32+
"github.com/containerd/containerd/platforms"
3233
"github.com/containerd/containerd/plugin"
3334
"github.com/containerd/containerd/runtime"
35+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3436
bolt "go.etcd.io/bbolt"
3537
)
3638

39+
// Config for the v2 runtime
40+
type Config struct {
41+
// Supported platforms
42+
Platforms []string `toml:"platforms"`
43+
}
44+
3745
func init() {
3846
plugin.Register(&plugin.Registration{
3947
Type: plugin.RuntimePluginV2,
4048
ID: "task",
4149
Requires: []plugin.Type{
4250
plugin.MetadataPlugin,
4351
},
52+
Config: &Config{
53+
Platforms: defaultPlatforms(),
54+
},
4455
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
45-
ic.Meta.Platforms = supportedPlatforms()
56+
supportedPlatforms, err := parsePlatforms(ic.Config.(*Config).Platforms)
57+
if err != nil {
58+
return nil, err
59+
}
60+
61+
ic.Meta.Platforms = supportedPlatforms
4662
if err := os.MkdirAll(ic.Root, 0711); err != nil {
4763
return nil, err
4864
}
@@ -262,3 +278,15 @@ func (m *TaskManager) cleanupWorkDirs(ctx context.Context) error {
262278
}
263279
return nil
264280
}
281+
282+
func parsePlatforms(platformStr []string) ([]ocispec.Platform, error) {
283+
p := make([]ocispec.Platform, len(platformStr))
284+
for i, v := range platformStr {
285+
parsed, err := platforms.Parse(v)
286+
if err != nil {
287+
return nil, err
288+
}
289+
p[i] = parsed
290+
}
291+
return p, nil
292+
}

runtime/v2/manager_unix.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ package v2
2020

2121
import (
2222
"github.com/containerd/containerd/platforms"
23-
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2423
)
2524

26-
func supportedPlatforms() []ocispec.Platform {
27-
return []ocispec.Platform{platforms.DefaultSpec()}
25+
func defaultPlatforms() []string {
26+
return []string{platforms.DefaultString()}
2827
}

runtime/v2/manager_windows.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ package v2
2020

2121
import (
2222
"github.com/containerd/containerd/platforms"
23-
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2423
)
2524

26-
func supportedPlatforms() []ocispec.Platform {
27-
return []ocispec.Platform{
28-
platforms.DefaultSpec(),
29-
{
30-
OS: "linux",
31-
Architecture: "amd64",
32-
},
25+
func defaultPlatforms() []string {
26+
return []string{
27+
platforms.DefaultString(),
28+
"linux/amd64",
3329
}
3430
}

0 commit comments

Comments
 (0)