From abc681ca5f69e79daadf63d51cc4e8700fa218c8 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Thu, 25 Nov 2021 09:47:44 +0100 Subject: [PATCH 01/10] katautils: Add Darwin stub for the netNS API And move the current implementation into a Linux only file. Signed-off-by: Samuel Ortiz --- src/runtime/pkg/katautils/network_darwin.go | 22 +++++++++++++++++++ .../{network.go => network_linux.go} | 0 2 files changed, 22 insertions(+) create mode 100644 src/runtime/pkg/katautils/network_darwin.go rename src/runtime/pkg/katautils/{network.go => network_linux.go} (100%) diff --git a/src/runtime/pkg/katautils/network_darwin.go b/src/runtime/pkg/katautils/network_darwin.go new file mode 100644 index 0000000000..d913557cb8 --- /dev/null +++ b/src/runtime/pkg/katautils/network_darwin.go @@ -0,0 +1,22 @@ +// Copyright (c) 2022 Apple Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// + +package katautils + +import ( + vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers" +) + +func EnterNetNS(networkID string, cb func() error) error { + return nil +} + +func SetupNetworkNamespace(config *vc.NetworkConfig) error { + return nil +} + +func cleanupNetNS(netNSPath string) error { + return nil +} diff --git a/src/runtime/pkg/katautils/network.go b/src/runtime/pkg/katautils/network_linux.go similarity index 100% rename from src/runtime/pkg/katautils/network.go rename to src/runtime/pkg/katautils/network_linux.go From 7d64ae7a417dd968cd355f4738764f9206f62eea Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Sat, 26 Feb 2022 10:49:52 +0100 Subject: [PATCH 02/10] runtime: Add a syscall wrapper package It allows to support syscall variations between host OSes. Signed-off-by: Samuel Ortiz --- src/runtime/pkg/syscall/syscall_darwin.go | 16 ++++++++++++++++ src/runtime/pkg/syscall/syscall_linux.go | 14 ++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/runtime/pkg/syscall/syscall_darwin.go create mode 100644 src/runtime/pkg/syscall/syscall_linux.go diff --git a/src/runtime/pkg/syscall/syscall_darwin.go b/src/runtime/pkg/syscall/syscall_darwin.go new file mode 100644 index 0000000000..a5cc79d18b --- /dev/null +++ b/src/runtime/pkg/syscall/syscall_darwin.go @@ -0,0 +1,16 @@ +// Copyright (c) 2022 Apple Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// + +package syscall + +import ( + "syscall" +) + +func Gettid() int { + // There is no equivalent to a thread ID on Darwin. + // We use the PID instead. + return syscall.Getpid() +} diff --git a/src/runtime/pkg/syscall/syscall_linux.go b/src/runtime/pkg/syscall/syscall_linux.go new file mode 100644 index 0000000000..b05fc156d1 --- /dev/null +++ b/src/runtime/pkg/syscall/syscall_linux.go @@ -0,0 +1,14 @@ +// Copyright (c) 2022 Apple Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// + +package syscall + +import ( + "syscall" +) + +func Gettid() int { + return syscall.Gettid() +} From 56751089c00dc388b476a217ee7ce80aceb50b27 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Thu, 25 Nov 2021 18:24:18 +0100 Subject: [PATCH 03/10] katautils: Use a syscall wrapper for the hook JSON state There is no real equivalent of a thread ID on Darwin. Signed-off-by: Samuel Ortiz --- src/runtime/pkg/katautils/hook.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime/pkg/katautils/hook.go b/src/runtime/pkg/katautils/hook.go index 303773e602..50ac95cb85 100644 --- a/src/runtime/pkg/katautils/hook.go +++ b/src/runtime/pkg/katautils/hook.go @@ -16,6 +16,7 @@ import ( "time" "github.com/kata-containers/kata-containers/src/runtime/pkg/katautils/katatrace" + syscallWrapper "github.com/kata-containers/kata-containers/src/runtime/pkg/syscall" "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" ) @@ -38,7 +39,7 @@ func runHook(ctx context.Context, spec specs.Spec, hook specs.Hook, cid, bundleP katatrace.AddTags(span, "path", hook.Path, "args", hook.Args) state := specs.State{ - Pid: syscall.Gettid(), + Pid: syscallWrapper.Gettid(), Bundle: bundlePath, ID: cid, Annotations: spec.Annotations, From ad0449195d1dda5d1dc588f66bc4fe2035d4aafe Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Thu, 25 Nov 2021 10:17:08 +0100 Subject: [PATCH 04/10] virtcontainers: Convert stats dev_t to uint64 We need to convert them to uint64 as their types may differ on various host OSes, but unix.Major|Minor takes a uint64 regardless. Signed-off-by: Samuel Ortiz --- src/runtime/virtcontainers/container.go | 8 ++++---- src/runtime/virtcontainers/device/config/config.go | 4 ++-- src/runtime/virtcontainers/device/config/pmem.go | 4 ++-- src/runtime/virtcontainers/kata_agent.go | 2 +- src/runtime/virtcontainers/mount.go | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/runtime/virtcontainers/container.go b/src/runtime/virtcontainers/container.go index b57f40e51b..582e196ae5 100644 --- a/src/runtime/virtcontainers/container.go +++ b/src/runtime/virtcontainers/container.go @@ -629,8 +629,8 @@ func (c *Container) createBlockDevices(ctx context.Context) error { HostPath: m.Source, ContainerPath: m.Destination, DevType: "b", - Major: int64(unix.Major(stat.Rdev)), - Minor: int64(unix.Minor(stat.Rdev)), + Major: int64(unix.Major(uint64(stat.Rdev))), + Minor: int64(unix.Minor(uint64(stat.Rdev))), ReadOnly: m.ReadOnly, } // Check whether source can be used as a pmem device @@ -1226,8 +1226,8 @@ func (c *Container) plugDevice(ctx context.Context, devicePath string) error { HostPath: devicePath, ContainerPath: filepath.Join(kataGuestSharedDir(), c.id), DevType: "b", - Major: int64(unix.Major(stat.Rdev)), - Minor: int64(unix.Minor(stat.Rdev)), + Major: int64(unix.Major(uint64(stat.Rdev))), + Minor: int64(unix.Minor(uint64(stat.Rdev))), }) if err != nil { return fmt.Errorf("device manager failed to create rootfs device for %q: %v", devicePath, err) diff --git a/src/runtime/virtcontainers/device/config/config.go b/src/runtime/virtcontainers/device/config/config.go index 835059ed6f..69be4f5832 100644 --- a/src/runtime/virtcontainers/device/config/config.go +++ b/src/runtime/virtcontainers/device/config/config.go @@ -425,8 +425,8 @@ func getVhostUserDevName(dirname string, majorNum, minorNum uint32) (string, err return "", err } - devMajor := unix.Major(devStat.Rdev) - devMinor := unix.Minor(devStat.Rdev) + devMajor := unix.Major(uint64(devStat.Rdev)) + devMinor := unix.Minor(uint64(devStat.Rdev)) if devMajor == majorNum && devMinor == minorNum { return file.Name(), nil } diff --git a/src/runtime/virtcontainers/device/config/pmem.go b/src/runtime/virtcontainers/device/config/pmem.go index 33ce4fdff4..81d1da9b57 100644 --- a/src/runtime/virtcontainers/device/config/pmem.go +++ b/src/runtime/virtcontainers/device/config/pmem.go @@ -51,8 +51,8 @@ func PmemDeviceInfo(source, destination string) (*DeviceInfo, error) { device := &DeviceInfo{ ContainerPath: destination, DevType: "b", - Major: int64(unix.Major(stat.Dev)), - Minor: int64(unix.Minor(stat.Dev)), + Major: int64(unix.Major(uint64(stat.Dev))), + Minor: int64(unix.Minor(uint64(stat.Dev))), Pmem: true, DriverOptions: make(map[string]string), } diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go index 1a10543051..47a1c1cc3f 100644 --- a/src/runtime/virtcontainers/kata_agent.go +++ b/src/runtime/virtcontainers/kata_agent.go @@ -2084,7 +2084,7 @@ func (k *kataAgent) copyFile(ctx context.Context, src, dst string) error { cpReq := &grpc.CopyFileRequest{ Path: dst, DirMode: uint32(DirMode), - FileMode: st.Mode, + FileMode: uint32(st.Mode), FileSize: fileSize, Uid: int32(st.Uid), Gid: int32(st.Gid), diff --git a/src/runtime/virtcontainers/mount.go b/src/runtime/virtcontainers/mount.go index 76e5fe3f49..c2879f2135 100644 --- a/src/runtime/virtcontainers/mount.go +++ b/src/runtime/virtcontainers/mount.go @@ -144,8 +144,8 @@ func getDeviceForPath(path string) (device, error) { if isHostDevice(path) { // stat.Rdev describes the device that this file (inode) represents. - devMajor = major(stat.Rdev) - devMinor = minor(stat.Rdev) + devMajor = major(uint64(stat.Rdev)) + devMinor = minor(uint64(stat.Rdev)) return device{ major: devMajor, @@ -154,8 +154,8 @@ func getDeviceForPath(path string) (device, error) { }, nil } // stat.Dev points to the underlying device containing the file - devMajor = major(stat.Dev) - devMinor = minor(stat.Dev) + devMajor = major(uint64(stat.Dev)) + devMinor = minor(uint64(stat.Dev)) path, err = filepath.Abs(path) if err != nil { From 5be188cc29a1281aa972d8db5103d1f4083e1fce Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Fri, 25 Feb 2022 11:43:57 -0800 Subject: [PATCH 05/10] utils: Add darwin stub Add a stub for utils_darwin to facilitate building this package on Darwin. We can probably drop this empty stub if we have better abstraction for the various parts of virtcontainers that call it today... Fixes:# 3777 Signed-off-by: Eric Ernst --- src/runtime/virtcontainers/utils/utils_darwin.go | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/runtime/virtcontainers/utils/utils_darwin.go diff --git a/src/runtime/virtcontainers/utils/utils_darwin.go b/src/runtime/virtcontainers/utils/utils_darwin.go new file mode 100644 index 0000000000..54b2124ce1 --- /dev/null +++ b/src/runtime/virtcontainers/utils/utils_darwin.go @@ -0,0 +1,10 @@ +// Copyright (c) 2022 Apple Inc. +// +// SPDX-License-Identifier: Apache-2.0 +// + +package utils + +func GetDevicePathAndFsTypeOptions(mountPoint string) (devicePath, fsType string, fsOptions []string, err error) { + return +} From cc58cf69931eb3d29ebc95a8053f8125146dfd78 Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Fri, 25 Feb 2022 11:50:04 -0800 Subject: [PATCH 06/10] resourcecontrol: convert stats dev_t to unit64types Their types may differ on various host OSes, but unix.Major|Minor always takes a uint64 Depends-on: github.com/kata-containers/tests#4516 Signed-off-by: Eric Ernst --- src/runtime/pkg/resourcecontrol/utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/pkg/resourcecontrol/utils.go b/src/runtime/pkg/resourcecontrol/utils.go index 9ab592be17..6fafe2d6a0 100644 --- a/src/runtime/pkg/resourcecontrol/utils.go +++ b/src/runtime/pkg/resourcecontrol/utils.go @@ -35,8 +35,8 @@ func DeviceToCgroupDeviceRule(device string) (*devices.Rule, error) { return nil, fmt.Errorf("unsupported device type: %v", devType) } - major := int64(unix.Major(st.Rdev)) - minor := int64(unix.Minor(st.Rdev)) + major := int64(unix.Major(uint64(st.Rdev))) + minor := int64(unix.Minor(uint64(st.Rdev))) deviceRule.Major = major deviceRule.Minor = minor From 6a5c634490882e517b3ba11b6b38a0ccbd526c98 Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Fri, 25 Feb 2022 12:05:01 -0800 Subject: [PATCH 07/10] resourcecontrol: SystemdCgroup check is not necessarily linux specific This utility function is also used to check the spec that will run in the guest - no need for this to be linux specific. Signed-off-by: Eric Ernst --- src/runtime/pkg/resourcecontrol/utils.go | 18 ++++++++++++++++++ src/runtime/pkg/resourcecontrol/utils_linux.go | 17 ----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/runtime/pkg/resourcecontrol/utils.go b/src/runtime/pkg/resourcecontrol/utils.go index 6fafe2d6a0..835cb54c47 100644 --- a/src/runtime/pkg/resourcecontrol/utils.go +++ b/src/runtime/pkg/resourcecontrol/utils.go @@ -7,6 +7,7 @@ package resourcecontrol import ( "fmt" + "strings" "github.com/opencontainers/runc/libcontainer/devices" "github.com/opencontainers/runtime-spec/specs-go" @@ -57,3 +58,20 @@ func DeviceToLinuxDevice(device string) (specs.LinuxDeviceCgroup, error) { Access: string(dev.Permissions), }, nil } + +func IsSystemdCgroup(cgroupPath string) bool { + + // If we are utilizing systemd to manage cgroups, we expect to receive a path + // in the format slice:scopeprefix:name. A typical example would be: + // + // system.slice:docker:6b4c4a4d0cc2a12c529dcb13a2b8e438dfb3b2a6af34d548d7d + // + // Based on this, let's split by the ':' delimiter and verify that the first + // section has .slice as a suffix. + parts := strings.Split(cgroupPath, ":") + if len(parts) == 3 && strings.HasSuffix(parts[0], ".slice") { + return true + } + + return false +} diff --git a/src/runtime/pkg/resourcecontrol/utils_linux.go b/src/runtime/pkg/resourcecontrol/utils_linux.go index 7a83db8f00..73d77dc235 100644 --- a/src/runtime/pkg/resourcecontrol/utils_linux.go +++ b/src/runtime/pkg/resourcecontrol/utils_linux.go @@ -43,23 +43,6 @@ func ValidCgroupPath(path string, systemdCgroup bool) (string, error) { return filepath.Join(DefaultResourceControllerID, filepath.Clean("/"+path)), nil } -func IsSystemdCgroup(cgroupPath string) bool { - - // If we are utilizing systemd to manage cgroups, we expect to receive a path - // in the format slice:scopeprefix:name. A typical example would be: - // - // system.slice:docker:6b4c4a4d0cc2a12c529dcb13a2b8e438dfb3b2a6af34d548d7d - // - // Based on this, let's split by the ':' delimiter and verify that the first - // section has .slice as a suffix. - parts := strings.Split(cgroupPath, ":") - if len(parts) == 3 && strings.HasSuffix(parts[0], ".slice") { - return true - } - - return false -} - func newProperty(name string, units interface{}) systemdDbus.Property { return systemdDbus.Property{ Name: name, From b31876eefb6fa1ffe0b95bc42ec1d09674320d04 Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Fri, 25 Feb 2022 14:34:41 -0800 Subject: [PATCH 08/10] device-manager: move linux-only test to a linux-only file We can't Mkdev on Darwin - let's make sure the vfio test is in a linux-only file. Signed-off-by: Eric Ernst --- .../device/manager/manager_linux_test.go | 100 ++++++++++++++++++ .../device/manager/manager_test.go | 81 -------------- 2 files changed, 100 insertions(+), 81 deletions(-) create mode 100644 src/runtime/virtcontainers/device/manager/manager_linux_test.go diff --git a/src/runtime/virtcontainers/device/manager/manager_linux_test.go b/src/runtime/virtcontainers/device/manager/manager_linux_test.go new file mode 100644 index 0000000000..78773fc5c2 --- /dev/null +++ b/src/runtime/virtcontainers/device/manager/manager_linux_test.go @@ -0,0 +1,100 @@ +// Copyright (c) 2017 Intel Corporation +// Copyright (c) 2018 Huawei Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// + +package manager + +import ( + "context" + "fmt" + "os" + "path/filepath" + "testing" + + ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils" + "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api" + "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" + "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/drivers" + "github.com/stretchr/testify/assert" + + "golang.org/x/sys/unix" +) + +func TestAttachVhostUserBlkDevice(t *testing.T) { + rootEnabled := true + tc := ktu.NewTestConstraint(false) + if tc.NotValid(ktu.NeedRoot()) { + rootEnabled = false + } + + tmpDir, err := os.MkdirTemp("", "") + dm := &deviceManager{ + blockDriver: VirtioBlock, + devices: make(map[string]api.Device), + vhostUserStoreEnabled: true, + vhostUserStorePath: tmpDir, + } + assert.Nil(t, err) + defer os.RemoveAll(tmpDir) + + vhostUserDevNodePath := filepath.Join(tmpDir, "/block/devices/") + vhostUserSockPath := filepath.Join(tmpDir, "/block/sockets/") + deviceNodePath := filepath.Join(vhostUserDevNodePath, "vhostblk0") + deviceSockPath := filepath.Join(vhostUserSockPath, "vhostblk0") + + err = os.MkdirAll(vhostUserDevNodePath, dirMode) + assert.Nil(t, err) + err = os.MkdirAll(vhostUserSockPath, dirMode) + assert.Nil(t, err) + _, err = os.Create(deviceSockPath) + assert.Nil(t, err) + + // mknod requires root privilege, call mock function for non-root to + // get VhostUserBlk device type. + if rootEnabled == true { + err = unix.Mknod(deviceNodePath, unix.S_IFBLK, int(unix.Mkdev(config.VhostUserBlkMajor, 0))) + assert.Nil(t, err) + } else { + savedFunc := config.GetVhostUserNodeStatFunc + + _, err = os.Create(deviceNodePath) + assert.Nil(t, err) + + config.GetVhostUserNodeStatFunc = func(devNodePath string, + devNodeStat *unix.Stat_t) error { + if deviceNodePath != devNodePath { + return fmt.Errorf("mock GetVhostUserNodeStatFunc error") + } + + devNodeStat.Rdev = unix.Mkdev(config.VhostUserBlkMajor, 0) + return nil + } + + defer func() { + config.GetVhostUserNodeStatFunc = savedFunc + }() + } + + path := "/dev/vda" + deviceInfo := config.DeviceInfo{ + HostPath: deviceNodePath, + ContainerPath: path, + DevType: "b", + Major: config.VhostUserBlkMajor, + Minor: 0, + } + + devReceiver := &api.MockDeviceReceiver{} + device, err := dm.NewDevice(deviceInfo) + assert.Nil(t, err) + _, ok := device.(*drivers.VhostUserBlkDevice) + assert.True(t, ok) + + err = device.Attach(context.Background(), devReceiver) + assert.Nil(t, err) + + err = device.Detach(context.Background(), devReceiver) + assert.Nil(t, err) +} diff --git a/src/runtime/virtcontainers/device/manager/manager_test.go b/src/runtime/virtcontainers/device/manager/manager_test.go index d6fab6d262..f0d7ef974d 100644 --- a/src/runtime/virtcontainers/device/manager/manager_test.go +++ b/src/runtime/virtcontainers/device/manager/manager_test.go @@ -8,19 +8,15 @@ package manager import ( "context" - "fmt" "os" "path/filepath" "strconv" "testing" - ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/drivers" "github.com/stretchr/testify/assert" - - "golang.org/x/sys/unix" ) const fileMode0640 = os.FileMode(0640) @@ -217,83 +213,6 @@ func TestAttachBlockDevice(t *testing.T) { assert.Nil(t, err) } -func TestAttachVhostUserBlkDevice(t *testing.T) { - rootEnabled := true - tc := ktu.NewTestConstraint(false) - if tc.NotValid(ktu.NeedRoot()) { - rootEnabled = false - } - - tmpDir, err := os.MkdirTemp("", "") - dm := &deviceManager{ - blockDriver: VirtioBlock, - devices: make(map[string]api.Device), - vhostUserStoreEnabled: true, - vhostUserStorePath: tmpDir, - } - assert.Nil(t, err) - defer os.RemoveAll(tmpDir) - - vhostUserDevNodePath := filepath.Join(tmpDir, "/block/devices/") - vhostUserSockPath := filepath.Join(tmpDir, "/block/sockets/") - deviceNodePath := filepath.Join(vhostUserDevNodePath, "vhostblk0") - deviceSockPath := filepath.Join(vhostUserSockPath, "vhostblk0") - - err = os.MkdirAll(vhostUserDevNodePath, dirMode) - assert.Nil(t, err) - err = os.MkdirAll(vhostUserSockPath, dirMode) - assert.Nil(t, err) - _, err = os.Create(deviceSockPath) - assert.Nil(t, err) - - // mknod requires root privilege, call mock function for non-root to - // get VhostUserBlk device type. - if rootEnabled == true { - err = unix.Mknod(deviceNodePath, unix.S_IFBLK, int(unix.Mkdev(config.VhostUserBlkMajor, 0))) - assert.Nil(t, err) - } else { - savedFunc := config.GetVhostUserNodeStatFunc - - _, err = os.Create(deviceNodePath) - assert.Nil(t, err) - - config.GetVhostUserNodeStatFunc = func(devNodePath string, - devNodeStat *unix.Stat_t) error { - if deviceNodePath != devNodePath { - return fmt.Errorf("mock GetVhostUserNodeStatFunc error") - } - - devNodeStat.Rdev = unix.Mkdev(config.VhostUserBlkMajor, 0) - return nil - } - - defer func() { - config.GetVhostUserNodeStatFunc = savedFunc - }() - } - - path := "/dev/vda" - deviceInfo := config.DeviceInfo{ - HostPath: deviceNodePath, - ContainerPath: path, - DevType: "b", - Major: config.VhostUserBlkMajor, - Minor: 0, - } - - devReceiver := &api.MockDeviceReceiver{} - device, err := dm.NewDevice(deviceInfo) - assert.Nil(t, err) - _, ok := device.(*drivers.VhostUserBlkDevice) - assert.True(t, ok) - - err = device.Attach(context.Background(), devReceiver) - assert.Nil(t, err) - - err = device.Detach(context.Background(), devReceiver) - assert.Nil(t, err) -} - func TestAttachDetachDevice(t *testing.T) { dm := NewDeviceManager(VirtioSCSI, false, "", nil) From e355a71860d62bb5312a395776dded73328be433 Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Fri, 25 Feb 2022 11:53:23 -0800 Subject: [PATCH 09/10] container: file is not linux specific This should not be linux specific -- drop restriction. Signed-off-by: Eric Ernst --- src/runtime/virtcontainers/container.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/runtime/virtcontainers/container.go b/src/runtime/virtcontainers/container.go index 582e196ae5..82aae79e37 100644 --- a/src/runtime/virtcontainers/container.go +++ b/src/runtime/virtcontainers/container.go @@ -1,6 +1,3 @@ -//go:build linux -// +build linux - // Copyright (c) 2016 Intel Corporation // Copyright (c) 2014,2015,2016,2017 Docker, Inc. // SPDX-License-Identifier: Apache-2.0 From 4afb278fe2c60ac59b20dc104b932c1f9be96466 Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Fri, 25 Feb 2022 14:06:56 -0800 Subject: [PATCH 10/10] ci: add github action to exercise darwin build, unit tests There are a few outstanding changes required to build the runtime on Darwin. Let's add a GitHub action to exercise build and unit tests of the packages which we do expect to work. Eventually this should be dropped and we can run any Darwin specific tests, or just add MacOS to the matrix for our static check OSes. Fixes: #3778 Signed-off-by: Eric Ernst --- .github/workflows/darwin-tests.yaml | 25 +++++++++++++++++ ci/darwin-test.sh | 42 +++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 .github/workflows/darwin-tests.yaml create mode 100755 ci/darwin-test.sh diff --git a/.github/workflows/darwin-tests.yaml b/.github/workflows/darwin-tests.yaml new file mode 100644 index 0000000000..5a83add32d --- /dev/null +++ b/.github/workflows/darwin-tests.yaml @@ -0,0 +1,25 @@ +on: + pull_request: + types: + - opened + - edited + - reopened + - synchronize + +name: Darwin tests +jobs: + test: + strategy: + matrix: + go-version: [1.16.x, 1.17.x] + os: [macos-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Checkout code + uses: actions/checkout@v2 + - name: Build utils + run: ./ci/darwin-test.sh diff --git a/ci/darwin-test.sh b/ci/darwin-test.sh new file mode 100755 index 0000000000..92317653be --- /dev/null +++ b/ci/darwin-test.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2022 Apple Inc. +# +# SPDX-License-Identifier: Apache-2.0 + +set -e + +cidir=$(dirname "$0") +runtimedir=$cidir/../src/runtime + +build_working_packages() { + # working packages: + device_api=$runtimedir/virtcontainers/device/api + device_config=$runtimedir/virtcontainers/device/config + device_drivers=$runtimedir/virtcontainers/device/drivers + device_manager=$runtimedir/virtcontainers/device/manager + rc_pkg_dir=$runtimedir/pkg/resourcecontrol/ + utils_pkg_dir=$runtimedir/virtcontainers/utils + + # broken packages :( : + #katautils=$runtimedir/pkg/katautils + #oci=$runtimedir/pkg/oci + #vc=$runtimedir/virtcontainers + + pkgs=( + "$device_api" + "$device_config" + "$device_drivers" + "$device_manager" + "$utils_pkg_dir" + "$rc_pkg_dir") + for pkg in "${pkgs[@]}"; do + echo building "$pkg" + pushd "$pkg" &>/dev/null + go build + go test + popd &>/dev/null + done +} + +build_working_packages