1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

Add config support for the pci feature source

User can now configure the list of device classes to detect, either via
a configuration file or by using the --options command line flag.

An example of a command line flag to detect all network controllers and
("main class 0x02) and VGA display controllers ("main" class 0x03 and
subclass 0x00) would be:
  --options='{"sources": {"pci": {"deviceClassWhitelist": ["02", "0300"] } } }'
This commit is contained in:
Markus Lehtonen 2018-09-21 13:25:47 +03:00
parent 74d6993e9b
commit b0d0797936
5 changed files with 33 additions and 8 deletions

View file

@ -189,8 +189,10 @@ format: `<class>_<vendor>`. E.g.
node.alpha.kubernetes-incubator.io/nfd-pci-1200_8086.present=true
```
Only device classes (0x)03, (0x)0b40 and (0x)12, i.e. GPUs, co-processors and
accelerator cards are deteted.
The set of PCI device classes that the feature source detects is configurable.
By default, device classes (0x)03, (0x)0b40 and (0x)12, i.e. GPUs,
co-processors and accelerator cards are deteted.
See [configuration options](#configuration-options) for more information.
### RDT (Intel Resource Director Technology) Features
@ -294,11 +296,16 @@ configuration in custom-built images.
Configuration options can also be specified via the `--options` command line
flag, in which case no mounts need to be used. The same format as in the config
file must be used, i.e. JSON (or YAML).
file must be used, i.e. JSON (or YAML). For example:
```
--options='{"sources": { "pci": { "deviceClassWhitelist": ["12"] } } }'
```
Configuration options specified from the command line will override those read
from the config file.
Currently, the only available configuration options are related to the
[PCI feature source](#pci-features).
## Building from source
Download the source code.

View file

@ -54,6 +54,7 @@ var (
// Global config
type NFDConfig struct {
Sources struct {
Pci *pci.NFDConfig `json:"pci,omitempty"`
} `json:"sources,omitempty"`
}
@ -206,6 +207,8 @@ func argsParse(argv []string) (args Args) {
// Parse configuration options
func configParse(filepath string, overrides string) error {
config.Sources.Pci = &pci.Config
data, err := ioutil.ReadFile(filepath)
if err != nil {
return fmt.Errorf("Failed to read config file: %s", err)

View file

@ -189,7 +189,10 @@ func TestConfigParse(t *testing.T) {
f, err := ioutil.TempFile("", "nfd-test-")
defer os.Remove(f.Name())
So(err, ShouldBeNil)
f.WriteString(`sources:`)
f.WriteString(`sources:
pci:
deviceClassWhitelist:
- "ff"`)
f.Close()
Convey("When proper config file is given", func() {
@ -197,6 +200,7 @@ func TestConfigParse(t *testing.T) {
Convey("Should return error", func() {
So(err, ShouldBeNil)
So(config.Sources.Pci.DeviceClassWhitelist, ShouldResemble, []string{"ff"})
})
})
})

View file

@ -1 +1,6 @@
#sources:
# pci:
# deviceClassWhitelist:
# - "0200"
# - "03"
# - "12"

View file

@ -29,7 +29,13 @@ type pciDeviceInfo map[string]string
var logger = log.New(os.Stderr, "", log.LstdFlags)
var deviceClassWhitelist = []string{"03", "0b40", "12"}
type NFDConfig struct {
DeviceClassWhitelist []string `json:"deviceClassWhitelist,omitempty"`
}
var Config = NFDConfig{
DeviceClassWhitelist: []string{"03", "0b40", "12"},
}
// Implement FeatureSource interface
type Source struct{}
@ -47,8 +53,8 @@ func (s Source) Discover() ([]string, error) {
}
for class, classDevs := range devs {
for _, white := range deviceClassWhitelist {
if strings.HasPrefix(class, white) {
for _, white := range Config.DeviceClassWhitelist {
if strings.HasPrefix(class, strings.ToLower(white)) {
for _, dev := range classDevs {
features[fmt.Sprintf("%s_%s.present", dev["class"], dev["vendor"])] = true
}