summaryrefslogtreecommitdiffhomepage
path: root/pkg/shim/v1/utils
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/shim/v1/utils')
-rw-r--r--pkg/shim/v1/utils/BUILD5
-rw-r--r--pkg/shim/v1/utils/annotations.go25
-rw-r--r--pkg/shim/v1/utils/utils.go7
-rw-r--r--pkg/shim/v1/utils/volumes.go4
-rw-r--r--pkg/shim/v1/utils/volumes_test.go45
5 files changed, 54 insertions, 32 deletions
diff --git a/pkg/shim/v1/utils/BUILD b/pkg/shim/v1/utils/BUILD
index 9045781e1..54a0aabb7 100644
--- a/pkg/shim/v1/utils/BUILD
+++ b/pkg/shim/v1/utils/BUILD
@@ -5,6 +5,7 @@ package(licenses = ["notice"])
go_library(
name = "utils",
srcs = [
+ "annotations.go",
"utils.go",
"volumes.go",
],
@@ -13,8 +14,7 @@ go_library(
"//shim:__subpackages__",
],
deps = [
- "@com_github_containerd_cri//pkg/annotations:go_default_library",
- "@com_github_opencontainers_runtime-spec//specs-go:go_default_library",
+ "@com_github_opencontainers_runtime_spec//specs-go:go_default_library",
],
)
@@ -23,4 +23,5 @@ go_test(
size = "small",
srcs = ["volumes_test.go"],
library = ":utils",
+ deps = ["@com_github_opencontainers_runtime_spec//specs-go:go_default_library"],
)
diff --git a/pkg/shim/v1/utils/annotations.go b/pkg/shim/v1/utils/annotations.go
new file mode 100644
index 000000000..1e9d3f365
--- /dev/null
+++ b/pkg/shim/v1/utils/annotations.go
@@ -0,0 +1,25 @@
+// Copyright 2018 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
+
+// Annotations from the CRI annotations package.
+//
+// These are vendor due to import conflicts.
+const (
+ sandboxLogDirAnnotation = "io.kubernetes.cri.sandbox-log-directory"
+ containerTypeAnnotation = "io.kubernetes.cri.container-type"
+ containerTypeSandbox = "sandbox"
+ containerTypeContainer = "container"
+)
diff --git a/pkg/shim/v1/utils/utils.go b/pkg/shim/v1/utils/utils.go
index 7a400af1c..07e346654 100644
--- a/pkg/shim/v1/utils/utils.go
+++ b/pkg/shim/v1/utils/utils.go
@@ -20,7 +20,6 @@ import (
"os"
"path/filepath"
- "github.com/containerd/cri/pkg/annotations"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
@@ -43,13 +42,13 @@ func ReadSpec(bundle string) (*specs.Spec, error) {
// IsSandbox checks whether a container is a sandbox container.
func IsSandbox(spec *specs.Spec) bool {
- t, ok := spec.Annotations[annotations.ContainerType]
- return !ok || t == annotations.ContainerTypeSandbox
+ t, ok := spec.Annotations[containerTypeAnnotation]
+ return !ok || t == containerTypeSandbox
}
// UserLogPath gets user log path from OCI annotation.
func UserLogPath(spec *specs.Spec) string {
- sandboxLogDir := spec.Annotations[annotations.SandboxLogDir]
+ sandboxLogDir := spec.Annotations[sandboxLogDirAnnotation]
if sandboxLogDir == "" {
return ""
}
diff --git a/pkg/shim/v1/utils/volumes.go b/pkg/shim/v1/utils/volumes.go
index e4e9bf9b1..52a428179 100644
--- a/pkg/shim/v1/utils/volumes.go
+++ b/pkg/shim/v1/utils/volumes.go
@@ -21,7 +21,6 @@ import (
"path/filepath"
"strings"
- "github.com/containerd/cri/pkg/annotations"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
@@ -44,7 +43,7 @@ func volumeFieldName(k string) string {
// podUID gets pod UID from the pod log path.
func podUID(s *specs.Spec) (string, error) {
- sandboxLogDir := s.Annotations[annotations.SandboxLogDir]
+ sandboxLogDir := s.Annotations[sandboxLogDirAnnotation]
if sandboxLogDir == "" {
return "", fmt.Errorf("no sandbox log path annotation")
}
@@ -101,7 +100,6 @@ func UpdateVolumeAnnotations(bundle string, s *specs.Spec) error {
if err != nil {
// Skip if we can't get pod UID, because this doesn't work
// for containerd 1.1.
- fmt.Errorf("Can't get pod uid: %w", err)
return nil
}
}
diff --git a/pkg/shim/v1/utils/volumes_test.go b/pkg/shim/v1/utils/volumes_test.go
index 4b2639545..3e02c6151 100644
--- a/pkg/shim/v1/utils/volumes_test.go
+++ b/pkg/shim/v1/utils/volumes_test.go
@@ -23,7 +23,6 @@ import (
"reflect"
"testing"
- "github.com/containerd/cri/pkg/annotations"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
@@ -58,8 +57,8 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
desc: "volume annotations for sandbox",
spec: &specs.Spec{
Annotations: map[string]string{
- annotations.SandboxLogDir: testLogDirPath,
- annotations.ContainerType: annotations.ContainerTypeSandbox,
+ sandboxLogDirAnnotation: testLogDirPath,
+ containerTypeAnnotation: containerTypeSandbox,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
@@ -67,8 +66,8 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
expected: &specs.Spec{
Annotations: map[string]string{
- annotations.SandboxLogDir: testLogDirPath,
- annotations.ContainerType: annotations.ContainerTypeSandbox,
+ sandboxLogDirAnnotation: testLogDirPath,
+ containerTypeAnnotation: containerTypeSandbox,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
@@ -81,8 +80,8 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
desc: "volume annotations for sandbox with legacy log path",
spec: &specs.Spec{
Annotations: map[string]string{
- annotations.SandboxLogDir: testLegacyLogDirPath,
- annotations.ContainerType: annotations.ContainerTypeSandbox,
+ sandboxLogDirAnnotation: testLegacyLogDirPath,
+ containerTypeAnnotation: containerTypeSandbox,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
@@ -90,8 +89,8 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
expected: &specs.Spec{
Annotations: map[string]string{
- annotations.SandboxLogDir: testLegacyLogDirPath,
- annotations.ContainerType: annotations.ContainerTypeSandbox,
+ sandboxLogDirAnnotation: testLegacyLogDirPath,
+ containerTypeAnnotation: containerTypeSandbox,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
@@ -118,7 +117,7 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
},
Annotations: map[string]string{
- annotations.ContainerType: annotations.ContainerTypeContainer,
+ containerTypeAnnotation: containerTypeContainer,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
@@ -140,7 +139,7 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
},
Annotations: map[string]string{
- annotations.ContainerType: annotations.ContainerTypeContainer,
+ containerTypeAnnotation: containerTypeContainer,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
@@ -160,7 +159,7 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
},
Annotations: map[string]string{
- annotations.ContainerType: annotations.ContainerTypeContainer,
+ containerTypeAnnotation: containerTypeContainer,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "container",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "bind",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
@@ -176,7 +175,7 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
},
Annotations: map[string]string{
- annotations.ContainerType: annotations.ContainerTypeContainer,
+ containerTypeAnnotation: containerTypeContainer,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "container",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "bind",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
@@ -188,7 +187,7 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
desc: "should not return error without pod log directory",
spec: &specs.Spec{
Annotations: map[string]string{
- annotations.ContainerType: annotations.ContainerTypeSandbox,
+ containerTypeAnnotation: containerTypeSandbox,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
@@ -196,7 +195,7 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
expected: &specs.Spec{
Annotations: map[string]string{
- annotations.ContainerType: annotations.ContainerTypeSandbox,
+ containerTypeAnnotation: containerTypeSandbox,
"dev.gvisor.spec.mount." + testVolumeName + ".share": "pod",
"dev.gvisor.spec.mount." + testVolumeName + ".type": "tmpfs",
"dev.gvisor.spec.mount." + testVolumeName + ".options": "ro",
@@ -207,8 +206,8 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
desc: "should return error if volume path does not exist",
spec: &specs.Spec{
Annotations: map[string]string{
- annotations.SandboxLogDir: testLogDirPath,
- annotations.ContainerType: annotations.ContainerTypeSandbox,
+ sandboxLogDirAnnotation: testLogDirPath,
+ containerTypeAnnotation: containerTypeSandbox,
"dev.gvisor.spec.mount.notexist.share": "pod",
"dev.gvisor.spec.mount.notexist.type": "tmpfs",
"dev.gvisor.spec.mount.notexist.options": "ro",
@@ -220,14 +219,14 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
desc: "no volume annotations for sandbox",
spec: &specs.Spec{
Annotations: map[string]string{
- annotations.SandboxLogDir: testLogDirPath,
- annotations.ContainerType: annotations.ContainerTypeSandbox,
+ sandboxLogDirAnnotation: testLogDirPath,
+ containerTypeAnnotation: containerTypeSandbox,
},
},
expected: &specs.Spec{
Annotations: map[string]string{
- annotations.SandboxLogDir: testLogDirPath,
- annotations.ContainerType: annotations.ContainerTypeSandbox,
+ sandboxLogDirAnnotation: testLogDirPath,
+ containerTypeAnnotation: containerTypeSandbox,
},
},
},
@@ -249,7 +248,7 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
},
Annotations: map[string]string{
- annotations.ContainerType: annotations.ContainerTypeContainer,
+ containerTypeAnnotation: containerTypeContainer,
},
},
expected: &specs.Spec{
@@ -268,7 +267,7 @@ func TestUpdateVolumeAnnotations(t *testing.T) {
},
},
Annotations: map[string]string{
- annotations.ContainerType: annotations.ContainerTypeContainer,
+ containerTypeAnnotation: containerTypeContainer,
},
},
},