Skip to content

Commit 9bbfd8e

Browse files
committed
Allow a resolver to be injected before the system resolver
This allows, for example, cdi mode to be detected. Signed-off-by: Evan Lezar <[email protected]>
1 parent 5c47984 commit 9bbfd8e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pkg/nvlib/info/builder.go

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type builder struct {
2727
nvmllib nvml.Interface
2828
devicelib device.Interface
2929

30+
preHook Resolver
3031
properties Properties
3132
}
3233

@@ -48,6 +49,9 @@ func New(opts ...Option) Interface {
4849
if b.devicelib == nil {
4950
b.devicelib = device.New(device.WithNvml(b.nvmllib))
5051
}
52+
if b.preHook == nil {
53+
b.preHook = noop{}
54+
}
5155
if b.properties == nil {
5256
b.properties = &info{
5357
root: b.root,
@@ -79,6 +83,7 @@ func (b *builder) getResolvers() Resolver {
7983

8084
return firstOf([]Resolver{
8185
auto,
86+
b.preHook,
8287
systemMode,
8388
})
8489
}

pkg/nvlib/info/options.go

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ func WithRoot(root string) Option {
5252
}
5353
}
5454

55+
// WithPreHookResolver provides an Option to set resolvers to use before others.
56+
func WithPreHookResolver(preHook Resolver) Option {
57+
return func(i *builder) {
58+
i.preHook = preHook
59+
}
60+
}
61+
5562
// WithProperties provides an Option to set the Properties interface implementation.
5663
// This is predominantly used for testing.
5764
func WithProperties(properties Properties) Option {

0 commit comments

Comments
 (0)