|
16 | 16 |
|
17 | 17 | package config |
18 | 18 |
|
19 | | -type featureName string |
20 | | - |
21 | | -const ( |
22 | | - FeatureGDS = featureName("gds") |
23 | | - FeatureMOFED = featureName("mofed") |
24 | | - FeatureNVSWITCH = featureName("nvswitch") |
25 | | - FeatureGDRCopy = featureName("gdrcopy") |
26 | | -) |
27 | | - |
28 | 19 | // features specifies a set of named features. |
29 | 20 | type features struct { |
30 | | - GDS *feature `toml:"gds,omitempty"` |
31 | | - MOFED *feature `toml:"mofed,omitempty"` |
32 | | - NVSWITCH *feature `toml:"nvswitch,omitempty"` |
33 | | - GDRCopy *feature `toml:"gdrcopy,omitempty"` |
34 | 21 | } |
35 | 22 |
|
| 23 | +//nolint:unused |
36 | 24 | type feature bool |
37 | 25 |
|
38 | | -// IsEnabled checks whether a specified named feature is enabled. |
39 | | -// An optional list of environments to check for feature-specific environment |
40 | | -// variables can also be supplied. |
41 | | -func (fs features) IsEnabled(n featureName, in ...getenver) bool { |
42 | | - featureEnvvars := map[featureName]string{ |
43 | | - FeatureGDS: "NVIDIA_GDS", |
44 | | - FeatureMOFED: "NVIDIA_MOFED", |
45 | | - FeatureNVSWITCH: "NVIDIA_NVSWITCH", |
46 | | - FeatureGDRCopy: "NVIDIA_GDRCOPY", |
47 | | - } |
48 | | - |
49 | | - envvar := featureEnvvars[n] |
50 | | - switch n { |
51 | | - case FeatureGDS: |
52 | | - return fs.GDS.isEnabled(envvar, in...) |
53 | | - case FeatureMOFED: |
54 | | - return fs.MOFED.isEnabled(envvar, in...) |
55 | | - case FeatureNVSWITCH: |
56 | | - return fs.NVSWITCH.isEnabled(envvar, in...) |
57 | | - case FeatureGDRCopy: |
58 | | - return fs.GDRCopy.isEnabled(envvar, in...) |
59 | | - default: |
60 | | - return false |
61 | | - } |
62 | | -} |
63 | | - |
64 | | -// isEnabled checks whether a feature is enabled. |
65 | | -// If the enabled value is explicitly set, this is returned, otherwise the |
66 | | -// associated envvar is checked in the specified getenver for the string "enabled" |
67 | | -// A CUDA container / image can be passed here. |
68 | | -func (f *feature) isEnabled(envvar string, ins ...getenver) bool { |
| 26 | +// IsEnabled checks whether a feature is explicitly enabled. |
| 27 | +// |
| 28 | +//nolint:unused |
| 29 | +func (f *feature) IsEnabled() bool { |
69 | 30 | if f != nil { |
70 | 31 | return bool(*f) |
71 | 32 | } |
72 | | - if envvar == "" { |
73 | | - return false |
74 | | - } |
75 | | - for _, in := range ins { |
76 | | - if in.Getenv(envvar) == "enabled" { |
77 | | - return true |
78 | | - } |
79 | | - } |
80 | 33 | return false |
81 | 34 | } |
82 | | - |
83 | | -type getenver interface { |
84 | | - Getenv(string) string |
85 | | -} |
0 commit comments