Skip to content

Commit 1899001

Browse files
[no-relnote] add e2e for containerd
Signed-off-by: Carlos Eduardo Arango Gutierrez <eduardoa@nvidia.com>
1 parent e129f35 commit 1899001

File tree

9 files changed

+471
-10
lines changed

9 files changed

+471
-10
lines changed

cmd/nvidia-ctk-installer/toolkit/installer/executables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ package installer
2020
import (
2121
"bytes"
2222
"fmt"
23-
"html/template"
2423
"io"
2524
"path/filepath"
2625
"strings"
26+
"text/template"
2727

2828
log "github.com/sirupsen/logrus"
2929

pkg/config/engine/containerd/config_drop_in.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@ func (c *topLevelConfig) removeVersion() {
153153

154154
func (c *topLevelConfig) ensureImports(dropInFilename string) {
155155
config := c.config.Tree
156-
var currentImports []string
157-
if ci, ok := c.config.Get("imports").([]string); ok {
158-
currentImports = ci
159-
}
156+
currentImports, _ := c.config.getStringArrayValue([]string{"imports"})
160157

161158
requiredImport := c.importPattern(dropInFilename)
162159
for _, currentImport := range currentImports {

tests/e2e/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ GINKGO_BIN := $(CURDIR)/bin/ginkgo
2525
# - nvidia-container-cli
2626
# - docker
2727
# - nvidia-cdi-refresh
28+
# - containerd
2829
GINKGO_FOCUS ?=
2930

3031
test: $(GINKGO_BIN)

tests/e2e/installer.go

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,49 @@ docker run --pid=host --rm -i --privileged \
6262
--restart-mode=systemd
6363
`
6464

65+
// containerdInstallTemplate is a template for installing the NVIDIA Container Toolkit
66+
// on a host using containerd with drop-in configuration support.
67+
var containerdInstallTemplate = `
68+
set -xe
69+
70+
# if the TEMP_DIR is already set, use it
71+
if [ -f /tmp/ctk_e2e_temp_dir.txt ]; then
72+
TEMP_DIR=$(cat /tmp/ctk_e2e_temp_dir.txt)
73+
else
74+
TEMP_DIR="/tmp/ctk_e2e.$(date +%s)_$RANDOM"
75+
echo "$TEMP_DIR" > /tmp/ctk_e2e_temp_dir.txt
76+
fi
77+
78+
# if TEMP_DIR does not exist, create it
79+
if [ ! -d "$TEMP_DIR" ]; then
80+
mkdir -p "$TEMP_DIR"
81+
fi
82+
83+
# Create the drop-in config directory if it doesn't exist
84+
mkdir -p /etc/containerd/conf.d || true
85+
86+
docker run --pid=host --rm -i --privileged \
87+
-v /:/host \
88+
-v "$TEMP_DIR:$TEMP_DIR" \
89+
-v /etc/containerd:/config-root \
90+
{{.Image}} \
91+
--root "$TEMP_DIR/toolkit" \
92+
--runtime=containerd \
93+
--config=/config-root/config.toml \
94+
--drop-in-config=/config-root/conf.d/99-nvidia.toml \
95+
--drop-in-config-host-path=/etc/containerd/conf.d/99-nvidia.toml \
96+
--driver-root=/ \
97+
--no-daemon \
98+
--restart-mode=none{{if .AdditionalFlags}} \
99+
{{.AdditionalFlags}}{{end}}
100+
`
101+
65102
type ToolkitInstaller struct {
66103
runner Runner
67104
template string
68105

69-
Image string
106+
Image string
107+
AdditionalFlags string
70108
}
71109

72110
type installerOption func(*ToolkitInstaller)
@@ -89,6 +127,12 @@ func WithTemplate(template string) installerOption {
89127
}
90128
}
91129

130+
func WithAdditionalFlags(flags string) installerOption {
131+
return func(i *ToolkitInstaller) {
132+
i.AdditionalFlags = flags
133+
}
134+
}
135+
92136
func NewToolkitInstaller(opts ...installerOption) (*ToolkitInstaller, error) {
93137
i := &ToolkitInstaller{
94138
runner: localRunner{},

tests/e2e/nvidia-cdi-refresh_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package e2e
1919
import (
2020
"context"
2121
"fmt"
22-
"html/template"
2322
"strings"
23+
"text/template"
2424

2525
. "github.com/onsi/ginkgo/v2"
2626
. "github.com/onsi/gomega"

tests/e2e/nvidia-container-cli_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ curl -fsSL http://cdimage.ubuntu.com/ubuntu-base/releases/22.04/release/ubuntu-b
4242
}
4343
4444
# Enter a new mount + PID namespace so we can pivot_root without touching the
45-
# container'\''s original filesystem.
46-
unshare --mount --pid --fork --propagation private -- sh -eux <<'\''IN_NS'\''
45+
# container's original filesystem.
46+
unshare --mount --pid --fork --propagation private -- sh -eux <<'IN_NS'
4747
: "${ROOTFS:?}"
4848
4949
# 1 Bind-mount the new root and make the mount private

0 commit comments

Comments
 (0)