Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion internal/discover/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ import (
// A HookName represents a supported CDI hooks.
type HookName string

// An OCIHookType is the OCI lifecycle stage at which a CDI hook runs.
type OCIHookType string

const (
// OCIHookTypeCreateRuntime runs in the runtime namespace before the container is created.
OCIHookTypeCreateRuntime = OCIHookType(cdi.CreateRuntimeHook)
// OCIHookTypeCreateContainer runs in the container mount namespace before pivot_root.
OCIHookTypeCreateContainer = OCIHookType(cdi.CreateContainerHook)
// OCIHookTypeStartContainer runs in the container namespace after the container is started.
OCIHookTypeStartContainer = OCIHookType(cdi.StartContainerHook)
)

const (
// AllHooks is a special hook name that allows all hooks to be matched.
AllHooks = HookName("all")
Expand Down Expand Up @@ -195,13 +207,22 @@ func (c cdiHookCreator) Create(name HookName, args ...string) *Hook {
}

return &Hook{
Lifecycle: cdi.CreateContainerHook,
Lifecycle: string(c.getOCIHookType(name)),
Path: c.nvidiaCDIHookPath,
Args: append(c.requiredArgs(name), c.transformArgs(name, args...)...),
Env: []string{fmt.Sprintf("NVIDIA_CTK_DEBUG=%v", c.debugLogging)},
}
}

func (c cdiHookCreator) getOCIHookType(name HookName) OCIHookType {
switch name {
case CreateSymlinksHook, ChmodHook, DisableDeviceNodeModificationHook, EnableCudaCompatHook, UpdateLDCacheHook:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created the method intentionally this way for readability's sake

return OCIHookTypeCreateContainer
default:
return OCIHookTypeCreateContainer
}
}

func (c cdiHookCreator) isDisabled(name HookName, args ...string) bool {
disabled, ok := c.disabledHooks[name]
if ok {
Expand Down
Loading