Skip to content

[CDI Hooks] add ability to specify OCI hook type#1907

Merged
tariq1890 merged 1 commit into
mainfrom
set-oci-hook-type
Jul 6, 2026
Merged

[CDI Hooks] add ability to specify OCI hook type#1907
tariq1890 merged 1 commit into
mainfrom
set-oci-hook-type

Conversation

@tariq1890

Copy link
Copy Markdown
Contributor

This PR makes it possible to specify a desired OCI hook type should we want the CDI spec generator to create OCI hooks that run in stages other than createContainer.

@tariq1890 tariq1890 requested a review from cdesiniotis July 5, 2026 18:24
@tariq1890 tariq1890 force-pushed the set-oci-hook-type branch from c7ac514 to d753b7e Compare July 5, 2026 18:24
@tariq1890 tariq1890 self-assigned this Jul 5, 2026
@tariq1890 tariq1890 force-pushed the set-oci-hook-type branch 2 times, most recently from 643879b to dfad56e Compare July 5, 2026 18:30
@coveralls

coveralls commented Jul 5, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 28810161382

Coverage increased (+0.009%) to 43.765%

Details

  • Coverage increased (+0.009%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (5 of 7 lines covered, 71.43%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
internal/discover/hooks.go 7 5 71.43%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15060
Covered Lines: 6591
Line Coverage: 43.76%
Coverage Strength: 0.49 hits per line

💛 - Coveralls

@tariq1890 tariq1890 force-pushed the set-oci-hook-type branch from dfad56e to d6cca5e Compare July 5, 2026 19:15
Comment thread internal/discover/compat_libs.go Outdated
// This hook is responsible for setting up CUDA compatibility in the container and depends on the host driver version.
func NewCUDACompatHookDiscoverer(logger logger.Interface, hookCreator HookCreator, o *EnableCUDACompatHookOptions) Discover {
return hookCreator.Create(EnableCudaCompatHook, o.args()...)
return hookCreator.Create(OCIHookTypeCreateContainer, EnableCudaCompatHook, o.args()...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since we're changing the API anyway, what about rather changing the type of the first argument to accept a Hook type that would give us the lifecycle AND the name?

type Hook interface {
    Type() HookType
    Name() HookName
}

For the default hooks we could have HookName implement this interface:

func (h HookName) Type() HookType {
    return OCIHookTypeCreateContainer
}

func (h HookName) Name() HookName {
    return h
}

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 updated the PR without the API changes now

}

hook := d.hookCreator.Create("create-symlinks", d.deviceLinks...)
hook := d.hookCreator.Create(discover.OCIHookTypeCreateContainer, "create-symlinks", d.deviceLinks...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My concern is that the "create-symlink" hook (and others) MUST -- as it's currently designed -- run as a createContainer hook. Splitting these arguments seems to indicate that there is more flexibility than we actually have.

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.

My motivation for this change is to make possible the addition of another CDI hook which will run as createRuntime.

The alternative to this that I can think of is adding a switch-case block within the method to select the OCI hook type based on the CDI hook name. Right now, only createcontainer will get selected of course.

The drawback here is that this approach would not work well for CDI hooks which could be run at different stages. But I am not sure if this is a legitimate scenario that we even want to address.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I share Evan's concern as well. Having the caller set the hook type when currently there is only one "right" choice doesn't feel right to me.

The alternative to this that I can think of is adding a switch-case block within the method to select the OCI hook type based on the CDI hook name. Right now, only createcontainer will get selected of course.

I would prefer this. We could always make this more flexible in the future if a use case arises for it.

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.

@cdesiniotis @elezar I've made the changes without modifying the interface

@tariq1890 tariq1890 force-pushed the set-oci-hook-type branch 3 times, most recently from 3a80cdb to 2e49c1c Compare July 6, 2026 17:21
Signed-off-by: Tariq Ibrahim <tibrahim@nvidia.com>
@tariq1890 tariq1890 force-pushed the set-oci-hook-type branch from 2e49c1c to ed1161d Compare July 6, 2026 17:22

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

@tariq1890

Copy link
Copy Markdown
Contributor Author

Thanks for the review @elezar @cdesiniotis !

@tariq1890 tariq1890 merged commit a60cf25 into main Jul 6, 2026
20 checks passed
@tariq1890 tariq1890 deleted the set-oci-hook-type branch July 6, 2026 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants