Skip to content

Commit e4fee32

Browse files
author
Evan Lezar
committed
Merge branch 'fix-hook' into 'main'
Handle empty root in config See merge request nvidia/container-toolkit/container-toolkit!454
2 parents 80a78e6 + ec63533 commit e4fee32

File tree

5 files changed

+71
-10
lines changed

5 files changed

+71
-10
lines changed

cmd/nvidia-container-runtime-hook/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func doPrestart() {
9292
rootfs := getRootfsPath(container)
9393

9494
args := []string{getCLIPath(cli)}
95-
if cli.Root != nil {
95+
if cli.Root != nil && *cli.Root != "" {
9696
args = append(args, fmt.Sprintf("--root=%s", *cli.Root))
9797
}
9898
if cli.LoadKmods {

internal/config/cli.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ package config
1818

1919
// ContainerCLIConfig stores the options for the nvidia-container-cli
2020
type ContainerCLIConfig struct {
21-
Root string `toml:"root"`
22-
LoadKmods bool `toml:"load-kmods"`
23-
Ldconfig string `toml:"ldconfig"`
21+
Root string `toml:"root"`
22+
LoadKmods bool `toml:"load-kmods"`
23+
Ldconfig string `toml:"ldconfig"`
24+
Environment []string `toml:"environment"`
2425
}

internal/config/config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var (
5757
// Config represents the contents of the config.toml file for the NVIDIA Container Toolkit
5858
// Note: This is currently duplicated by the HookConfig in cmd/nvidia-container-toolkit/hook_config.go
5959
type Config struct {
60+
DisableRequire bool `toml:"disable-require"`
6061
AcceptEnvvarUnprivileged bool `toml:"accept-nvidia-visible-devices-envvar-when-unprivileged"`
6162

6263
NVIDIAContainerCLIConfig ContainerCLIConfig `toml:"nvidia-container-cli"`
@@ -279,25 +280,26 @@ func (c Config) asCommentedToml() (*toml.Tree, error) {
279280
}
280281
for k, v := range commentedDefaults {
281282
set := asToml.Get(k)
282-
fmt.Printf("k=%v v=%+v set=%+v\n", k, v, set)
283283
if !shouldComment(k, v, set) {
284284
continue
285285
}
286-
fmt.Printf("set=%+v v=%+v\n", set, v)
287286
asToml.SetWithComment(k, "", true, v)
288287
}
289288

290289
return asToml, nil
291290
}
292291

293-
func shouldComment(key string, value interface{}, set interface{}) bool {
292+
func shouldComment(key string, defaultValue interface{}, setTo interface{}) bool {
293+
if key == "nvidia-container-cli.root" && setTo == "" {
294+
return true
295+
}
294296
if key == "nvidia-container-cli.user" && !getCommentedUserGroup() {
295297
return false
296298
}
297-
if key == "nvidia-container-runtime.debug" && set == "/dev/null" {
299+
if key == "nvidia-container-runtime.debug" && setTo == "/dev/null" {
298300
return true
299301
}
300-
if set == nil || value == set {
302+
if setTo == nil || defaultValue == setTo {
301303
return true
302304
}
303305

internal/config/config_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package config
1818

1919
import (
20+
"bytes"
2021
"io/ioutil"
2122
"os"
2223
"path/filepath"
@@ -234,3 +235,47 @@ func TestGetConfig(t *testing.T) {
234235
})
235236
}
236237
}
238+
239+
func TestConfigDefault(t *testing.T) {
240+
config, err := getDefault()
241+
require.NoError(t, err)
242+
243+
buffer := new(bytes.Buffer)
244+
_, err = config.Save(buffer)
245+
require.NoError(t, err)
246+
247+
var lines []string
248+
for _, l := range strings.Split(buffer.String(), "\n") {
249+
l = strings.TrimSpace(l)
250+
if strings.HasPrefix(l, "# ") {
251+
l = "#" + strings.TrimPrefix(l, "# ")
252+
}
253+
lines = append(lines, l)
254+
}
255+
256+
// We take the lines from the config that was included in previous packages.
257+
expectedLines := []string{
258+
"disable-require = false",
259+
"#swarm-resource = \"DOCKER_RESOURCE_GPU\"",
260+
"#accept-nvidia-visible-devices-envvar-when-unprivileged = true",
261+
"#accept-nvidia-visible-devices-as-volume-mounts = false",
262+
263+
"#root = \"/run/nvidia/driver\"",
264+
"#path = \"/usr/bin/nvidia-container-cli\"",
265+
"environment = []",
266+
"#debug = \"/var/log/nvidia-container-toolkit.log\"",
267+
"#ldcache = \"/etc/ld.so.cache\"",
268+
"load-kmods = true",
269+
"#no-cgroups = false",
270+
"#user = \"root:video\"",
271+
272+
"[nvidia-container-runtime]",
273+
"#debug = \"/var/log/nvidia-container-runtime.log\"",
274+
"log-level = \"info\"",
275+
"mode = \"auto\"",
276+
277+
"mount-spec-path = \"/etc/nvidia-container-runtime/host-files-for-container.d\"",
278+
}
279+
280+
require.Subset(t, lines, expectedLines)
281+
}

scripts/release-packages.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,20 @@ function sync() {
102102
ubuntu*) pkg_type=deb
103103
;;
104104
*) echo "ERROR: unexpected distribution ${src_dist}"
105+
exit 1
105106
;;
106107
esac
107108

109+
if [[ $# -ge 4 && $4 == "package_type" ]] ; then
110+
if [[ "${src_dist}" != "ubuntu18.04" && "${src_dist}" != "centos7" ]]; then
111+
echo "Package type repos require ubuntu18.04 or centos7 as the source"
112+
echo "skipping"
113+
return
114+
fi
115+
dst_dist=$pkg_type
116+
fi
117+
118+
108119
local arch=${target##*-}
109120
local dst_arch=${arch}
110121
case ${src_dist} in
@@ -174,11 +185,13 @@ git -C ${PACKAGE_REPO_ROOT} clean -fdx ${REPO}
174185

175186
for target in ${targets[@]}; do
176187
sync ${target} ${PACKAGE_CACHE}/packages ${PACKAGE_REPO_ROOT}/${REPO}
188+
# We also create a `package_type` repo; internally we skip this for non-ubuntu18.04 or centos7 distributions
189+
sync ${target} ${PACKAGE_CACHE}/packages ${PACKAGE_REPO_ROOT}/${REPO} "package_type"
177190
done
178191

179192
git -C ${PACKAGE_REPO_ROOT} add ${REPO}
180193

181-
if [[ ${REPO} == "stable" ]]; then
194+
if [[ "${REPO}" == "stable" ]]; then
182195
# Stable release
183196
git -C ${PACKAGE_REPO_ROOT} commit -s -F- <<EOF
184197
Add packages for NVIDIA Container Toolkit ${VERSION} release

0 commit comments

Comments
 (0)