Skip to content

Commit

Permalink
Merge pull request containerd#10277 from thaJeztah/1.7_backport_remov…
Browse files Browse the repository at this point in the history
…e_use_of_platform_alias

[release/1.7] remove uses of platforms.Platform alias
  • Loading branch information
dmcgowan authored May 29, 2024
2 parents 300a6de + 1e3c662 commit 0a137f0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions pkg/cri/sbserver/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
// volumeMounts sets up image volumes for container. Rely on the removal of container
// root directory to do cleanup. Note that image volume will be skipped, if there is criMounts
// specified with the same destination.
func (c *criService) volumeMounts(platform platforms.Platform, containerRootDir string, criMounts []*runtime.Mount, config *imagespec.ImageConfig) []*runtime.Mount {
func (c *criService) volumeMounts(platform imagespec.Platform, containerRootDir string, criMounts []*runtime.Mount, config *imagespec.ImageConfig) []*runtime.Mount {
if len(config.Volumes) == 0 {
return nil
}
Expand Down Expand Up @@ -374,7 +374,7 @@ func (c *criService) volumeMounts(platform platforms.Platform, containerRootDir
}

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

// buildContainerSpec build container's OCI spec depending on controller's target platform OS.
func (c *criService) buildContainerSpec(
platform platforms.Platform,
platform imagespec.Platform,
id string,
sandboxID string,
sandboxPid uint32,
Expand Down
4 changes: 2 additions & 2 deletions pkg/cri/sbserver/container_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TestVolumeMounts(t *testing.T) {
testContainerRootDir := "test-container-root"
for desc, test := range map[string]struct {
criMounts []*runtime.Mount
platform platforms.Platform
platform imagespec.Platform
imageVolumes map[string]struct{}
expectedMountDest []string
}{
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestVolumeMounts(t *testing.T) {
},
},
"should make relative paths absolute on Linux": {
platform: platforms.Platform{OS: "linux"},
platform: imagespec.Platform{OS: "linux"},
imageVolumes: map[string]struct{}{
"./test-volume-1": {},
"C:/test-volume-2": {},
Expand Down
3 changes: 2 additions & 1 deletion pkg/cri/sbserver/podsandbox/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"time"

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

Expand Down Expand Up @@ -85,7 +86,7 @@ func New(

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

func (c *Controller) Platform(_ctx context.Context, _sandboxID string) (platforms.Platform, error) {
func (c *Controller) Platform(_ctx context.Context, _sandboxID string) (imagespec.Platform, error) {
return platforms.DefaultSpec(), nil
}

Expand Down
10 changes: 5 additions & 5 deletions plugins/sandbox/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import (
runtimeAPI "github.com/containerd/containerd/api/runtime/sandbox/v1"
"github.com/containerd/containerd/events"
"github.com/containerd/containerd/events/exchange"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/runtime"
v2 "github.com/containerd/containerd/runtime/v2"
"github.com/containerd/containerd/sandbox"
"github.com/containerd/errdefs"
"github.com/containerd/log"

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

Expand Down Expand Up @@ -178,18 +178,18 @@ func (c *controllerLocal) Start(ctx context.Context, sandboxID string) (sandbox.
}, nil
}

func (c *controllerLocal) Platform(ctx context.Context, sandboxID string) (platforms.Platform, error) {
func (c *controllerLocal) Platform(ctx context.Context, sandboxID string) (imagespec.Platform, error) {
svc, err := c.getSandbox(ctx, sandboxID)
if err != nil {
return platforms.Platform{}, err
return imagespec.Platform{}, err
}

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

var platform platforms.Platform
var platform imagespec.Platform
if p := response.GetPlatform(); p != nil {
platform.OS = p.OS
platform.Architecture = p.Architecture
Expand Down
4 changes: 2 additions & 2 deletions sandbox/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"time"

"github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/platforms"
"github.com/containerd/typeurl/v2"
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
)

type CreateOptions struct {
Expand Down Expand Up @@ -90,7 +90,7 @@ type Controller interface {
Start(ctx context.Context, sandboxID string) (ControllerInstance, error)
// Platform returns target sandbox OS that will be used by Controller.
// containerd will rely on this to generate proper OCI spec.
Platform(_ctx context.Context, _sandboxID string) (platforms.Platform, error)
Platform(_ctx context.Context, _sandboxID string) (imagespec.Platform, error)
// Stop will stop sandbox instance
Stop(ctx context.Context, sandboxID string, opts ...StopOpt) error
// Wait blocks until sandbox process exits.
Expand Down
8 changes: 4 additions & 4 deletions sandbox/proxy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"context"

api "github.com/containerd/containerd/api/services/sandbox/v1"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/sandbox"
"github.com/containerd/errdefs"
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
"google.golang.org/protobuf/types/known/anypb"
)

Expand Down Expand Up @@ -73,14 +73,14 @@ func (s *remoteSandboxController) Start(ctx context.Context, sandboxID string) (
}, nil
}

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

platform := resp.GetPlatform()
return platforms.Platform{
return imagespec.Platform{
Architecture: platform.GetArchitecture(),
OS: platform.GetOS(),
Variant: platform.GetVariant(),
Expand Down

0 comments on commit 0a137f0

Please sign in to comment.