mirror of
				https://github.com/NVIDIA/nvidia-container-toolkit
				synced 2025-06-26 18:18:24 +00:00 
			
		
		
		
	Merge branch 'fix-hook' into 'main'
Handle empty root in config See merge request nvidia/container-toolkit/container-toolkit!454
This commit is contained in:
		
						commit
						e4fee325cb
					
				| @ -92,7 +92,7 @@ func doPrestart() { | ||||
| 	rootfs := getRootfsPath(container) | ||||
| 
 | ||||
| 	args := []string{getCLIPath(cli)} | ||||
| 	if cli.Root != nil { | ||||
| 	if cli.Root != nil && *cli.Root != "" { | ||||
| 		args = append(args, fmt.Sprintf("--root=%s", *cli.Root)) | ||||
| 	} | ||||
| 	if cli.LoadKmods { | ||||
|  | ||||
| @ -18,7 +18,8 @@ package config | ||||
| 
 | ||||
| // ContainerCLIConfig stores the options for the nvidia-container-cli
 | ||||
| type ContainerCLIConfig struct { | ||||
| 	Root      string `toml:"root"` | ||||
| 	LoadKmods bool   `toml:"load-kmods"` | ||||
| 	Ldconfig  string `toml:"ldconfig"` | ||||
| 	Root        string   `toml:"root"` | ||||
| 	LoadKmods   bool     `toml:"load-kmods"` | ||||
| 	Ldconfig    string   `toml:"ldconfig"` | ||||
| 	Environment []string `toml:"environment"` | ||||
| } | ||||
|  | ||||
| @ -57,6 +57,7 @@ var ( | ||||
| // Config represents the contents of the config.toml file for the NVIDIA Container Toolkit
 | ||||
| // Note: This is currently duplicated by the HookConfig in cmd/nvidia-container-toolkit/hook_config.go
 | ||||
| type Config struct { | ||||
| 	DisableRequire           bool `toml:"disable-require"` | ||||
| 	AcceptEnvvarUnprivileged bool `toml:"accept-nvidia-visible-devices-envvar-when-unprivileged"` | ||||
| 
 | ||||
| 	NVIDIAContainerCLIConfig         ContainerCLIConfig `toml:"nvidia-container-cli"` | ||||
| @ -279,25 +280,26 @@ func (c Config) asCommentedToml() (*toml.Tree, error) { | ||||
| 	} | ||||
| 	for k, v := range commentedDefaults { | ||||
| 		set := asToml.Get(k) | ||||
| 		fmt.Printf("k=%v v=%+v set=%+v\n", k, v, set) | ||||
| 		if !shouldComment(k, v, set) { | ||||
| 			continue | ||||
| 		} | ||||
| 		fmt.Printf("set=%+v v=%+v\n", set, v) | ||||
| 		asToml.SetWithComment(k, "", true, v) | ||||
| 	} | ||||
| 
 | ||||
| 	return asToml, nil | ||||
| } | ||||
| 
 | ||||
| func shouldComment(key string, value interface{}, set interface{}) bool { | ||||
| func shouldComment(key string, defaultValue interface{}, setTo interface{}) bool { | ||||
| 	if key == "nvidia-container-cli.root" && setTo == "" { | ||||
| 		return true | ||||
| 	} | ||||
| 	if key == "nvidia-container-cli.user" && !getCommentedUserGroup() { | ||||
| 		return false | ||||
| 	} | ||||
| 	if key == "nvidia-container-runtime.debug" && set == "/dev/null" { | ||||
| 	if key == "nvidia-container-runtime.debug" && setTo == "/dev/null" { | ||||
| 		return true | ||||
| 	} | ||||
| 	if set == nil || value == set { | ||||
| 	if setTo == nil || defaultValue == setTo { | ||||
| 		return true | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -17,6 +17,7 @@ | ||||
| package config | ||||
| 
 | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"io/ioutil" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| @ -234,3 +235,47 @@ func TestGetConfig(t *testing.T) { | ||||
| 		}) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestConfigDefault(t *testing.T) { | ||||
| 	config, err := getDefault() | ||||
| 	require.NoError(t, err) | ||||
| 
 | ||||
| 	buffer := new(bytes.Buffer) | ||||
| 	_, err = config.Save(buffer) | ||||
| 	require.NoError(t, err) | ||||
| 
 | ||||
| 	var lines []string | ||||
| 	for _, l := range strings.Split(buffer.String(), "\n") { | ||||
| 		l = strings.TrimSpace(l) | ||||
| 		if strings.HasPrefix(l, "# ") { | ||||
| 			l = "#" + strings.TrimPrefix(l, "# ") | ||||
| 		} | ||||
| 		lines = append(lines, l) | ||||
| 	} | ||||
| 
 | ||||
| 	// We take the lines from the config that was included in previous packages.
 | ||||
| 	expectedLines := []string{ | ||||
| 		"disable-require = false", | ||||
| 		"#swarm-resource = \"DOCKER_RESOURCE_GPU\"", | ||||
| 		"#accept-nvidia-visible-devices-envvar-when-unprivileged = true", | ||||
| 		"#accept-nvidia-visible-devices-as-volume-mounts = false", | ||||
| 
 | ||||
| 		"#root = \"/run/nvidia/driver\"", | ||||
| 		"#path = \"/usr/bin/nvidia-container-cli\"", | ||||
| 		"environment = []", | ||||
| 		"#debug = \"/var/log/nvidia-container-toolkit.log\"", | ||||
| 		"#ldcache = \"/etc/ld.so.cache\"", | ||||
| 		"load-kmods = true", | ||||
| 		"#no-cgroups = false", | ||||
| 		"#user = \"root:video\"", | ||||
| 
 | ||||
| 		"[nvidia-container-runtime]", | ||||
| 		"#debug = \"/var/log/nvidia-container-runtime.log\"", | ||||
| 		"log-level = \"info\"", | ||||
| 		"mode = \"auto\"", | ||||
| 
 | ||||
| 		"mount-spec-path = \"/etc/nvidia-container-runtime/host-files-for-container.d\"", | ||||
| 	} | ||||
| 
 | ||||
| 	require.Subset(t, lines, expectedLines) | ||||
| } | ||||
|  | ||||
| @ -102,9 +102,20 @@ function sync() { | ||||
|     ubuntu*) pkg_type=deb | ||||
|         ;; | ||||
|     *) echo "ERROR: unexpected distribution ${src_dist}" | ||||
|        exit 1 | ||||
|         ;; | ||||
|     esac | ||||
| 
 | ||||
|     if [[ $# -ge 4 && $4 == "package_type" ]] ; then | ||||
|         if [[ "${src_dist}" != "ubuntu18.04" && "${src_dist}" != "centos7" ]]; then | ||||
|             echo "Package type repos require ubuntu18.04 or centos7 as the source" | ||||
|             echo "skipping" | ||||
|             return | ||||
|         fi | ||||
|         dst_dist=$pkg_type | ||||
|     fi | ||||
| 
 | ||||
| 
 | ||||
|     local arch=${target##*-} | ||||
|     local dst_arch=${arch} | ||||
|     case ${src_dist} in | ||||
| @ -174,11 +185,13 @@ git -C ${PACKAGE_REPO_ROOT} clean -fdx ${REPO} | ||||
| 
 | ||||
| for target in ${targets[@]}; do | ||||
|     sync ${target} ${PACKAGE_CACHE}/packages ${PACKAGE_REPO_ROOT}/${REPO} | ||||
|     # We also create a `package_type` repo; internally we skip this for non-ubuntu18.04 or centos7 distributions | ||||
|     sync ${target} ${PACKAGE_CACHE}/packages ${PACKAGE_REPO_ROOT}/${REPO} "package_type" | ||||
| done | ||||
| 
 | ||||
| git -C ${PACKAGE_REPO_ROOT} add ${REPO} | ||||
| 
 | ||||
| if [[ ${REPO} == "stable" ]]; then | ||||
| if [[ "${REPO}" == "stable" ]]; then | ||||
| # Stable release | ||||
| git -C ${PACKAGE_REPO_ROOT} commit -s -F- <<EOF | ||||
| Add packages for NVIDIA Container Toolkit ${VERSION} release | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user