Skip to content

Commit 1e3c662

Browse files
committed
[release/1.7] remove uses of platforms.Platform alias
Commit 3c8469a removed uses of the api types.Platform type from public interfaces, instead using the type from the OCI image spec. For convenience, it also introduced an alias in the platforms package. While this alias allows packages that already import containerd's platforms package (now a separate module), it may also cause confusion (it's not clear that it's an alias for the OCI type), and for packages that do not depend on containerd's platforms package / module may now be resulting in an extra dependency. Let's remove the use of this alias, and instead use the OCI type directly. Equivalent of 446e635 in main. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 300a6de commit 1e3c662

6 files changed

Lines changed: 19 additions & 18 deletions

File tree

pkg/cri/sbserver/container_create.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
338338
// volumeMounts sets up image volumes for container. Rely on the removal of container
339339
// root directory to do cleanup. Note that image volume will be skipped, if there is criMounts
340340
// specified with the same destination.
341-
func (c *criService) volumeMounts(platform platforms.Platform, containerRootDir string, criMounts []*runtime.Mount, config *imagespec.ImageConfig) []*runtime.Mount {
341+
func (c *criService) volumeMounts(platform imagespec.Platform, containerRootDir string, criMounts []*runtime.Mount, config *imagespec.ImageConfig) []*runtime.Mount {
342342
if len(config.Volumes) == 0 {
343343
return nil
344344
}
@@ -374,7 +374,7 @@ func (c *criService) volumeMounts(platform platforms.Platform, containerRootDir
374374
}
375375

376376
// runtimeSpec returns a default runtime spec used in cri-containerd.
377-
func (c *criService) runtimeSpec(id string, platform platforms.Platform, baseSpecFile string, opts ...oci.SpecOpts) (*runtimespec.Spec, error) {
377+
func (c *criService) runtimeSpec(id string, platform imagespec.Platform, baseSpecFile string, opts ...oci.SpecOpts) (*runtimespec.Spec, error) {
378378
// GenerateSpec needs namespace.
379379
ctx := util.NamespacedContext()
380380
container := &containers.Container{ID: id}
@@ -468,7 +468,7 @@ func generateUserString(username string, uid, gid *runtime.Int64Value) (string,
468468
// runtime information (rootfs mounted), or platform specific checks with
469469
// no defined workaround (yet) to specify for other platforms.
470470
func (c *criService) platformSpecOpts(
471-
platform platforms.Platform,
471+
platform imagespec.Platform,
472472
config *runtime.ContainerConfig,
473473
imageConfig *imagespec.ImageConfig,
474474
) ([]oci.SpecOpts, error) {
@@ -515,7 +515,7 @@ func (c *criService) platformSpecOpts(
515515

516516
// buildContainerSpec build container's OCI spec depending on controller's target platform OS.
517517
func (c *criService) buildContainerSpec(
518-
platform platforms.Platform,
518+
platform imagespec.Platform,
519519
id string,
520520
sandboxID string,
521521
sandboxPid uint32,

pkg/cri/sbserver/container_create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func TestVolumeMounts(t *testing.T) {
220220
testContainerRootDir := "test-container-root"
221221
for desc, test := range map[string]struct {
222222
criMounts []*runtime.Mount
223-
platform platforms.Platform
223+
platform imagespec.Platform
224224
imageVolumes map[string]struct{}
225225
expectedMountDest []string
226226
}{
@@ -265,7 +265,7 @@ func TestVolumeMounts(t *testing.T) {
265265
},
266266
},
267267
"should make relative paths absolute on Linux": {
268-
platform: platforms.Platform{OS: "linux"},
268+
platform: imagespec.Platform{OS: "linux"},
269269
imageVolumes: map[string]struct{}{
270270
"./test-volume-1": {},
271271
"C:/test-volume-2": {},

pkg/cri/sbserver/podsandbox/controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"time"
2323

24+
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
2425
"github.com/sirupsen/logrus"
2526
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
2627

@@ -85,7 +86,7 @@ func New(
8586

8687
var _ sandbox.Controller = (*Controller)(nil)
8788

88-
func (c *Controller) Platform(_ctx context.Context, _sandboxID string) (platforms.Platform, error) {
89+
func (c *Controller) Platform(_ctx context.Context, _sandboxID string) (imagespec.Platform, error) {
8990
return platforms.DefaultSpec(), nil
9091
}
9192

plugins/sandbox/controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import (
2424
runtimeAPI "github.com/containerd/containerd/api/runtime/sandbox/v1"
2525
"github.com/containerd/containerd/events"
2626
"github.com/containerd/containerd/events/exchange"
27-
"github.com/containerd/containerd/platforms"
2827
"github.com/containerd/containerd/plugin"
2928
"github.com/containerd/containerd/runtime"
3029
v2 "github.com/containerd/containerd/runtime/v2"
3130
"github.com/containerd/containerd/sandbox"
3231
"github.com/containerd/errdefs"
3332
"github.com/containerd/log"
3433

34+
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
3535
"google.golang.org/protobuf/types/known/anypb"
3636
)
3737

@@ -178,18 +178,18 @@ func (c *controllerLocal) Start(ctx context.Context, sandboxID string) (sandbox.
178178
}, nil
179179
}
180180

181-
func (c *controllerLocal) Platform(ctx context.Context, sandboxID string) (platforms.Platform, error) {
181+
func (c *controllerLocal) Platform(ctx context.Context, sandboxID string) (imagespec.Platform, error) {
182182
svc, err := c.getSandbox(ctx, sandboxID)
183183
if err != nil {
184-
return platforms.Platform{}, err
184+
return imagespec.Platform{}, err
185185
}
186186

187187
response, err := svc.Platform(ctx, &runtimeAPI.PlatformRequest{SandboxID: sandboxID})
188188
if err != nil {
189-
return platforms.Platform{}, fmt.Errorf("failed to get sandbox platform: %w", errdefs.FromGRPC(err))
189+
return imagespec.Platform{}, fmt.Errorf("failed to get sandbox platform: %w", errdefs.FromGRPC(err))
190190
}
191191

192-
var platform platforms.Platform
192+
var platform imagespec.Platform
193193
if p := response.GetPlatform(); p != nil {
194194
platform.OS = p.OS
195195
platform.Architecture = p.Architecture

sandbox/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"time"
2323

2424
"github.com/containerd/containerd/api/types"
25-
"github.com/containerd/containerd/platforms"
2625
"github.com/containerd/typeurl/v2"
26+
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
2727
)
2828

2929
type CreateOptions struct {
@@ -90,7 +90,7 @@ type Controller interface {
9090
Start(ctx context.Context, sandboxID string) (ControllerInstance, error)
9191
// Platform returns target sandbox OS that will be used by Controller.
9292
// containerd will rely on this to generate proper OCI spec.
93-
Platform(_ctx context.Context, _sandboxID string) (platforms.Platform, error)
93+
Platform(_ctx context.Context, _sandboxID string) (imagespec.Platform, error)
9494
// Stop will stop sandbox instance
9595
Stop(ctx context.Context, sandboxID string, opts ...StopOpt) error
9696
// Wait blocks until sandbox process exits.

sandbox/proxy/controller.go

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

2222
api "github.com/containerd/containerd/api/services/sandbox/v1"
23-
"github.com/containerd/containerd/platforms"
2423
"github.com/containerd/containerd/sandbox"
2524
"github.com/containerd/errdefs"
25+
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
2626
"google.golang.org/protobuf/types/known/anypb"
2727
)
2828

@@ -73,14 +73,14 @@ func (s *remoteSandboxController) Start(ctx context.Context, sandboxID string) (
7373
}, nil
7474
}
7575

76-
func (s *remoteSandboxController) Platform(ctx context.Context, sandboxID string) (platforms.Platform, error) {
76+
func (s *remoteSandboxController) Platform(ctx context.Context, sandboxID string) (imagespec.Platform, error) {
7777
resp, err := s.client.Platform(ctx, &api.ControllerPlatformRequest{SandboxID: sandboxID})
7878
if err != nil {
79-
return platforms.Platform{}, errdefs.FromGRPC(err)
79+
return imagespec.Platform{}, errdefs.FromGRPC(err)
8080
}
8181

8282
platform := resp.GetPlatform()
83-
return platforms.Platform{
83+
return imagespec.Platform{
8484
Architecture: platform.GetArchitecture(),
8585
OS: platform.GetOS(),
8686
Variant: platform.GetVariant(),

0 commit comments

Comments
 (0)