From a43fa9f284e5f0a4c50f65f80a88a3a91d3e5f75 Mon Sep 17 00:00:00 2001 From: Hajime Tazaki Date: Thu, 2 Sep 2021 11:20:58 +0900 Subject: [PATCH] darwin: runtime support This commit attemts to support containerd on darwin platform. With an external runtime shim, ctr run should work with, for instance, --runtime=io.containerd.runu.v1. An example of runtime and shim is managed under different repository (github.com/ukontainer/runu/). Signed-off-by: Hajime Tazaki --- defaults/defaults_darwin.go | 3 +-- platforms/defaults_darwin.go | 44 ++++++++++++++++++++++++++++++++++ platforms/defaults_unix.go | 4 ++-- services/tasks/local_darwin.go | 35 +++++++++++++++++++++++++++ services/tasks/local_unix.go | 4 ++-- 5 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 platforms/defaults_darwin.go create mode 100644 services/tasks/local_darwin.go diff --git a/defaults/defaults_darwin.go b/defaults/defaults_darwin.go index 79a834ea2..1391884cd 100644 --- a/defaults/defaults_darwin.go +++ b/defaults/defaults_darwin.go @@ -30,8 +30,7 @@ const ( // DefaultFIFODir is the default location used by client-side cio library // to store FIFOs. DefaultFIFODir = "/var/run/containerd/fifo" - // DefaultRuntime is the default Darwin runtime. - // NOTE: there is no runtime on Darwin as of now. + // DefaultRuntime would be a multiple of choices, thus empty DefaultRuntime = "" // DefaultConfigDir is the default location for config files. DefaultConfigDir = "/etc/containerd" diff --git a/platforms/defaults_darwin.go b/platforms/defaults_darwin.go new file mode 100644 index 000000000..386edc7d7 --- /dev/null +++ b/platforms/defaults_darwin.go @@ -0,0 +1,44 @@ +// +build darwin + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package platforms + +import ( + "runtime" + + specs "github.com/opencontainers/image-spec/specs-go/v1" +) + +// DefaultSpec returns the current platform's default platform specification. +func DefaultSpec() specs.Platform { + return specs.Platform{ + OS: runtime.GOOS, + Architecture: runtime.GOARCH, + // The Variant field will be empty if arch != ARM. + Variant: cpuVariant(), + } +} + +// Default returns the default matcher for the platform. +func Default() MatchComparer { + return Ordered(DefaultSpec(), specs.Platform{ + // darwin runtime also supports Linux binary via runu/LKL + OS: "linux", + Architecture: runtime.GOARCH, + }) +} diff --git a/platforms/defaults_unix.go b/platforms/defaults_unix.go index e88b5b0d0..49690f1b3 100644 --- a/platforms/defaults_unix.go +++ b/platforms/defaults_unix.go @@ -1,5 +1,5 @@ -//go:build !windows -// +build !windows +//go:build !windows && !darwin +// +build !windows,!darwin /* Copyright The containerd Authors. diff --git a/services/tasks/local_darwin.go b/services/tasks/local_darwin.go new file mode 100644 index 000000000..4c3d7fc3a --- /dev/null +++ b/services/tasks/local_darwin.go @@ -0,0 +1,35 @@ +// +build darwin + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package tasks + +import ( + "github.com/containerd/containerd/plugin" + "github.com/containerd/containerd/runtime" +) + +var tasksServiceRequires = []plugin.Type{ + plugin.RuntimePluginV2, + plugin.MetadataPlugin, + plugin.TaskMonitorPlugin, +} + +// loadV1Runtimes on darwin returns an empty map. There are no v1 runtimes +func loadV1Runtimes(ic *plugin.InitContext) (map[string]runtime.PlatformRuntime, error) { + return make(map[string]runtime.PlatformRuntime), nil +} diff --git a/services/tasks/local_unix.go b/services/tasks/local_unix.go index bf0410407..50a29f612 100644 --- a/services/tasks/local_unix.go +++ b/services/tasks/local_unix.go @@ -1,5 +1,5 @@ -//go:build !windows && !freebsd -// +build !windows,!freebsd +//go:build !windows && !freebsd && !darwin +// +build !windows,!freebsd,!darwin /* Copyright The containerd Authors.