Skip to content

Commit 875b92c

Browse files
authored
Merge pull request #2512 from crosbymichael/gpupath
Add nvidia Opts to lookup containerd binary or hook path
2 parents ed0e734 + e4f33dc commit 875b92c

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
@@ -69,9 +69,12 @@ func WithGPUs(opts ...Opts) oci.SpecOpts {
6969
return err
7070
}
7171
}
72-
path, err := exec.LookPath("containerd")
73-
if err != nil {
74-
return err
72+
if c.OCIHookPath == "" {
73+
path, err := exec.LookPath("containerd")
74+
if err != nil {
75+
return err
76+
}
77+
c.OCIHookPath = path
7578
}
7679
nvidiaPath, err := exec.LookPath(nvidiaCLI)
7780
if err != nil {
@@ -81,7 +84,7 @@ func WithGPUs(opts ...Opts) oci.SpecOpts {
8184
s.Hooks = &specs.Hooks{}
8285
}
8386
s.Hooks.Prestart = append(s.Hooks.Prestart, specs.Hook{
84-
Path: path,
87+
Path: c.OCIHookPath,
8588
Args: append([]string{
8689
"containerd",
8790
"oci-hook",
@@ -101,6 +104,7 @@ type config struct {
101104
LDCache string
102105
LDConfig string
103106
Requirements []string
107+
OCIHookPath string
104108
}
105109

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

0 commit comments

Comments
 (0)