Skip to content

Commit 3c8469a

Browse files
committed
Use Platform instead of generated API
Signed-off-by: Maksym Pavlenko <[email protected]>
1 parent d0893da commit 3c8469a

6 files changed

Lines changed: 27 additions & 20 deletions

File tree

pkg/cri/sbserver/container_create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
3434

3535
"github.com/containerd/containerd"
36-
"github.com/containerd/containerd/api/types"
3736
"github.com/containerd/containerd/containers"
3837
"github.com/containerd/containerd/log"
3938
"github.com/containerd/containerd/oci"
@@ -45,6 +44,7 @@ import (
4544
containerstore "github.com/containerd/containerd/pkg/cri/store/container"
4645
"github.com/containerd/containerd/pkg/cri/util"
4746
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
47+
"github.com/containerd/containerd/platforms"
4848
)
4949

5050
func init() {
@@ -407,7 +407,7 @@ const (
407407

408408
// buildContainerSpec build container's OCI spec depending on controller's target platform OS.
409409
func (c *criService) buildContainerSpec(
410-
platform *types.Platform,
410+
platform platforms.Platform,
411411
id string,
412412
sandboxID string,
413413
sandboxPid uint32,

pkg/cri/sbserver/container_create_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import (
2222
goruntime "runtime"
2323
"testing"
2424

25-
"github.com/containerd/containerd/api/types"
25+
"github.com/containerd/containerd/platforms"
26+
2627
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
2728
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
2829
"github.com/stretchr/testify/assert"
@@ -35,7 +36,7 @@ import (
3536
"github.com/containerd/containerd/pkg/cri/opts"
3637
)
3738

38-
var currentPlatform = &types.Platform{OS: goruntime.GOOS, Architecture: goruntime.GOARCH}
39+
var currentPlatform = platforms.DefaultSpec()
3940

4041
func checkMount(t *testing.T, mounts []runtimespec.Mount, src, dest, typ string,
4142
contains, notcontains []string) {

pkg/cri/sbserver/podsandbox/controller.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ package podsandbox
1919
import (
2020
"context"
2121
"fmt"
22-
goruntime "runtime"
2322
"time"
2423

24+
"github.com/sirupsen/logrus"
25+
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
26+
2527
"github.com/containerd/containerd"
2628
eventtypes "github.com/containerd/containerd/api/events"
2729
api "github.com/containerd/containerd/api/services/sandbox/v1"
28-
"github.com/containerd/containerd/api/types"
2930
"github.com/containerd/containerd/errdefs"
3031
"github.com/containerd/containerd/oci"
3132
criconfig "github.com/containerd/containerd/pkg/cri/config"
3233
imagestore "github.com/containerd/containerd/pkg/cri/store/image"
3334
sandboxstore "github.com/containerd/containerd/pkg/cri/store/sandbox"
3435
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
3536
osinterface "github.com/containerd/containerd/pkg/os"
37+
"github.com/containerd/containerd/platforms"
3638
"github.com/containerd/containerd/protobuf"
3739
"github.com/containerd/containerd/sandbox"
38-
"github.com/sirupsen/logrus"
39-
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
4040
)
4141

4242
// CRIService interface contains things required by controller, but not yet refactored from criService.
@@ -86,11 +86,8 @@ func New(
8686

8787
var _ sandbox.Controller = (*Controller)(nil)
8888

89-
func (c *Controller) Platform(_ctx context.Context, _sandboxID string) (*types.Platform, error) {
90-
return &types.Platform{
91-
OS: goruntime.GOOS,
92-
Architecture: goruntime.GOARCH,
93-
}, nil
89+
func (c *Controller) Platform(_ctx context.Context, _sandboxID string) (platforms.Platform, error) {
90+
return platforms.DefaultSpec(), nil
9491
}
9592

9693
func (c *Controller) Wait(ctx context.Context, sandboxID string) (*api.ControllerWaitResponse, error) {

platforms/platforms.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,18 @@ import (
114114
"strconv"
115115
"strings"
116116

117-
"github.com/containerd/containerd/errdefs"
118117
specs "github.com/opencontainers/image-spec/specs-go/v1"
118+
119+
"github.com/containerd/containerd/errdefs"
119120
)
120121

121122
var (
122123
specifierRe = regexp.MustCompile(`^[A-Za-z0-9_-]+$`)
123124
)
124125

126+
// Platform is a type alias for convenience, so there is no need to import image-spec package everywhere.
127+
type Platform = specs.Platform
128+
125129
// Matcher matches platforms specifications, provided by an image or runtime.
126130
type Matcher interface {
127131
Match(platform specs.Platform) bool

sandbox/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121

2222
"github.com/containerd/containerd/api/services/sandbox/v1"
23-
"github.com/containerd/containerd/api/types"
23+
"github.com/containerd/containerd/platforms"
2424
)
2525

2626
// Controller is an interface to manage sandboxes at runtime.
@@ -33,7 +33,7 @@ type Controller interface {
3333
Start(ctx context.Context, sandboxID string) (*sandbox.ControllerStartResponse, error)
3434
// Platform returns target sandbox OS that will be used by Controller.
3535
// containerd will rely on this to generate proper OCI spec.
36-
Platform(_ctx context.Context, _sandboxID string) (*types.Platform, error)
36+
Platform(_ctx context.Context, _sandboxID string) (platforms.Platform, error)
3737
// Stop will stop sandbox instance
3838
Stop(ctx context.Context, sandboxID string) (*sandbox.ControllerStopResponse, error)
3939
// Wait blocks until sandbox process exits.

sandbox/proxy/controller.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"context"
2121

2222
api "github.com/containerd/containerd/api/services/sandbox/v1"
23-
"github.com/containerd/containerd/api/types"
2423
"github.com/containerd/containerd/errdefs"
24+
"github.com/containerd/containerd/platforms"
2525
sb "github.com/containerd/containerd/sandbox"
2626
)
2727

@@ -55,13 +55,18 @@ func (s *remoteSandboxController) Start(ctx context.Context, sandboxID string) (
5555
return resp, nil
5656
}
5757

58-
func (s *remoteSandboxController) Platform(ctx context.Context, sandboxID string) (*types.Platform, error) {
58+
func (s *remoteSandboxController) Platform(ctx context.Context, sandboxID string) (platforms.Platform, error) {
5959
resp, err := s.client.Platform(ctx, &api.ControllerPlatformRequest{SandboxID: sandboxID})
6060
if err != nil {
61-
return nil, errdefs.FromGRPC(err)
61+
return platforms.Platform{}, errdefs.FromGRPC(err)
6262
}
6363

64-
return resp.GetPlatform(), nil
64+
platform := resp.GetPlatform()
65+
return platforms.Platform{
66+
Architecture: platform.GetArchitecture(),
67+
OS: platform.GetOS(),
68+
Variant: platform.GetVariant(),
69+
}, nil
6570
}
6671

6772
func (s *remoteSandboxController) Stop(ctx context.Context, sandboxID string) (*api.ControllerStopResponse, error) {

0 commit comments

Comments
 (0)