diff options
Diffstat (limited to 'pkg/shim')
-rw-r--r-- | pkg/shim/BUILD | 60 | ||||
-rw-r--r-- | pkg/shim/proc/BUILD | 38 | ||||
-rw-r--r-- | pkg/shim/proc/proc_state_autogen.go | 3 | ||||
-rw-r--r-- | pkg/shim/runsc/BUILD | 18 | ||||
-rw-r--r-- | pkg/shim/runsc/runsc_state_autogen.go | 3 | ||||
-rw-r--r-- | pkg/shim/runtimeoptions/BUILD | 32 | ||||
-rw-r--r-- | pkg/shim/runtimeoptions/runtimeoptions.proto | 25 | ||||
-rw-r--r-- | pkg/shim/runtimeoptions/runtimeoptions_state_autogen.go | 3 | ||||
-rw-r--r-- | pkg/shim/runtimeoptions/runtimeoptions_test.go | 57 | ||||
-rw-r--r-- | pkg/shim/service_test.go | 121 | ||||
-rw-r--r-- | pkg/shim/shim_linux_state_autogen.go | 5 | ||||
-rw-r--r-- | pkg/shim/shim_state_autogen.go | 5 | ||||
-rw-r--r-- | pkg/shim/utils/BUILD | 37 | ||||
-rw-r--r-- | pkg/shim/utils/errors_test.go | 50 | ||||
-rw-r--r-- | pkg/shim/utils/utils_state_autogen.go | 3 | ||||
-rw-r--r-- | pkg/shim/utils/volumes_test.go | 330 |
16 files changed, 22 insertions, 768 deletions
diff --git a/pkg/shim/BUILD b/pkg/shim/BUILD deleted file mode 100644 index 367765209..000000000 --- a/pkg/shim/BUILD +++ /dev/null @@ -1,60 +0,0 @@ -load("//tools:defs.bzl", "go_library", "go_test") - -package(licenses = ["notice"]) - -go_library( - name = "shim", - srcs = [ - "api.go", - "debug.go", - "epoll.go", - "options.go", - "service.go", - "service_linux.go", - "state.go", - ], - visibility = ["//shim:__subpackages__"], - deps = [ - "//pkg/cleanup", - "//pkg/shim/proc", - "//pkg/shim/runsc", - "//pkg/shim/runtimeoptions", - "//pkg/shim/utils", - "//runsc/specutils", - "@com_github_burntsushi_toml//:go_default_library", - "@com_github_containerd_cgroups//:go_default_library", - "@com_github_containerd_cgroups//stats/v1:go_default_library", - "@com_github_containerd_console//:go_default_library", - "@com_github_containerd_containerd//api/events:go_default_library", - "@com_github_containerd_containerd//api/types/task:go_default_library", - "@com_github_containerd_containerd//errdefs:go_default_library", - "@com_github_containerd_containerd//events:go_default_library", - "@com_github_containerd_containerd//log:go_default_library", - "@com_github_containerd_containerd//mount:go_default_library", - "@com_github_containerd_containerd//namespaces:go_default_library", - "@com_github_containerd_containerd//pkg/process:go_default_library", - "@com_github_containerd_containerd//pkg/stdio:go_default_library", - "@com_github_containerd_containerd//runtime:go_default_library", - "@com_github_containerd_containerd//runtime/linux/runctypes:go_default_library", - "@com_github_containerd_containerd//runtime/v2/shim:go_default_library", - "@com_github_containerd_containerd//runtime/v2/task:go_default_library", - "@com_github_containerd_containerd//sys/reaper:go_default_library", - "@com_github_containerd_fifo//:go_default_library", - "@com_github_containerd_typeurl//:go_default_library", - "@com_github_gogo_protobuf//types:go_default_library", - "@com_github_opencontainers_runtime_spec//specs-go:go_default_library", - "@com_github_sirupsen_logrus//:go_default_library", - "@org_golang_x_sys//unix:go_default_library", - ], -) - -go_test( - name = "shim_test", - size = "small", - srcs = ["service_test.go"], - library = ":shim", - deps = [ - "//pkg/shim/utils", - "@com_github_opencontainers_runtime_spec//specs-go:go_default_library", - ], -) diff --git a/pkg/shim/proc/BUILD b/pkg/shim/proc/BUILD deleted file mode 100644 index c8527a6d9..000000000 --- a/pkg/shim/proc/BUILD +++ /dev/null @@ -1,38 +0,0 @@ -load("//tools:defs.bzl", "go_library") - -package(licenses = ["notice"]) - -go_library( - name = "proc", - srcs = [ - "deleted_state.go", - "exec.go", - "exec_state.go", - "init.go", - "init_state.go", - "io.go", - "proc.go", - "types.go", - "utils.go", - ], - visibility = [ - "//pkg/shim:__subpackages__", - "//shim:__subpackages__", - ], - deps = [ - "//pkg/cleanup", - "//pkg/shim/runsc", - "//pkg/shim/utils", - "@com_github_containerd_console//:go_default_library", - "@com_github_containerd_containerd//errdefs:go_default_library", - "@com_github_containerd_containerd//log:go_default_library", - "@com_github_containerd_containerd//mount:go_default_library", - "@com_github_containerd_containerd//pkg/process:go_default_library", - "@com_github_containerd_containerd//pkg/stdio:go_default_library", - "@com_github_containerd_fifo//:go_default_library", - "@com_github_containerd_go_runc//:go_default_library", - "@com_github_gogo_protobuf//types:go_default_library", - "@com_github_opencontainers_runtime_spec//specs-go:go_default_library", - "@org_golang_x_sys//unix:go_default_library", - ], -) diff --git a/pkg/shim/proc/proc_state_autogen.go b/pkg/shim/proc/proc_state_autogen.go new file mode 100644 index 000000000..210252d9d --- /dev/null +++ b/pkg/shim/proc/proc_state_autogen.go @@ -0,0 +1,3 @@ +// automatically generated by stateify. + +package proc diff --git a/pkg/shim/runsc/BUILD b/pkg/shim/runsc/BUILD deleted file mode 100644 index f2fc813e6..000000000 --- a/pkg/shim/runsc/BUILD +++ /dev/null @@ -1,18 +0,0 @@ -load("//tools:defs.bzl", "go_library") - -package(licenses = ["notice"]) - -go_library( - name = "runsc", - srcs = [ - "runsc.go", - "utils.go", - ], - visibility = ["//:sandbox"], - deps = [ - "@com_github_containerd_containerd//log:go_default_library", - "@com_github_containerd_go_runc//:go_default_library", - "@com_github_opencontainers_runtime_spec//specs-go:go_default_library", - "@org_golang_x_sys//unix:go_default_library", - ], -) diff --git a/pkg/shim/runsc/runsc_state_autogen.go b/pkg/shim/runsc/runsc_state_autogen.go new file mode 100644 index 000000000..ee470594f --- /dev/null +++ b/pkg/shim/runsc/runsc_state_autogen.go @@ -0,0 +1,3 @@ +// automatically generated by stateify. + +package runsc diff --git a/pkg/shim/runtimeoptions/BUILD b/pkg/shim/runtimeoptions/BUILD deleted file mode 100644 index 029be7c09..000000000 --- a/pkg/shim/runtimeoptions/BUILD +++ /dev/null @@ -1,32 +0,0 @@ -load("//tools:defs.bzl", "go_library", "go_test", "proto_library") - -package(licenses = ["notice"]) - -proto_library( - name = "api", - srcs = [ - "runtimeoptions.proto", - ], -) - -go_library( - name = "runtimeoptions", - srcs = [ - "runtimeoptions.go", - "runtimeoptions_cri.go", - ], - visibility = ["//pkg/shim:__pkg__"], - deps = ["@com_github_gogo_protobuf//proto:go_default_library"], -) - -go_test( - name = "runtimeoptions_test", - size = "small", - srcs = ["runtimeoptions_test.go"], - library = ":runtimeoptions", - deps = [ - "@com_github_containerd_containerd//runtime/v1/shim/v1:go_default_library", - "@com_github_containerd_typeurl//:go_default_library", - "@com_github_gogo_protobuf//proto:go_default_library", - ], -) diff --git a/pkg/shim/runtimeoptions/runtimeoptions.proto b/pkg/shim/runtimeoptions/runtimeoptions.proto deleted file mode 100644 index 057032e34..000000000 --- a/pkg/shim/runtimeoptions/runtimeoptions.proto +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2020 The gVisor 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 -// -// https://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. - -syntax = "proto3"; - -package cri.runtimeoptions.v1; - -// This is a version of the runtimeoptions CRI API that is vendored. -// -// Importing the full CRI package is a nightmare. -message Options { - string type_url = 1; - string config_path = 2; -} diff --git a/pkg/shim/runtimeoptions/runtimeoptions_state_autogen.go b/pkg/shim/runtimeoptions/runtimeoptions_state_autogen.go new file mode 100644 index 000000000..f5c883045 --- /dev/null +++ b/pkg/shim/runtimeoptions/runtimeoptions_state_autogen.go @@ -0,0 +1,3 @@ +// automatically generated by stateify. + +package runtimeoptions diff --git a/pkg/shim/runtimeoptions/runtimeoptions_test.go b/pkg/shim/runtimeoptions/runtimeoptions_test.go deleted file mode 100644 index c59a2400e..000000000 --- a/pkg/shim/runtimeoptions/runtimeoptions_test.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2020 The gVisor 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 -// -// https://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 runtimeoptions - -import ( - "bytes" - "testing" - - shim "github.com/containerd/containerd/runtime/v1/shim/v1" - "github.com/containerd/typeurl" - "github.com/gogo/protobuf/proto" -) - -func TestCreateTaskRequest(t *testing.T) { - // Serialize the top-level message. - const encodedText = `options: < - type_url: "cri.runtimeoptions.v1.Options" - value: "\n\010type_url\022\013config_path" ->` - got := &shim.CreateTaskRequest{} // Should have raw options. - if err := proto.UnmarshalText(encodedText, got); err != nil { - t.Fatalf("unable to unmarshal text: %v", err) - } - var textBuffer bytes.Buffer - if err := proto.MarshalText(&textBuffer, got); err != nil { - t.Errorf("unable to marshal text: %v", err) - } - t.Logf("got: %s", string(textBuffer.Bytes())) - - // Check the options. - wantOptions := &Options{} - wantOptions.TypeUrl = "type_url" - wantOptions.ConfigPath = "config_path" - gotMessage, err := typeurl.UnmarshalAny(got.Options) - if err != nil { - t.Fatalf("unable to unmarshal any: %v", err) - } - gotOptions, ok := gotMessage.(*Options) - if !ok { - t.Fatalf("got %v, want %v", gotMessage, wantOptions) - } - if !proto.Equal(gotOptions, wantOptions) { - t.Fatalf("got %v, want %v", gotOptions, wantOptions) - } -} diff --git a/pkg/shim/service_test.go b/pkg/shim/service_test.go deleted file mode 100644 index 2d9f07e02..000000000 --- a/pkg/shim/service_test.go +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright 2021 The gVisor 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 -// -// https://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 shim - -import ( - "testing" - - specs "github.com/opencontainers/runtime-spec/specs-go" - "gvisor.dev/gvisor/pkg/shim/utils" -) - -func TestCgroupPath(t *testing.T) { - for _, tc := range []struct { - name string - path string - want string - }{ - { - name: "simple", - path: "foo/pod123/container", - want: "foo/pod123", - }, - { - name: "absolute", - path: "/foo/pod123/container", - want: "/foo/pod123", - }, - { - name: "no-container", - path: "foo/pod123", - want: "foo/pod123", - }, - { - name: "no-container-absolute", - path: "/foo/pod123", - want: "/foo/pod123", - }, - { - name: "double-pod", - path: "/foo/podium/pod123/container", - want: "/foo/podium/pod123", - }, - { - name: "start-pod", - path: "pod123/container", - want: "pod123", - }, - { - name: "start-pod-absolute", - path: "/pod123/container", - want: "/pod123", - }, - { - name: "slashes", - path: "///foo/////pod123//////container", - want: "/foo/pod123", - }, - { - name: "no-pod", - path: "/foo/nopod123/container", - want: "/foo/nopod123/container", - }, - } { - t.Run(tc.name, func(t *testing.T) { - spec := specs.Spec{ - Linux: &specs.Linux{ - CgroupsPath: tc.path, - }, - } - updated := updateCgroup(&spec) - if spec.Linux.CgroupsPath != tc.want { - t.Errorf("updateCgroup(%q), want: %q, got: %q", tc.path, tc.want, spec.Linux.CgroupsPath) - } - if shouldUpdate := tc.path != tc.want; shouldUpdate != updated { - t.Errorf("updateCgroup(%q)=%v, want: %v", tc.path, updated, shouldUpdate) - } - }) - } -} - -// Test cases that cgroup path should not be updated. -func TestCgroupNoUpdate(t *testing.T) { - for _, tc := range []struct { - name string - spec *specs.Spec - }{ - { - name: "empty", - spec: &specs.Spec{}, - }, - { - name: "subcontainer", - spec: &specs.Spec{ - Linux: &specs.Linux{ - CgroupsPath: "foo/pod123/container", - }, - Annotations: map[string]string{ - utils.ContainerTypeAnnotation: utils.ContainerTypeContainer, - }, - }, - }, - } { - t.Run(tc.name, func(t *testing.T) { - if updated := updateCgroup(tc.spec); updated { - t.Errorf("updateCgroup(%+v), got: %v, want: false", tc.spec.Linux, updated) - } - }) - } -} diff --git a/pkg/shim/shim_linux_state_autogen.go b/pkg/shim/shim_linux_state_autogen.go new file mode 100644 index 000000000..191a9e496 --- /dev/null +++ b/pkg/shim/shim_linux_state_autogen.go @@ -0,0 +1,5 @@ +// automatically generated by stateify. + +// +build linux + +package shim diff --git a/pkg/shim/shim_state_autogen.go b/pkg/shim/shim_state_autogen.go new file mode 100644 index 000000000..191a9e496 --- /dev/null +++ b/pkg/shim/shim_state_autogen.go @@ -0,0 +1,5 @@ +// automatically generated by stateify. + +// +build linux + +package shim diff --git a/pkg/shim/utils/BUILD b/pkg/shim/utils/BUILD deleted file mode 100644 index 2eb82f63c..000000000 --- a/pkg/shim/utils/BUILD +++ /dev/null @@ -1,37 +0,0 @@ -load("//tools:defs.bzl", "go_library", "go_test") - -package(licenses = ["notice"]) - -go_library( - name = "utils", - srcs = [ - "annotations.go", - "errors.go", - "utils.go", - "volumes.go", - ], - visibility = [ - "//pkg/shim:__subpackages__", - "//shim:__subpackages__", - ], - deps = [ - "@com_github_containerd_containerd//errdefs:go_default_library", - "@com_github_opencontainers_runtime_spec//specs-go:go_default_library", - "@org_golang_google_grpc//codes:go_default_library", - "@org_golang_google_grpc//status:go_default_library", - ], -) - -go_test( - name = "utils_test", - size = "small", - srcs = [ - "errors_test.go", - "volumes_test.go", - ], - library = ":utils", - deps = [ - "@com_github_containerd_containerd//errdefs:go_default_library", - "@com_github_opencontainers_runtime_spec//specs-go:go_default_library", - ], -) diff --git a/pkg/shim/utils/errors_test.go b/pkg/shim/utils/errors_test.go deleted file mode 100644 index 0a8fe34c8..000000000 --- a/pkg/shim/utils/errors_test.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2021 The gVisor 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 -// -// https://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 utils - -import ( - "fmt" - "testing" - - "github.com/containerd/containerd/errdefs" -) - -func TestGRPCRoundTripsErrors(t *testing.T) { - for _, tc := range []struct { - name string - err error - test func(err error) bool - }{ - { - name: "passthrough", - err: errdefs.ErrNotFound, - test: errdefs.IsNotFound, - }, - { - name: "wrapped", - err: fmt.Errorf("oh no: %w", errdefs.ErrNotFound), - test: errdefs.IsNotFound, - }, - } { - t.Run(tc.name, func(t *testing.T) { - if err := errdefs.FromGRPC(ErrToGRPC(tc.err)); !tc.test(err) { - t.Errorf("errToGRPC got %+v", err) - } - if err := errdefs.FromGRPC(ErrToGRPCf(tc.err, "testing %s", "123")); !tc.test(err) { - t.Errorf("errToGRPCf got %+v", err) - } - }) - } -} diff --git a/pkg/shim/utils/utils_state_autogen.go b/pkg/shim/utils/utils_state_autogen.go new file mode 100644 index 000000000..dba8bfb1a --- /dev/null +++ b/pkg/shim/utils/utils_state_autogen.go @@ -0,0 +1,3 @@ +// automatically generated by stateify. + +package utils diff --git a/pkg/shim/utils/volumes_test.go b/pkg/shim/utils/volumes_test.go deleted file mode 100644 index 5db43cdf1..000000000 --- a/pkg/shim/utils/volumes_test.go +++ /dev/null @@ -1,330 +0,0 @@ -// Copyright 2019 The gVisor 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 -// -// https://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 utils - -import ( - "fmt" - "io/ioutil" - "os" - "reflect" - "testing" - - specs "github.com/opencontainers/runtime-spec/specs-go" -) - -func TestUpdateVolumeAnnotations(t *testing.T) { - dir, err := ioutil.TempDir("", "test-update-volume-annotations") - if err != nil { - t.Fatalf("create tempdir: %v", err) - } - defer os.RemoveAll(dir) - kubeletPodsDir = dir - - const ( - testPodUID = "testuid" - testVolumeName = "testvolume" - testLogDirPath = "/var/log/pods/testns_testname_" + testPodUID - testLegacyLogDirPath = "/var/log/pods/" + testPodUID - ) - testVolumePath := fmt.Sprintf("%s/%s/volumes/kubernetes.io~empty-dir/%s", dir, testPodUID, testVolumeName) - - if err := os.MkdirAll(testVolumePath, 0755); err != nil { - t.Fatalf("Create test volume: %v", err) - } - - for _, test := range []struct { - name string - spec *specs.Spec - expected *specs.Spec - expectErr bool - expectUpdate bool - }{ - { - name: "volume annotations for sandbox", - spec: &specs.Spec{ - Annotations: map[string]string{ - sandboxLogDirAnnotation: testLogDirPath, - ContainerTypeAnnotation: containerTypeSandbox, - volumeKeyPrefix + testVolumeName + ".share": "pod", - volumeKeyPrefix + testVolumeName + ".type": "tmpfs", - volumeKeyPrefix + testVolumeName + ".options": "ro", - }, - }, - expected: &specs.Spec{ - Annotations: map[string]string{ - sandboxLogDirAnnotation: testLogDirPath, - ContainerTypeAnnotation: containerTypeSandbox, - volumeKeyPrefix + testVolumeName + ".share": "pod", - volumeKeyPrefix + testVolumeName + ".type": "tmpfs", - volumeKeyPrefix + testVolumeName + ".options": "ro", - volumeKeyPrefix + testVolumeName + ".source": testVolumePath, - }, - }, - expectUpdate: true, - }, - { - name: "volume annotations for sandbox with legacy log path", - spec: &specs.Spec{ - Annotations: map[string]string{ - sandboxLogDirAnnotation: testLegacyLogDirPath, - ContainerTypeAnnotation: containerTypeSandbox, - volumeKeyPrefix + testVolumeName + ".share": "pod", - volumeKeyPrefix + testVolumeName + ".type": "tmpfs", - volumeKeyPrefix + testVolumeName + ".options": "ro", - }, - }, - expected: &specs.Spec{ - Annotations: map[string]string{ - sandboxLogDirAnnotation: testLegacyLogDirPath, - ContainerTypeAnnotation: containerTypeSandbox, - volumeKeyPrefix + testVolumeName + ".share": "pod", - volumeKeyPrefix + testVolumeName + ".type": "tmpfs", - volumeKeyPrefix + testVolumeName + ".options": "ro", - volumeKeyPrefix + testVolumeName + ".source": testVolumePath, - }, - }, - expectUpdate: true, - }, - { - name: "tmpfs: volume annotations for container", - spec: &specs.Spec{ - Mounts: []specs.Mount{ - { - Destination: "/test", - Type: "bind", - Source: testVolumePath, - Options: []string{"ro"}, - }, - { - Destination: "/random", - Type: "bind", - Source: "/random", - Options: []string{"ro"}, - }, - }, - Annotations: map[string]string{ - ContainerTypeAnnotation: ContainerTypeContainer, - volumeKeyPrefix + testVolumeName + ".share": "pod", - volumeKeyPrefix + testVolumeName + ".type": "tmpfs", - volumeKeyPrefix + testVolumeName + ".options": "ro", - }, - }, - expected: &specs.Spec{ - Mounts: []specs.Mount{ - { - Destination: "/test", - Type: "tmpfs", - Source: testVolumePath, - Options: []string{"ro"}, - }, - { - Destination: "/random", - Type: "bind", - Source: "/random", - Options: []string{"ro"}, - }, - }, - Annotations: map[string]string{ - ContainerTypeAnnotation: ContainerTypeContainer, - volumeKeyPrefix + testVolumeName + ".share": "pod", - volumeKeyPrefix + testVolumeName + ".type": "tmpfs", - volumeKeyPrefix + testVolumeName + ".options": "ro", - }, - }, - expectUpdate: true, - }, - { - name: "bind: volume annotations for container", - spec: &specs.Spec{ - Mounts: []specs.Mount{ - { - Destination: "/test", - Type: "bind", - Source: testVolumePath, - Options: []string{"ro"}, - }, - }, - Annotations: map[string]string{ - ContainerTypeAnnotation: ContainerTypeContainer, - volumeKeyPrefix + testVolumeName + ".share": "container", - volumeKeyPrefix + testVolumeName + ".type": "bind", - volumeKeyPrefix + testVolumeName + ".options": "ro", - }, - }, - expected: &specs.Spec{ - Mounts: []specs.Mount{ - { - Destination: "/test", - Type: "bind", - Source: testVolumePath, - Options: []string{"ro"}, - }, - }, - Annotations: map[string]string{ - ContainerTypeAnnotation: ContainerTypeContainer, - volumeKeyPrefix + testVolumeName + ".share": "container", - volumeKeyPrefix + testVolumeName + ".type": "bind", - volumeKeyPrefix + testVolumeName + ".options": "ro", - }, - }, - expectUpdate: true, - }, - { - name: "should not return error without pod log directory", - spec: &specs.Spec{ - Annotations: map[string]string{ - ContainerTypeAnnotation: containerTypeSandbox, - volumeKeyPrefix + testVolumeName + ".share": "pod", - volumeKeyPrefix + testVolumeName + ".type": "tmpfs", - volumeKeyPrefix + testVolumeName + ".options": "ro", - }, - }, - expected: &specs.Spec{ - Annotations: map[string]string{ - ContainerTypeAnnotation: containerTypeSandbox, - volumeKeyPrefix + testVolumeName + ".share": "pod", - volumeKeyPrefix + testVolumeName + ".type": "tmpfs", - volumeKeyPrefix + testVolumeName + ".options": "ro", - }, - }, - }, - { - name: "should return error if volume path does not exist", - spec: &specs.Spec{ - Annotations: map[string]string{ - sandboxLogDirAnnotation: testLogDirPath, - ContainerTypeAnnotation: containerTypeSandbox, - volumeKeyPrefix + "notexist.share": "pod", - volumeKeyPrefix + "notexist.type": "tmpfs", - volumeKeyPrefix + "notexist.options": "ro", - }, - }, - expectErr: true, - }, - { - name: "no volume annotations for sandbox", - spec: &specs.Spec{ - Annotations: map[string]string{ - sandboxLogDirAnnotation: testLogDirPath, - ContainerTypeAnnotation: containerTypeSandbox, - }, - }, - expected: &specs.Spec{ - Annotations: map[string]string{ - sandboxLogDirAnnotation: testLogDirPath, - ContainerTypeAnnotation: containerTypeSandbox, - }, - }, - }, - { - name: "no volume annotations for container", - spec: &specs.Spec{ - Mounts: []specs.Mount{ - { - Destination: "/test", - Type: "bind", - Source: "/test", - Options: []string{"ro"}, - }, - { - Destination: "/random", - Type: "bind", - Source: "/random", - Options: []string{"ro"}, - }, - }, - Annotations: map[string]string{ - ContainerTypeAnnotation: ContainerTypeContainer, - }, - }, - expected: &specs.Spec{ - Mounts: []specs.Mount{ - { - Destination: "/test", - Type: "bind", - Source: "/test", - Options: []string{"ro"}, - }, - { - Destination: "/random", - Type: "bind", - Source: "/random", - Options: []string{"ro"}, - }, - }, - Annotations: map[string]string{ - ContainerTypeAnnotation: ContainerTypeContainer, - }, - }, - }, - { - name: "bind options removed", - spec: &specs.Spec{ - Annotations: map[string]string{ - ContainerTypeAnnotation: ContainerTypeContainer, - volumeKeyPrefix + testVolumeName + ".share": "pod", - volumeKeyPrefix + testVolumeName + ".type": "tmpfs", - volumeKeyPrefix + testVolumeName + ".options": "ro", - volumeKeyPrefix + testVolumeName + ".source": testVolumePath, - }, - Mounts: []specs.Mount{ - { - Destination: "/dst", - Type: "bind", - Source: testVolumePath, - Options: []string{"ro", "bind", "rbind"}, - }, - }, - }, - expected: &specs.Spec{ - Annotations: map[string]string{ - ContainerTypeAnnotation: ContainerTypeContainer, - volumeKeyPrefix + testVolumeName + ".share": "pod", - volumeKeyPrefix + testVolumeName + ".type": "tmpfs", - volumeKeyPrefix + testVolumeName + ".options": "ro", - volumeKeyPrefix + testVolumeName + ".source": testVolumePath, - }, - Mounts: []specs.Mount{ - { - Destination: "/dst", - Type: "tmpfs", - Source: testVolumePath, - Options: []string{"ro"}, - }, - }, - }, - expectUpdate: true, - }, - } { - t.Run(test.name, func(t *testing.T) { - updated, err := UpdateVolumeAnnotations(test.spec) - if test.expectErr { - if err == nil { - t.Fatal("Expected error, but got nil") - } - return - } - if err != nil { - t.Fatalf("Unexpected error: %v", err) - } - if !reflect.DeepEqual(test.expected, test.spec) { - t.Fatalf("Expected %+v, got %+v", test.expected, test.spec) - } - if test.expectUpdate != updated { - t.Errorf("Expected %v, got %v", test.expected, updated) - } - }) - } -} |