Skip to content

Commit

Permalink
packages: add NVIDIA k8s device plugin
Browse files Browse the repository at this point in the history
The NVIDIA k8s device plugin exposes to the kubelet the NVIDIA GPUs in
the host. By providing the k8s device plugin in the base image, the
startup time for a GPU workload decreases, since the kubelet doesn't
have to fetch yet another system container.

Signed-off-by: Arnaldo Garcia Rincon <[email protected]>
  • Loading branch information
arnaldo2792 committed Jan 19, 2022
1 parent 5b9bc1d commit 6d39439
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/nvidia-container-toolkit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sha512 = "7bc3601ca5cca5b3ad7f30f9c2453d41452b425811d37209c20b7f375d557666a1369d
[build-dependencies]
glibc = { path = "../glibc" }
libnvidia-container = { path = "../libnvidia-container" }
nvidia-k8s-device-plugin = { path = "../nvidia-k8s-device-plugin" }
# This package depends on `shimpei`, but it is built in the `os` package
# which is expected to be pulled in
# os = { path = "../os" }
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Source3: nvidia-oci-hooks-json
BuildRequires: %{_cross_os}glibc-devel
Requires: %{_cross_os}libnvidia-container
Requires: %{_cross_os}shimpei
Requires: %{_cross_os}nvidia-k8s-device-plugin

%description
%{summary}.
Expand Down
19 changes: 19 additions & 0 deletions packages/nvidia-k8s-device-plugin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "nvidia-k8s-device-plugin"
version = "0.1.0"
edition = "2018"
publish = false
build = "build.rs"

[lib]
path = "pkg.rs"

[package.metadata.build-package]
releases-url = "https://github.com/NVIDIA/k8s-device-plugin/releases"

[[package.metadata.build-package.external-files]]
url = "https://github.com/NVIDIA/k8s-device-plugin/archive/v0.10.0/v0.10.0.tar.gz"
sha512 = "d83107ef511a1fa8b43596726e084feea1bbf9b0e22754444e76cbf0aefd5476421d00bc02173c606509f0dbf7b4e86f9453d59fca976b7f8f15c7667932bebe"

[build-dependencies]
glibc = { path = "../glibc" }
9 changes: 9 additions & 0 deletions packages/nvidia-k8s-device-plugin/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use std::process::{exit, Command};

fn main() -> Result<(), std::io::Error> {
let ret = Command::new("buildsys").arg("build-package").status()?;
if !ret.success() {
exit(1);
}
Ok(())
}
17 changes: 17 additions & 0 deletions packages/nvidia-k8s-device-plugin/nvidia-k8s-device-plugin.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Start NVIDIA kubernetes device plugin
RefuseManualStart=true
RefuseManualStop=true
After=kubelet.service
BindsTo=kubelet.service

[Service]
ExecStart=/usr/bin/nvidia-device-plugin
Type=simple
TimeoutSec=0
RestartSec=2
Restart=always
StandardError=journal+console

[Install]
WantedBy=multi-user.target
43 changes: 43 additions & 0 deletions packages/nvidia-k8s-device-plugin/nvidia-k8s-device-plugin.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
%global goproject github.com/NVIDIA
%global gorepo k8s-device-plugin
%global goimport %{goproject}/%{gorepo}

%global gover 0.10.0
%global rpmver %{gover}

Name: %{_cross_os}nvidia-k8s-device-plugin
Version: %{rpmver}
Release: 1%{?dist}
Summary: Kubernetes device plugin for NVIDIA GPUs
License: Apache-2.0
URL: https://github.com/NVIDIA/k8s-device-plugin
Source0: https://%{goimport}/archive/v%{gover}/v%{gover}.tar.gz
Source1: nvidia-k8s-device-plugin.service

BuildRequires: %{_cross_os}glibc-devel

%description
%{summary}.

%prep
%autosetup -n %{gorepo}-%{gover} -p1
%cross_go_setup %{gorepo}-%{gover} %{goproject} %{goimport}

%build
%cross_go_configure %{goimport}
# We don't set `-Wl,-z,now`, because the binary uses lazy loading
# to load the NVIDIA libraries in the host
export CGO_LDFLAGS="-Wl,-z,relro"
go build -ldflags="${GOLDFLAGS}" -o nvidia-device-plugin ./cmd/nvidia-device-plugin/

%install
install -d %{buildroot}%{_cross_bindir}
install -d %{buildroot}%{_cross_unitdir}
install -p -m 0755 nvidia-device-plugin %{buildroot}%{_cross_bindir}
install -p -m 0644 %{S:1} %{buildroot}%{_cross_unitdir}

%files
%license LICENSE
%{_cross_attribution_file}
%{_cross_unitdir}/nvidia-k8s-device-plugin.service
%{_cross_bindir}/nvidia-device-plugin
1 change: 1 addition & 0 deletions packages/nvidia-k8s-device-plugin/pkg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// not used

0 comments on commit 6d39439

Please sign in to comment.