mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-16 13:28:18 +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:
parent
74d6993e9b
commit
b0d0797936
5 changed files with 33 additions and 8 deletions
15
README.md
15
README.md
|
@ -189,8 +189,10 @@ format: `<class>_<vendor>`. E.g.
|
||||||
node.alpha.kubernetes-incubator.io/nfd-pci-1200_8086.present=true
|
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
|
The set of PCI device classes that the feature source detects is configurable.
|
||||||
accelerator cards are deteted.
|
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
|
### 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
|
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
|
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
|
Configuration options specified from the command line will override those read
|
||||||
from the config file.
|
from the config file.
|
||||||
|
|
||||||
|
Currently, the only available configuration options are related to the
|
||||||
|
[PCI feature source](#pci-features).
|
||||||
|
|
||||||
## Building from source
|
## Building from source
|
||||||
|
|
||||||
Download the source code.
|
Download the source code.
|
||||||
|
|
3
main.go
3
main.go
|
@ -54,6 +54,7 @@ var (
|
||||||
// Global config
|
// Global config
|
||||||
type NFDConfig struct {
|
type NFDConfig struct {
|
||||||
Sources struct {
|
Sources struct {
|
||||||
|
Pci *pci.NFDConfig `json:"pci,omitempty"`
|
||||||
} `json:"sources,omitempty"`
|
} `json:"sources,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +207,8 @@ func argsParse(argv []string) (args Args) {
|
||||||
|
|
||||||
// Parse configuration options
|
// Parse configuration options
|
||||||
func configParse(filepath string, overrides string) error {
|
func configParse(filepath string, overrides string) error {
|
||||||
|
config.Sources.Pci = &pci.Config
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(filepath)
|
data, err := ioutil.ReadFile(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to read config file: %s", err)
|
return fmt.Errorf("Failed to read config file: %s", err)
|
||||||
|
|
|
@ -189,7 +189,10 @@ func TestConfigParse(t *testing.T) {
|
||||||
f, err := ioutil.TempFile("", "nfd-test-")
|
f, err := ioutil.TempFile("", "nfd-test-")
|
||||||
defer os.Remove(f.Name())
|
defer os.Remove(f.Name())
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
f.WriteString(`sources:`)
|
f.WriteString(`sources:
|
||||||
|
pci:
|
||||||
|
deviceClassWhitelist:
|
||||||
|
- "ff"`)
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
Convey("When proper config file is given", func() {
|
Convey("When proper config file is given", func() {
|
||||||
|
@ -197,6 +200,7 @@ func TestConfigParse(t *testing.T) {
|
||||||
|
|
||||||
Convey("Should return error", func() {
|
Convey("Should return error", func() {
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
So(config.Sources.Pci.DeviceClassWhitelist, ShouldResemble, []string{"ff"})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1 +1,6 @@
|
||||||
#sources:
|
#sources:
|
||||||
|
# pci:
|
||||||
|
# deviceClassWhitelist:
|
||||||
|
# - "0200"
|
||||||
|
# - "03"
|
||||||
|
# - "12"
|
||||||
|
|
|
@ -29,7 +29,13 @@ type pciDeviceInfo map[string]string
|
||||||
|
|
||||||
var logger = log.New(os.Stderr, "", log.LstdFlags)
|
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
|
// Implement FeatureSource interface
|
||||||
type Source struct{}
|
type Source struct{}
|
||||||
|
@ -47,8 +53,8 @@ func (s Source) Discover() ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for class, classDevs := range devs {
|
for class, classDevs := range devs {
|
||||||
for _, white := range deviceClassWhitelist {
|
for _, white := range Config.DeviceClassWhitelist {
|
||||||
if strings.HasPrefix(class, white) {
|
if strings.HasPrefix(class, strings.ToLower(white)) {
|
||||||
for _, dev := range classDevs {
|
for _, dev := range classDevs {
|
||||||
features[fmt.Sprintf("%s_%s.present", dev["class"], dev["vendor"])] = true
|
features[fmt.Sprintf("%s_%s.present", dev["class"], dev["vendor"])] = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue