From f50aecb84e058ff9a7e927c2830e00624227f107 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 6 Sep 2021 11:52:23 +0200 Subject: [PATCH 1/5] Rename -toolkit executable to -runtime-hook This change renames the nvidia-container-toolkit executable to nvidia-container-runtime-hook. Here nvidia-container-toolkit is created as a symlink to nvidia-container-runtime-hook. Signed-off-by: Evan Lezar --- .../capabilities.go | 0 .../capabilities_test.go | 0 .../container_config.go | 0 .../container_config_test.go | 0 .../hook_config.go | 2 +- .../hook_config_test.go | 0 .../hook_test.go | 0 .../main.go | 0 8 files changed, 1 insertion(+), 1 deletion(-) rename cmd/{nvidia-container-toolkit => nvidia-container-runtime-hook}/capabilities.go (100%) rename cmd/{nvidia-container-toolkit => nvidia-container-runtime-hook}/capabilities_test.go (100%) rename cmd/{nvidia-container-toolkit => nvidia-container-runtime-hook}/container_config.go (100%) rename cmd/{nvidia-container-toolkit => nvidia-container-runtime-hook}/container_config_test.go (100%) rename cmd/{nvidia-container-toolkit => nvidia-container-runtime-hook}/hook_config.go (98%) rename cmd/{nvidia-container-toolkit => nvidia-container-runtime-hook}/hook_config_test.go (100%) rename cmd/{nvidia-container-toolkit => nvidia-container-runtime-hook}/hook_test.go (100%) rename cmd/{nvidia-container-toolkit => nvidia-container-runtime-hook}/main.go (100%) diff --git a/cmd/nvidia-container-toolkit/capabilities.go b/cmd/nvidia-container-runtime-hook/capabilities.go similarity index 100% rename from cmd/nvidia-container-toolkit/capabilities.go rename to cmd/nvidia-container-runtime-hook/capabilities.go diff --git a/cmd/nvidia-container-toolkit/capabilities_test.go b/cmd/nvidia-container-runtime-hook/capabilities_test.go similarity index 100% rename from cmd/nvidia-container-toolkit/capabilities_test.go rename to cmd/nvidia-container-runtime-hook/capabilities_test.go diff --git a/cmd/nvidia-container-toolkit/container_config.go b/cmd/nvidia-container-runtime-hook/container_config.go similarity index 100% rename from cmd/nvidia-container-toolkit/container_config.go rename to cmd/nvidia-container-runtime-hook/container_config.go diff --git a/cmd/nvidia-container-toolkit/container_config_test.go b/cmd/nvidia-container-runtime-hook/container_config_test.go similarity index 100% rename from cmd/nvidia-container-toolkit/container_config_test.go rename to cmd/nvidia-container-runtime-hook/container_config_test.go diff --git a/cmd/nvidia-container-toolkit/hook_config.go b/cmd/nvidia-container-runtime-hook/hook_config.go similarity index 98% rename from cmd/nvidia-container-toolkit/hook_config.go rename to cmd/nvidia-container-runtime-hook/hook_config.go index 6a6d18b3..9913ccc5 100644 --- a/cmd/nvidia-container-toolkit/hook_config.go +++ b/cmd/nvidia-container-runtime-hook/hook_config.go @@ -34,7 +34,7 @@ type CLIConfig struct { Ldconfig *string `toml:"ldconfig"` } -// HookConfig : options for the nvidia-container-toolkit. +// HookConfig : options for the nvidia-container-runtime-hook. type HookConfig struct { DisableRequire bool `toml:"disable-require"` SwarmResource *string `toml:"swarm-resource"` diff --git a/cmd/nvidia-container-toolkit/hook_config_test.go b/cmd/nvidia-container-runtime-hook/hook_config_test.go similarity index 100% rename from cmd/nvidia-container-toolkit/hook_config_test.go rename to cmd/nvidia-container-runtime-hook/hook_config_test.go diff --git a/cmd/nvidia-container-toolkit/hook_test.go b/cmd/nvidia-container-runtime-hook/hook_test.go similarity index 100% rename from cmd/nvidia-container-toolkit/hook_test.go rename to cmd/nvidia-container-runtime-hook/hook_test.go diff --git a/cmd/nvidia-container-toolkit/main.go b/cmd/nvidia-container-runtime-hook/main.go similarity index 100% rename from cmd/nvidia-container-toolkit/main.go rename to cmd/nvidia-container-runtime-hook/main.go From 1d81db76a64e6773d0315fccba91428d65a6a1d8 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 6 Sep 2021 11:58:03 +0200 Subject: [PATCH 2/5] Update references to nvidia-container-runtime-hook Signed-off-by: Evan Lezar --- oci-nvidia-hook | 2 +- oci-nvidia-hook.json | 4 ++-- test/container/toolkit_test.sh | 5 +++-- tools/container/crio/crio.go | 5 +++-- tools/container/toolkit/toolkit.go | 8 ++++---- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/oci-nvidia-hook b/oci-nvidia-hook index b00c2986..5e8f3b7d 100755 --- a/oci-nvidia-hook +++ b/oci-nvidia-hook @@ -1,2 +1,2 @@ #!/bin/sh -PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" exec /usr/bin/nvidia-container-toolkit "$@" +PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" exec /usr/bin/nvidia-container-runtime-hook "$@" diff --git a/oci-nvidia-hook.json b/oci-nvidia-hook.json index 5c79b6d0..6cbbe5cf 100644 --- a/oci-nvidia-hook.json +++ b/oci-nvidia-hook.json @@ -1,8 +1,8 @@ { "version": "1.0.0", "hook": { - "path": "/usr/bin/nvidia-container-toolkit", - "args": ["nvidia-container-toolkit", "prestart"], + "path": "/usr/bin/nvidia-container-runtime-hook", + "args": ["nvidia-container-runtime-hook", "prestart"], "env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ] diff --git a/test/container/toolkit_test.sh b/test/container/toolkit_test.sh index 7a21169c..77df5fb0 100644 --- a/test/container/toolkit_test.sh +++ b/test/container/toolkit_test.sh @@ -35,14 +35,15 @@ testing::toolkit::install() { test -e "$(${READLINK} -f "${shared_dir}/usr/local/nvidia/toolkit/libnvidia-container-go.so.1")" test -e "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-cli" - test -e "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-toolkit" + test -e "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-runtime-hook" + test -L "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-toolkit" test -e "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-runtime" grep -q -E "nvidia driver modules are not yet loaded, invoking runc directly" "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-runtime" grep -q -E "exec runc \".@\"" "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-runtime" test -e "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-cli.real" - test -e "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-toolkit.real" + test -e "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-runtime-hook.real" test -e "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-runtime.real" test -e "${shared_dir}/usr/local/nvidia/toolkit/nvidia-container-runtime.experimental" diff --git a/tools/container/crio/crio.go b/tools/container/crio/crio.go index 0459f631..8f09ba48 100644 --- a/tools/container/crio/crio.go +++ b/tools/container/crio/crio.go @@ -21,6 +21,7 @@ import ( "os" "path/filepath" + "github.com/NVIDIA/nvidia-container-toolkit/internal/config" hooks "github.com/containers/podman/v4/pkg/hooks/1.0.0" rspec "github.com/opencontainers/runtime-spec/specs-go" log "github.com/sirupsen/logrus" @@ -164,7 +165,7 @@ func getHookPath(hooksDir string, hookFilename string) string { } func generateOciHook(toolkitDir string) hooks.Hook { - hookPath := filepath.Join(toolkitDir, "nvidia-container-toolkit") + hookPath := filepath.Join(toolkitDir, config.NVIDIAContainerRuntimeHookExecutable) envPath := "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:" + toolkitDir always := true @@ -173,7 +174,7 @@ func generateOciHook(toolkitDir string) hooks.Hook { Stages: []string{"prestart"}, Hook: rspec.Hook{ Path: hookPath, - Args: []string{"nvidia-container-toolkit", "prestart"}, + Args: []string{filepath.Base(config.NVIDIAContainerRuntimeHookExecutable), "prestart"}, Env: []string{envPath}, }, When: hooks.When{ diff --git a/tools/container/toolkit/toolkit.go b/tools/container/toolkit/toolkit.go index 273fcc90..4f215942 100644 --- a/tools/container/toolkit/toolkit.go +++ b/tools/container/toolkit/toolkit.go @@ -33,7 +33,7 @@ const ( DefaultNvidiaDriverRoot = "/run/nvidia/driver" nvidiaContainerCliSource = "/usr/bin/nvidia-container-cli" - nvidiaContainerRuntimeHookSource = "/usr/bin/nvidia-container-toolkit" + nvidiaContainerRuntimeHookSource = "/usr/bin/nvidia-container-runtime-hook" nvidiaContainerToolkitConfigSource = "/etc/nvidia-container-runtime/config.toml" configFilename = "config.toml" @@ -319,8 +319,8 @@ func installRuntimeHook(toolkitDir string, configFilePath string) (string, error e := executable{ source: nvidiaContainerRuntimeHookSource, target: executableTarget{ - dotfileName: "nvidia-container-toolkit.real", - wrapperName: "nvidia-container-toolkit", + dotfileName: "nvidia-container-runtime-hook.real", + wrapperName: "nvidia-container-runtime-hook", }, argLines: argLines, } @@ -330,7 +330,7 @@ func installRuntimeHook(toolkitDir string, configFilePath string) (string, error return "", fmt.Errorf("error installing NVIDIA container runtime hook: %v", err) } - err = installSymlink(toolkitDir, "nvidia-container-runtime-hook", installedPath) + err = installSymlink(toolkitDir, "nvidia-container-toolkit", installedPath) if err != nil { return "", fmt.Errorf("error installing symlink to NVIDIA container runtime hook: %v", err) } From 8a56671d18a3f1953ea973b1b744bc9cb97b72b9 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Mon, 6 Sep 2021 12:22:04 +0200 Subject: [PATCH 3/5] Update package definitions Signed-off-by: Evan Lezar --- packaging/debian/nvidia-container-toolkit.install | 2 +- packaging/debian/nvidia-container-toolkit.postinst | 6 +++--- packaging/debian/nvidia-container-toolkit.postrm | 2 +- packaging/rpm/SPECS/nvidia-container-toolkit.spec | 10 +++++----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packaging/debian/nvidia-container-toolkit.install b/packaging/debian/nvidia-container-toolkit.install index 0faa1ede..2f2bee2a 100644 --- a/packaging/debian/nvidia-container-toolkit.install +++ b/packaging/debian/nvidia-container-toolkit.install @@ -1,4 +1,4 @@ config.toml /etc/nvidia-container-runtime -nvidia-container-toolkit /usr/bin +nvidia-container-runtime-hook /usr/bin nvidia-container-runtime /usr/bin nvidia-ctk /usr/bin diff --git a/packaging/debian/nvidia-container-toolkit.postinst b/packaging/debian/nvidia-container-toolkit.postinst index 6666d5d2..a58d42d5 100644 --- a/packaging/debian/nvidia-container-toolkit.postinst +++ b/packaging/debian/nvidia-container-toolkit.postinst @@ -7,9 +7,9 @@ NVIDIA_CONTAINER_TOOLKIT=/usr/bin/nvidia-container-toolkit case "$1" in configure) - if [ -f "${NVIDIA_CONTAINER_TOOLKIT}" ]; then - if [ ! -e "${NVIDIA_CONTAINER_RUNTIME_HOOK}" ]; then - ln -s ${NVIDIA_CONTAINER_TOOLKIT} ${NVIDIA_CONTAINER_RUNTIME_HOOK} + if [ -f "${NVIDIA_CONTAINER_RUNTIME_HOOK}" ]; then + if [ ! -e "${NVIDIA_CONTAINER_TOOLKIT}" ]; then + ln -s ${NVIDIA_CONTAINER_RUNTIME_HOOK} ${NVIDIA_CONTAINER_TOOLKIT} fi fi ;; diff --git a/packaging/debian/nvidia-container-toolkit.postrm b/packaging/debian/nvidia-container-toolkit.postrm index 688c65b1..bf4e8a5a 100644 --- a/packaging/debian/nvidia-container-toolkit.postrm +++ b/packaging/debian/nvidia-container-toolkit.postrm @@ -7,7 +7,7 @@ NVIDIA_CONTAINER_TOOLKIT=/usr/bin/nvidia-container-toolkit case "$1" in purge) - [ -L "${NVIDIA_CONTAINER_RUNTIME_HOOK}" ] && rm ${NVIDIA_CONTAINER_RUNTIME_HOOK} + [ -L "${NVIDIA_CONTAINER_TOOLKIT}" ] && rm ${NVIDIA_CONTAINER_TOOLKIT} ;; upgrade|failed-upgrade|remove|abort-install|abort-upgrade|disappear) diff --git a/packaging/rpm/SPECS/nvidia-container-toolkit.spec b/packaging/rpm/SPECS/nvidia-container-toolkit.spec index 3f682bde..8fa15bb9 100644 --- a/packaging/rpm/SPECS/nvidia-container-toolkit.spec +++ b/packaging/rpm/SPECS/nvidia-container-toolkit.spec @@ -10,7 +10,7 @@ Summary: NVIDIA container runtime hook URL: https://github.com/NVIDIA/nvidia-container-runtime License: Apache-2.0 -Source0: nvidia-container-toolkit +Source0: nvidia-container-runtime-hook Source1: nvidia-container-runtime Source2: nvidia-ctk Source3: config.toml @@ -38,7 +38,7 @@ cp %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} %{SOURCE5} %{SOURCE6} %install mkdir -p %{buildroot}%{_bindir} -install -m 755 -t %{buildroot}%{_bindir} nvidia-container-toolkit +install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime-hook install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime install -m 755 -t %{buildroot}%{_bindir} nvidia-ctk @@ -52,14 +52,14 @@ mkdir -p %{buildroot}/usr/share/containers/oci/hooks.d install -m 644 -t %{buildroot}/usr/share/containers/oci/hooks.d oci-nvidia-hook.json %posttrans -ln -sf %{_bindir}/nvidia-container-toolkit %{_bindir}/nvidia-container-runtime-hook +ln -sf %{_bindir}/nvidia-container-runtime-hook %{_bindir}/nvidia-container-toolkit %postun -rm -f %{_bindir}/nvidia-container-runtime-hook +rm -f %{_bindir}/nvidia-container-runtime-toolkit %files %license LICENSE -%{_bindir}/nvidia-container-toolkit +%{_bindir}/nvidia-container-runtime-hook %{_bindir}/nvidia-container-runtime %{_bindir}/nvidia-ctk %config /etc/nvidia-container-runtime/config.toml From 6ed3a4e1a692fcfb69e48f4b57091490a0d4126b Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 8 Jul 2022 12:05:12 +0200 Subject: [PATCH 4/5] Update package descriptions and URLs Signed-off-by: Evan Lezar --- packaging/debian/control | 10 +++++----- packaging/rpm/SPECS/nvidia-container-toolkit.spec | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packaging/debian/control b/packaging/debian/control index 22d9d8fd..e2d5b434 100644 --- a/packaging/debian/control +++ b/packaging/debian/control @@ -3,9 +3,9 @@ Section: @SECTION@utils Priority: optional Maintainer: NVIDIA CORPORATION Standards-Version: 3.9.8 -Homepage: https://github.com/NVIDIA/nvidia-container-runtime/wiki -Vcs-Git: https://github.com/NVIDIA/nvidia-container-runtime -Vcs-Browser: https://github.com/NVIDIA/nvidia-container-runtime +Homepage: https://github.com/NVIDIA/nvidia-container-toolkit +Vcs-Git: https://github.com/NVIDIA/nvidia-container-toolkit +Vcs-Browser: https://github.com/NVIDIA/nvidia-container-toolkit Build-Depends: debhelper (>= 9) Package: nvidia-container-toolkit @@ -13,5 +13,5 @@ Architecture: any Depends: ${misc:Depends}, libnvidia-container-tools (>= @LIBNVIDIA_CONTAINER_TOOLS_VERSION@), libnvidia-container-tools (<< 2.0.0), libseccomp2 Breaks: nvidia-container-runtime (<= 3.5.0-1), nvidia-container-runtime-hook Replaces: nvidia-container-runtime (<= 3.5.0-1), nvidia-container-runtime-hook -Description: NVIDIA container runtime hook - Provides a OCI hook to enable GPU support in containers. +Description: NVIDIA Container toolkit + Provides tools and utilities to enable GPU support in containers. diff --git a/packaging/rpm/SPECS/nvidia-container-toolkit.spec b/packaging/rpm/SPECS/nvidia-container-toolkit.spec index 8fa15bb9..34c33e92 100644 --- a/packaging/rpm/SPECS/nvidia-container-toolkit.spec +++ b/packaging/rpm/SPECS/nvidia-container-toolkit.spec @@ -6,8 +6,8 @@ Group: Development Tools Vendor: NVIDIA CORPORATION Packager: NVIDIA CORPORATION -Summary: NVIDIA container runtime hook -URL: https://github.com/NVIDIA/nvidia-container-runtime +Summary: NVIDIA Container Toolkit +URL: https://github.com/NVIDIA/nvidia-container-toolkit License: Apache-2.0 Source0: nvidia-container-runtime-hook @@ -31,7 +31,7 @@ Requires: libseccomp %endif %description -Provides a OCI hook to enable GPU support in containers. +Provides tools and utilities to enable GPU support in containers. %prep cp %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} %{SOURCE5} %{SOURCE6} . From 87afcc3ef462d40f22f6dfc3149a3477f95afa30 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 8 Jul 2022 12:20:17 +0200 Subject: [PATCH 5/5] Reuse check for existing hook This change reuse the code that checks for the existing NVIDIA Container Runtime hook to ensure that both nvidia-container-toolkit and nvidia-container-runtime-hook are detected. Signed-off-by: Evan Lezar --- internal/modifier/stable.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/modifier/stable.go b/internal/modifier/stable.go index 57bacf0b..c927e702 100644 --- a/internal/modifier/stable.go +++ b/internal/modifier/stable.go @@ -20,7 +20,6 @@ import ( "os" "os/exec" "path/filepath" - "strings" "github.com/NVIDIA/nvidia-container-toolkit/internal/config" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" @@ -61,8 +60,8 @@ func (m stableRuntimeModifier) Modify(spec *specs.Spec) error { spec.Hooks = &specs.Hooks{} } else if len(spec.Hooks.Prestart) != 0 { for _, hook := range spec.Hooks.Prestart { - if strings.Contains(hook.Path, config.NVIDIAContainerRuntimeHookExecutable) { - m.logger.Infof("existing nvidia prestart hook found in OCI spec") + if isNVIDIAContainerRuntimeHook(&hook) { + m.logger.Infof("Existing nvidia prestart hook (%v) found in OCI spec", hook.Path) return nil } }