Skip to content

Commit fc2d446

Browse files
committed
Add FeatureFlags to the nvcdi API
This change adds support for feature flags to the nvcdi API. A feature flag to disable nvsandboxutils is also added to allow more flexibility in cases where this library causes issue. Signed-off-by: Evan Lezar <[email protected]>
1 parent e70a037 commit fc2d446

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

pkg/nvcdi/api.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ const (
4545
// This was added with v1.17.5 of the NVIDIA Container Toolkit.
4646
HookEnableCudaCompat = HookName("enable-cuda-compat")
4747
)
48+
49+
// A FeatureFlag refers to a specific feature that can be toggled in the CDI api.
50+
// All features are off by default.
51+
type FeatureFlag string
52+
53+
const (
54+
// FeatureDisableNvsandboxUtils disables the use of nvsandboxutils when
55+
// querying devices.
56+
FeatureDisableNvsandboxUtils = FeatureFlag("disable-nvsandbox-utils")
57+
)

pkg/nvcdi/lib.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ type nvcdilib struct {
5656

5757
mergedDeviceOptions []transform.MergedDeviceOption
5858

59+
featureFlags map[FeatureFlag]bool
60+
5961
disabledHooks disabledHooks
6062
hookCreator discover.HookCreator
6163
}
@@ -64,6 +66,7 @@ type nvcdilib struct {
6466
func New(opts ...Option) (Interface, error) {
6567
l := &nvcdilib{
6668
disabledHooks: make(disabledHooks),
69+
featureFlags: make(map[FeatureFlag]bool),
6770
}
6871
for _, opt := range opts {
6972
opt(l)
@@ -218,6 +221,9 @@ func (l *nvcdilib) getCudaVersionNvsandboxutils() (string, error) {
218221
// getNvsandboxUtilsLib returns the nvsandboxutilslib to use for CDI spec
219222
// generation.
220223
func (l *nvcdilib) getNvsandboxUtilsLib() nvsandboxutils.Interface {
224+
if l.featureFlags[FeatureDisableNvsandboxUtils] {
225+
return nil
226+
}
221227
if l.nvsandboxutilslib != nil {
222228
return l.nvsandboxutilslib
223229
}

pkg/nvcdi/options.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,14 @@ func WithDisabledHook(hook HookName) Option {
166166
o.disabledHooks[hook] = true
167167
}
168168
}
169+
170+
// WithFeatureFlag allows specified features to be toggled on.
171+
// This option can be specified multiple times for each feature flag.
172+
func WithFeatureFlag(featureFlag FeatureFlag) Option {
173+
return func(o *nvcdilib) {
174+
if o.featureFlags == nil {
175+
o.featureFlags = make(map[FeatureFlag]bool)
176+
}
177+
o.featureFlags[featureFlag] = true
178+
}
179+
}

0 commit comments

Comments
 (0)