Add basic spec and mounts for Darwin

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko
2023-01-12 17:00:40 -08:00
parent a43d719ce2
commit 1ade777c24
7 changed files with 201 additions and 32 deletions

View File

@@ -21,11 +21,11 @@ import (
"path/filepath"
"runtime"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/platforms"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/containerd/containerd/containers"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/platforms"
)
const (
@@ -66,15 +66,19 @@ func generateDefaultSpecWithPlatform(ctx context.Context, platform, id string, s
return err
}
if plat.OS == "windows" {
switch plat.OS {
case "windows":
err = populateDefaultWindowsSpec(ctx, s, id)
} else {
case "darwin":
err = populateDefaultDarwinSpec(s)
default:
err = populateDefaultUnixSpec(ctx, s, id)
if err == nil && runtime.GOOS == "windows" {
// To run LCOW we have a Linux and Windows section. Add an empty one now.
s.Windows = &specs.Windows{}
}
}
return err
}
@@ -207,3 +211,12 @@ func populateDefaultWindowsSpec(ctx context.Context, s *Spec, id string) error {
}
return nil
}
func populateDefaultDarwinSpec(s *Spec) error {
*s = Spec{
Version: specs.Version,
Root: &specs.Root{},
Process: &specs.Process{Cwd: "/"},
}
return nil
}

View File

@@ -30,17 +30,16 @@ import (
"strings"
"testing"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/errdefs"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/namespaces"
"github.com/opencontainers/runtime-spec/specs-go"
)
type blob []byte
@@ -302,13 +301,20 @@ func TestWithDefaultSpec(t *testing.T) {
t.Fatal(err)
}
var expected Spec
var err error
if runtime.GOOS == "windows" {
var (
expected Spec
err error
)
switch runtime.GOOS {
case "windows":
err = populateDefaultWindowsSpec(ctx, &expected, c.ID)
} else {
case "darwin":
err = populateDefaultDarwinSpec(&expected)
default:
err = populateDefaultUnixSpec(ctx, &expected, c.ID)
}
if err != nil {
t.Fatal(err)
}

View File

@@ -21,10 +21,11 @@ import (
"runtime"
"testing"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/containerd/containerd/containers"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/pkg/testutil"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
func TestGenerateSpec(t *testing.T) {
@@ -39,7 +40,7 @@ func TestGenerateSpec(t *testing.T) {
t.Fatal("GenerateSpec() returns a nil spec")
}
if runtime.GOOS != "windows" {
if runtime.GOOS == "linux" {
// check for matching caps
defaults := defaultUnixCaps()
for _, cl := range [][]string{
@@ -61,9 +62,9 @@ func TestGenerateSpec(t *testing.T) {
t.Errorf("ns at %d does not match set %q != %q", i, defaultNS[i], ns)
}
}
} else {
} else if runtime.GOOS == "windows" {
if s.Windows == nil {
t.Fatal("Windows section of spec not filled in on Windows platform")
t.Fatal("Windows section of spec not filled in for Windows spec")
}
}
@@ -122,7 +123,7 @@ func TestSpecWithTTY(t *testing.T) {
if !s.Process.Terminal {
t.Error("terminal net set WithTTY()")
}
if runtime.GOOS != "windows" {
if runtime.GOOS == "linux" {
v := s.Process.Env[len(s.Process.Env)-1]
if v != "TERM=xterm" {
t.Errorf("xterm not set in env for TTY")