diff --git a/cmd/containerd/builtins_unix.go b/cmd/containerd/builtins_linux.go similarity index 97% rename from cmd/containerd/builtins_unix.go rename to cmd/containerd/builtins_linux.go index 0f1a8e936..9d1916d71 100644 --- a/cmd/containerd/builtins_unix.go +++ b/cmd/containerd/builtins_linux.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/integration/addition_gids_test.go b/integration/addition_gids_test.go index a5dadfd1c..c984cf7ad 100644 --- a/integration/addition_gids_test.go +++ b/integration/addition_gids_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/container_log_test.go b/integration/container_log_test.go index e748806b7..c11c874bf 100644 --- a/integration/container_log_test.go +++ b/integration/container_log_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/container_restart_test.go b/integration/container_restart_test.go index 44f51ba27..bce558e88 100644 --- a/integration/container_restart_test.go +++ b/integration/container_restart_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/container_stats_test.go b/integration/container_stats_test.go index f3aab2e83..6752b523f 100644 --- a/integration/container_stats_test.go +++ b/integration/container_stats_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/container_stop_test.go b/integration/container_stop_test.go index 7e6bb8f19..b270ed54b 100644 --- a/integration/container_stop_test.go +++ b/integration/container_stop_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/container_update_resources_test.go b/integration/container_update_resources_test.go index 3cbc8e7fc..83850e0b7 100644 --- a/integration/container_update_resources_test.go +++ b/integration/container_update_resources_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/container_without_image_ref_test.go b/integration/container_without_image_ref_test.go index bbbfeff2c..9fc897789 100644 --- a/integration/container_without_image_ref_test.go +++ b/integration/container_without_image_ref_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/containerd_image_test.go b/integration/containerd_image_test.go index d3b711381..1832b50ff 100644 --- a/integration/containerd_image_test.go +++ b/integration/containerd_image_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/duplicate_name_test.go b/integration/duplicate_name_test.go index eab4beae2..6c8532063 100644 --- a/integration/duplicate_name_test.go +++ b/integration/duplicate_name_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/image_load_test.go b/integration/image_load_test.go index 874de340f..ab7fed613 100644 --- a/integration/image_load_test.go +++ b/integration/image_load_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/imagefs_info_test.go b/integration/imagefs_info_test.go index b715221e8..1fc01e9ea 100644 --- a/integration/imagefs_info_test.go +++ b/integration/imagefs_info_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/main_test.go b/integration/main_test.go index b201a78c4..e8f4459b5 100644 --- a/integration/main_test.go +++ b/integration/main_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/no_metadata_test.go b/integration/no_metadata_test.go index 7740b0e6e..5766e19b4 100644 --- a/integration/no_metadata_test.go +++ b/integration/no_metadata_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/pod_dualstack_test.go b/integration/pod_dualstack_test.go index 89993e28c..acaacdd56 100644 --- a/integration/pod_dualstack_test.go +++ b/integration/pod_dualstack_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/pod_hostname_test.go b/integration/pod_hostname_test.go index a0a469a26..5b87f6dc8 100644 --- a/integration/pod_hostname_test.go +++ b/integration/pod_hostname_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/restart_test.go b/integration/restart_test.go index be76d017e..9c9051193 100644 --- a/integration/restart_test.go +++ b/integration/restart_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/runtime_handler_test.go b/integration/runtime_handler_test.go index 848a66b0e..f07bf7b90 100644 --- a/integration/runtime_handler_test.go +++ b/integration/runtime_handler_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/sandbox_clean_remove_test.go b/integration/sandbox_clean_remove_test.go index e0fff69a1..f74c145cc 100644 --- a/integration/sandbox_clean_remove_test.go +++ b/integration/sandbox_clean_remove_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/truncindex_test.go b/integration/truncindex_test.go index bfacc0bb8..f3e52300b 100644 --- a/integration/truncindex_test.go +++ b/integration/truncindex_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/integration/volume_copy_up_test.go b/integration/volume_copy_up_test.go index f54da88d3..d9b9f1533 100644 --- a/integration/volume_copy_up_test.go +++ b/integration/volume_copy_up_test.go @@ -1,4 +1,4 @@ -// +build !windows +// +build linux /* Copyright The containerd Authors. diff --git a/pkg/containerd/opts/spec_unix.go b/pkg/containerd/opts/spec_linux.go similarity index 99% rename from pkg/containerd/opts/spec_unix.go rename to pkg/containerd/opts/spec_linux.go index d644962d5..e358d8d6e 100644 --- a/pkg/containerd/opts/spec_unix.go +++ b/pkg/containerd/opts/spec_linux.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/containerd/opts/spec_unix_test.go b/pkg/containerd/opts/spec_linux_test.go similarity index 98% rename from pkg/containerd/opts/spec_unix_test.go rename to pkg/containerd/opts/spec_linux_test.go index bfc6cff62..1c9942f80 100644 --- a/pkg/containerd/opts/spec_unix_test.go +++ b/pkg/containerd/opts/spec_linux_test.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/netns/netns_unix.go b/pkg/netns/netns_linux.go similarity index 97% rename from pkg/netns/netns_unix.go rename to pkg/netns/netns_linux.go index 7449e2350..ff879d9d6 100644 --- a/pkg/netns/netns_unix.go +++ b/pkg/netns/netns_linux.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. @@ -25,6 +23,7 @@ // 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 @@ -40,12 +39,11 @@ import ( "runtime" "sync" + "github.com/containerd/containerd/mount" cnins "github.com/containernetworking/plugins/pkg/ns" "github.com/docker/docker/pkg/symlink" "github.com/pkg/errors" "golang.org/x/sys/unix" - - osinterface "github.com/containerd/cri/pkg/os" ) const nsRunDir = "/var/run/netns" @@ -141,7 +139,7 @@ func unmountNS(path string) error { if err != nil { return errors.Wrap(err, "failed to follow symlink") } - if err := osinterface.Unmount(path); err != nil && !os.IsNotExist(err) { + if err := mount.Unmount(path, unix.MNT_DETACH); err != nil && !os.IsNotExist(err) { return errors.Wrap(err, "failed to umount netns") } if err := os.RemoveAll(path); err != nil { diff --git a/pkg/netns/netns_other.go b/pkg/netns/netns_other.go new file mode 100644 index 000000000..253987ea6 --- /dev/null +++ b/pkg/netns/netns_other.go @@ -0,0 +1,58 @@ +// +build !windows,!linux + +/* + 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 netns + +import ( + "github.com/pkg/errors" +) + +var errNotImplementedOnUnix = errors.New("not implemented on unix") + +// NetNS holds network namespace. +type NetNS struct { + path string +} + +// NewNetNS creates a network namespace. +func NewNetNS() (*NetNS, error) { + return nil, errNotImplementedOnUnix +} + +// LoadNetNS loads existing network namespace. +func LoadNetNS(path string) *NetNS { + return &NetNS{path: path} +} + +// Remove removes network namepace. Remove is idempotent, meaning it might +// be invoked multiple times and provides consistent result. +func (n *NetNS) Remove() error { + return errNotImplementedOnUnix +} + +// Closed checks whether the network namespace has been closed. +func (n *NetNS) Closed() (bool, error) { + return false, errNotImplementedOnUnix +} + +// GetPath returns network namespace path for sandbox container +func (n *NetNS) GetPath() string { + return n.path +} + +// NOTE: Do function is not supported. diff --git a/pkg/os/mount_linux.go b/pkg/os/mount_linux.go new file mode 100644 index 000000000..15228e57d --- /dev/null +++ b/pkg/os/mount_linux.go @@ -0,0 +1,37 @@ +/* + 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 os + +import ( + "github.com/containerd/containerd/mount" + "golang.org/x/sys/unix" +) + +// Mount will call unix.Mount to mount the file. +func (RealOS) Mount(source string, target string, fstype string, flags uintptr, data string) error { + return unix.Mount(source, target, fstype, flags, data) +} + +// Unmount will call Unmount to unmount the file. +func (RealOS) Unmount(target string) error { + return mount.Unmount(target, unix.MNT_DETACH) +} + +// LookupMount gets mount info of a given path. +func (RealOS) LookupMount(path string) (mount.Info, error) { + return mount.Lookup(path) +} diff --git a/pkg/os/mount_other.go b/pkg/os/mount_other.go new file mode 100644 index 000000000..3a778d058 --- /dev/null +++ b/pkg/os/mount_other.go @@ -0,0 +1,26 @@ +// +build !windows,!linux + +/* + 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 os + +import "github.com/containerd/containerd/mount" + +// LookupMount gets mount info of a given path. +func (RealOS) LookupMount(path string) (mount.Info, error) { + return mount.Lookup(path) +} diff --git a/pkg/os/mount_unix.go b/pkg/os/mount_unix.go new file mode 100644 index 000000000..e81def359 --- /dev/null +++ b/pkg/os/mount_unix.go @@ -0,0 +1,33 @@ +// +build !windows,!linux + +/* + 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 os + +import ( + "github.com/containerd/containerd/mount" +) + +// Mount will call unix.Mount to mount the file. +func (RealOS) Mount(source string, target string, fstype string, flags uintptr, data string) error { + return mount.ErrNotImplementOnUnix +} + +// Unmount will call Unmount to unmount the file. +func (RealOS) Unmount(target string) error { + return mount.Unmount(target, 0) +} diff --git a/pkg/os/os_unix.go b/pkg/os/os_unix.go index 51f57871d..eaf0984dd 100644 --- a/pkg/os/os_unix.go +++ b/pkg/os/os_unix.go @@ -20,7 +20,6 @@ package os import ( "github.com/containerd/containerd/mount" - "golang.org/x/sys/unix" ) // UNIX collects unix system level operations that need to be @@ -30,30 +29,3 @@ type UNIX interface { Unmount(target string) error LookupMount(path string) (mount.Info, error) } - -// Mount will call unix.Mount to mount the file. -func (RealOS) Mount(source string, target string, fstype string, flags uintptr, data string) error { - return unix.Mount(source, target, fstype, flags, data) -} - -// Unmount will call Unmount to unmount the file. -func (RealOS) Unmount(target string) error { - return Unmount(target) -} - -// LookupMount gets mount info of a given path. -func (RealOS) LookupMount(path string) (mount.Info, error) { - return mount.Lookup(path) -} - -// Unmount unmounts the target. It does not return an error in case the target is not mounted. -// In case the target does not exist, the appropriate error is returned. -func Unmount(target string) error { - err := unix.Unmount(target, unix.MNT_DETACH) - if err == unix.EINVAL { - // ignore "not mounted" error - err = nil - } - - return err -} diff --git a/pkg/server/container_create_unix.go b/pkg/server/container_create_linux.go similarity index 99% rename from pkg/server/container_create_unix.go rename to pkg/server/container_create_linux.go index fc51bcf15..0b930394e 100644 --- a/pkg/server/container_create_unix.go +++ b/pkg/server/container_create_linux.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/container_create_unix_test.go b/pkg/server/container_create_linux_test.go similarity index 99% rename from pkg/server/container_create_unix_test.go rename to pkg/server/container_create_linux_test.go index 733c2e1f6..7187ec383 100644 --- a/pkg/server/container_create_unix_test.go +++ b/pkg/server/container_create_linux_test.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/container_create_other.go b/pkg/server/container_create_other.go new file mode 100644 index 000000000..82bbb87e0 --- /dev/null +++ b/pkg/server/container_create_other.go @@ -0,0 +1,44 @@ +// +build !windows,!linux + +/* + 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 server + +import ( + "github.com/containerd/containerd/oci" + imagespec "github.com/opencontainers/image-spec/specs-go/v1" + runtimespec "github.com/opencontainers/runtime-spec/specs-go" + runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" + + "github.com/containerd/cri/pkg/config" +) + +// containerMounts sets up necessary container system file mounts +// including /dev/shm, /etc/hosts and /etc/resolv.conf. +func (c *criService) containerMounts(sandboxID string, config *runtime.ContainerConfig) []*runtime.Mount { + return []*runtime.Mount{} +} + +func (c *criService) containerSpec(id string, sandboxID string, sandboxPid uint32, netNSPath string, containerName string, + config *runtime.ContainerConfig, sandboxConfig *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig, + extraMounts []*runtime.Mount, ociRuntime config.Runtime) (_ *runtimespec.Spec, retErr error) { + return c.runtimeSpec(id, ociRuntime.BaseRuntimeSpec) +} + +func (c *criService) containerSpecOpts(config *runtime.ContainerConfig, imageConfig *imagespec.ImageConfig) ([]oci.SpecOpts, error) { + return []oci.SpecOpts{}, nil +} diff --git a/pkg/server/container_create_other_test.go b/pkg/server/container_create_other_test.go new file mode 100644 index 000000000..891c46765 --- /dev/null +++ b/pkg/server/container_create_other_test.go @@ -0,0 +1,40 @@ +// +build !windows,!linux + +/* + 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 server + +import ( + "testing" + + imagespec "github.com/opencontainers/image-spec/specs-go/v1" + runtimespec "github.com/opencontainers/runtime-spec/specs-go" + runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" +) + +// checkMount is defined by all tests but not used here +var _ = checkMount + +func getCreateContainerTestData() (*runtime.ContainerConfig, *runtime.PodSandboxConfig, + *imagespec.ImageConfig, func(*testing.T, string, string, uint32, *runtimespec.Spec)) { + config := &runtime.ContainerConfig{} + sandboxConfig := &runtime.PodSandboxConfig{} + imageConfig := &imagespec.ImageConfig{} + specCheck := func(t *testing.T, id string, sandboxID string, sandboxPid uint32, spec *runtimespec.Spec) { + } + return config, sandboxConfig, imageConfig, specCheck +} diff --git a/pkg/server/container_stats_list_unix.go b/pkg/server/container_stats_list_linux.go similarity index 99% rename from pkg/server/container_stats_list_unix.go rename to pkg/server/container_stats_list_linux.go index ad398bc7a..d160b0928 100644 --- a/pkg/server/container_stats_list_unix.go +++ b/pkg/server/container_stats_list_linux.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/container_stats_list_unix_test.go b/pkg/server/container_stats_list_linux_test.go similarity index 98% rename from pkg/server/container_stats_list_unix_test.go rename to pkg/server/container_stats_list_linux_test.go index 39ef1584f..a35b5f21a 100644 --- a/pkg/server/container_stats_list_unix_test.go +++ b/pkg/server/container_stats_list_linux_test.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/container_stats_list_other.go b/pkg/server/container_stats_list_other.go new file mode 100644 index 000000000..b4bc28ff5 --- /dev/null +++ b/pkg/server/container_stats_list_other.go @@ -0,0 +1,36 @@ +// +build !windows,!linux + +/* + 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 server + +import ( + "github.com/containerd/containerd/api/types" + "github.com/containerd/containerd/errdefs" + "github.com/pkg/errors" + runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" + + containerstore "github.com/containerd/cri/pkg/store/container" +) + +func (c *criService) containerMetrics( + meta containerstore.Metadata, + stats *types.Metric, +) (*runtime.ContainerStats, error) { + var cs runtime.ContainerStats + return &cs, errors.Wrap(errdefs.ErrNotImplemented, "container metrics") +} diff --git a/pkg/server/container_update_resources_unix.go b/pkg/server/container_update_resources_linux.go similarity index 99% rename from pkg/server/container_update_resources_unix.go rename to pkg/server/container_update_resources_linux.go index 23e0d409b..ce3f8a812 100644 --- a/pkg/server/container_update_resources_unix.go +++ b/pkg/server/container_update_resources_linux.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/container_update_resources_unix_test.go b/pkg/server/container_update_resources_linux_test.go similarity index 99% rename from pkg/server/container_update_resources_unix_test.go rename to pkg/server/container_update_resources_linux_test.go index 6ec3dec12..ffbc3f88f 100644 --- a/pkg/server/container_update_resources_unix_test.go +++ b/pkg/server/container_update_resources_linux_test.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/container_update_resources_other.go b/pkg/server/container_update_resources_other.go new file mode 100644 index 000000000..57975fdc3 --- /dev/null +++ b/pkg/server/container_update_resources_other.go @@ -0,0 +1,44 @@ +// +build !windows,!linux + +/* + 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 server + +import ( + "github.com/pkg/errors" + "golang.org/x/net/context" + runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" + + containerstore "github.com/containerd/cri/pkg/store/container" +) + +// UpdateContainerResources updates ContainerConfig of the container. +func (c *criService) UpdateContainerResources(ctx context.Context, r *runtime.UpdateContainerResourcesRequest) (retRes *runtime.UpdateContainerResourcesResponse, retErr error) { + container, err := c.containerStore.Get(r.GetContainerId()) + if err != nil { + return nil, errors.Wrap(err, "failed to find container") + } + // Update resources in status update transaction, so that: + // 1) There won't be race condition with container start. + // 2) There won't be concurrent resource update to the same container. + if err := container.Status.Update(func(status containerstore.Status) (containerstore.Status, error) { + return status, nil + }); err != nil { + return nil, errors.Wrap(err, "failed to update resources") + } + return &runtime.UpdateContainerResourcesResponse{}, nil +} diff --git a/pkg/server/helpers_unix.go b/pkg/server/helpers_linux.go similarity index 99% rename from pkg/server/helpers_unix.go rename to pkg/server/helpers_linux.go index 0c3a6652d..6b8b048dc 100644 --- a/pkg/server/helpers_unix.go +++ b/pkg/server/helpers_linux.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/helpers_unix_test.go b/pkg/server/helpers_linux_test.go similarity index 99% rename from pkg/server/helpers_unix_test.go rename to pkg/server/helpers_linux_test.go index c060471ba..ca19c154a 100644 --- a/pkg/server/helpers_unix_test.go +++ b/pkg/server/helpers_linux_test.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/helpers_other.go b/pkg/server/helpers_other.go new file mode 100644 index 000000000..6a67375d7 --- /dev/null +++ b/pkg/server/helpers_other.go @@ -0,0 +1,43 @@ +// +build !windows,!linux + +/* + 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 server + +import ( + "context" + "os" + + "github.com/opencontainers/runtime-spec/specs-go" +) + +// openLogFile opens/creates a container log file. +func openLogFile(path string) (*os.File, error) { + return os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0640) +} + +// ensureRemoveAll wraps `os.RemoveAll` to check for specific errors that can +// often be remedied. +// Only use `ensureRemoveAll` if you really want to make every effort to remove +// a directory. +func ensureRemoveAll(ctx context.Context, dir string) error { + return os.RemoveAll(dir) +} + +func modifyProcessLabel(runtimeType string, spec *specs.Spec) error { + return nil +} diff --git a/pkg/server/sandbox_portforward_unix.go b/pkg/server/sandbox_portforward_linux.go similarity index 99% rename from pkg/server/sandbox_portforward_unix.go rename to pkg/server/sandbox_portforward_linux.go index 5691c2b61..32b062456 100644 --- a/pkg/server/sandbox_portforward_unix.go +++ b/pkg/server/sandbox_portforward_linux.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/sandbox_portforward_other.go b/pkg/server/sandbox_portforward_other.go new file mode 100644 index 000000000..1b88170ed --- /dev/null +++ b/pkg/server/sandbox_portforward_other.go @@ -0,0 +1,33 @@ +// +build !windows,!linux + +/* + 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 server + +import ( + "io" + + "github.com/containerd/containerd/errdefs" + "github.com/pkg/errors" + "golang.org/x/net/context" +) + +// portForward uses netns to enter the sandbox namespace, and forwards a stream inside the +// the namespace to a specific port. It keeps forwarding until it exits or client disconnect. +func (c *criService) portForward(ctx context.Context, id string, port int32, stream io.ReadWriteCloser) error { + return errors.Wrap(errdefs.ErrNotImplemented, "port forward") +} diff --git a/pkg/server/sandbox_run_unix.go b/pkg/server/sandbox_run_linux.go similarity index 99% rename from pkg/server/sandbox_run_unix.go rename to pkg/server/sandbox_run_linux.go index ad0b85254..f886d2ae2 100644 --- a/pkg/server/sandbox_run_unix.go +++ b/pkg/server/sandbox_run_linux.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/sandbox_run_unix_test.go b/pkg/server/sandbox_run_linux_test.go similarity index 99% rename from pkg/server/sandbox_run_unix_test.go rename to pkg/server/sandbox_run_linux_test.go index c74612657..166cd6f9e 100644 --- a/pkg/server/sandbox_run_unix_test.go +++ b/pkg/server/sandbox_run_linux_test.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/sandbox_run_other.go b/pkg/server/sandbox_run_other.go new file mode 100644 index 000000000..61d3904f7 --- /dev/null +++ b/pkg/server/sandbox_run_other.go @@ -0,0 +1,55 @@ +// +build !windows,!linux + +/* + 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 server + +import ( + "github.com/containerd/containerd" + "github.com/containerd/containerd/oci" + imagespec "github.com/opencontainers/image-spec/specs-go/v1" + runtimespec "github.com/opencontainers/runtime-spec/specs-go" + runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" +) + +func (c *criService) sandboxContainerSpec(id string, config *runtime.PodSandboxConfig, + imageConfig *imagespec.ImageConfig, nsPath string, runtimePodAnnotations []string) (_ *runtimespec.Spec, retErr error) { + return c.runtimeSpec(id, "") +} + +// sandboxContainerSpecOpts generates OCI spec options for +// the sandbox container. +func (c *criService) sandboxContainerSpecOpts(config *runtime.PodSandboxConfig, imageConfig *imagespec.ImageConfig) ([]oci.SpecOpts, error) { + return []oci.SpecOpts{}, nil +} + +// setupSandboxFiles sets up necessary sandbox files including /dev/shm, /etc/hosts, +// /etc/resolv.conf and /etc/hostname. +func (c *criService) setupSandboxFiles(id string, config *runtime.PodSandboxConfig) error { + return nil +} + +// cleanupSandboxFiles unmount some sandbox files, we rely on the removal of sandbox root directory to +// remove these files. Unmount should *NOT* return error if the mount point is already unmounted. +func (c *criService) cleanupSandboxFiles(id string, config *runtime.PodSandboxConfig) error { + return nil +} + +// taskOpts generates task options for a (sandbox) container. +func (c *criService) taskOpts(runtimeType string) []containerd.NewTaskOpts { + return []containerd.NewTaskOpts{} +} diff --git a/pkg/server/sandbox_run_other_test.go b/pkg/server/sandbox_run_other_test.go new file mode 100644 index 000000000..daf903908 --- /dev/null +++ b/pkg/server/sandbox_run_other_test.go @@ -0,0 +1,35 @@ +// +build !windows,!linux + +/* + 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 server + +import ( + "testing" + + imagespec "github.com/opencontainers/image-spec/specs-go/v1" + runtimespec "github.com/opencontainers/runtime-spec/specs-go" + runtime "k8s.io/cri-api/pkg/apis/runtime/v1alpha2" +) + +func getRunPodSandboxTestData() (*runtime.PodSandboxConfig, *imagespec.ImageConfig, func(*testing.T, string, *runtimespec.Spec)) { + config := &runtime.PodSandboxConfig{} + imageConfig := &imagespec.ImageConfig{} + specCheck := func(t *testing.T, id string, spec *runtimespec.Spec) { + } + return config, imageConfig, specCheck +} diff --git a/pkg/server/service_unix.go b/pkg/server/service_linux.go similarity index 99% rename from pkg/server/service_unix.go rename to pkg/server/service_linux.go index a1d9c9038..03b28f0ae 100644 --- a/pkg/server/service_unix.go +++ b/pkg/server/service_linux.go @@ -1,5 +1,3 @@ -// +build !windows - /* Copyright The containerd Authors. diff --git a/pkg/server/service_other.go b/pkg/server/service_other.go new file mode 100644 index 000000000..c17f7ccae --- /dev/null +++ b/pkg/server/service_other.go @@ -0,0 +1,33 @@ +// +build !windows,!linux + +/* + 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 server + +import ( + cni "github.com/containerd/go-cni" +) + +// initPlatform handles linux specific initialization for the CRI service. +func (c *criService) initPlatform() error { + return nil +} + +// cniLoadOptions returns cni load options for the linux. +func (c *criService) cniLoadOptions() []cni.CNIOpt { + return []cni.CNIOpt{} +}