Skip to content

Commit e4f33dc

Browse files
committed
Add nvidia Opts to lookup containerd binary or hook path
This is for consumers like Docker that manage a `docker-containerd`. Signed-off-by: Michael Crosby <[email protected]>
1 parent ca71484 commit e4f33dc

1 file changed

Lines changed: 28 additions & 4 deletions

File tree

contrib/nvidia/nvidia.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ func WithGPUs(opts ...Opts) oci.SpecOpts {
6060
return err
6161
}
6262
}
63-
path, err := exec.LookPath("containerd")
64-
if err != nil {
65-
return err
63+
if c.OCIHookPath == "" {
64+
path, err := exec.LookPath("containerd")
65+
if err != nil {
66+
return err
67+
}
68+
c.OCIHookPath = path
6669
}
6770
nvidiaPath, err := exec.LookPath(nvidiaCLI)
6871
if err != nil {
@@ -72,7 +75,7 @@ func WithGPUs(opts ...Opts) oci.SpecOpts {
7275
s.Hooks = &specs.Hooks{}
7376
}
7477
s.Hooks.Prestart = append(s.Hooks.Prestart, specs.Hook{
75-
Path: path,
78+
Path: c.OCIHookPath,
7679
Args: append([]string{
7780
"containerd",
7881
"oci-hook",
@@ -92,6 +95,7 @@ type config struct {
9295
LDCache string
9396
LDConfig string
9497
Requirements []string
98+
OCIHookPath string
9599
}
96100

97101
func (c *config) args() []string {
@@ -181,3 +185,23 @@ func WithRequiredCUDAVersion(major, minor int) Opts {
181185
return nil
182186
}
183187
}
188+
189+
// WithOCIHookPath sets the hook path for the binary
190+
func WithOCIHookPath(path string) Opts {
191+
return func(c *config) error {
192+
c.OCIHookPath = path
193+
return nil
194+
}
195+
}
196+
197+
// WithLookupOCIHookPath sets the hook path for the binary via a binary name
198+
func WithLookupOCIHookPath(name string) Opts {
199+
return func(c *config) error {
200+
path, err := exec.LookPath(name)
201+
if err != nil {
202+
return err
203+
}
204+
c.OCIHookPath = path
205+
return nil
206+
}
207+
}

0 commit comments

Comments
 (0)