mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-05 08:17:04 +00:00
nfd-worker: add special handling for --sources=all
A new special value 'all' is a shortcut for enabling all feature sources. It should be the only name specified -- if any other names are specified 'all' does not take effect, but, we only enable the listed feature sources. E.g. --sources=all enables all sources, but --sources=all,cpu only enables the cpu source Also, print a warning if unknown sources are specified.
This commit is contained in:
parent
b0c02455d6
commit
29cbb2429c
5 changed files with 36 additions and 19 deletions
|
@ -90,8 +90,9 @@ func argsParse(argv []string) (worker.Args, error) {
|
|||
--server-name-override=<name> Name (CN) expect from server certificate, useful
|
||||
in testing
|
||||
[Default: ]
|
||||
--sources=<sources> Comma separated list of feature sources.
|
||||
[Default: cpu,custom,iommu,kernel,local,memory,network,pci,storage,system,usb]
|
||||
--sources=<sources> Comma separated list of feature sources. Special
|
||||
value 'all' enables all feature sources.
|
||||
[Default: all]
|
||||
--no-publish Do not publish discovered features to the
|
||||
cluster-local Kubernetes API server.
|
||||
--label-whitelist=<pattern> Regular expression to filter label names to
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
var allSources = []string{"cpu", "custom", "iommu", "kernel", "local", "memory", "network", "pci", "storage", "system", "usb"}
|
||||
var allSources = []string{"all"}
|
||||
|
||||
func TestArgsParse(t *testing.T) {
|
||||
Convey("When parsing command line arguments", t, func() {
|
||||
|
|
|
@ -222,8 +222,6 @@ Command line flags of nfd-worker:
|
|||
```bash
|
||||
$ docker run --rm ${NFD_CONTAINER_IMAGE} nfd-worker --help
|
||||
...
|
||||
nfd-worker.
|
||||
|
||||
Usage:
|
||||
nfd-worker [--no-publish] [--sources=<sources>] [--label-whitelist=<pattern>]
|
||||
[--oneshot | --sleep-interval=<seconds>] [--config=<path>]
|
||||
|
@ -253,8 +251,9 @@ nfd-worker.
|
|||
--server-name-override=<name> Name (CN) expect from server certificate, useful
|
||||
in testing
|
||||
[Default: ]
|
||||
--sources=<sources> Comma separated list of feature sources.
|
||||
[Default: cpu,custom,iommu,kernel,local,memory,network,pci,storage,system,usb]
|
||||
--sources=<sources> Comma separated list of feature sources. Special
|
||||
value 'all' enables all feature sources.
|
||||
[Default: all]
|
||||
--no-publish Do not publish discovered features to the
|
||||
cluster-local Kubernetes API server.
|
||||
--label-whitelist=<pattern> Regular expression to filter label names to
|
||||
|
@ -266,6 +265,7 @@ nfd-worker.
|
|||
--sleep-interval=<seconds> Time to sleep between re-labeling. Non-positive
|
||||
value implies no re-labeling (i.e. infinite
|
||||
sleep). [Default: 60s]
|
||||
|
||||
```
|
||||
|
||||
**NOTE** Some feature sources need certain directories and/or files from the
|
||||
|
|
|
@ -139,9 +139,9 @@ nfd-worker --server-name-override=localhost
|
|||
### --sources
|
||||
|
||||
The `--sources` flag specifies a comma-separated list of enabled feature
|
||||
sources.
|
||||
sources. A special value `all` enables all feature sources.
|
||||
|
||||
Default: cpu,custom,iommu,kernel,local,memory,network,pci,storage,system,usb
|
||||
Default: all
|
||||
|
||||
Example:
|
||||
|
||||
|
|
|
@ -124,12 +124,10 @@ func NewNfdWorker(args Args) (NfdWorker, error) {
|
|||
// Figure out active sources
|
||||
allSources := []source.FeatureSource{
|
||||
&cpu.Source{},
|
||||
&fake.Source{},
|
||||
&iommu.Source{},
|
||||
&kernel.Source{},
|
||||
&memory.Source{},
|
||||
&network.Source{},
|
||||
&panicfake.Source{},
|
||||
&pci.Source{},
|
||||
&storage.Source{},
|
||||
&system.Source{},
|
||||
|
@ -140,15 +138,33 @@ func NewNfdWorker(args Args) (NfdWorker, error) {
|
|||
&local.Source{},
|
||||
}
|
||||
|
||||
sourceWhiteList := map[string]struct{}{}
|
||||
for _, s := range args.Sources {
|
||||
sourceWhiteList[strings.TrimSpace(s)] = struct{}{}
|
||||
}
|
||||
// Determine enabled feature
|
||||
if len(args.Sources) == 1 && args.Sources[0] == "all" {
|
||||
nfd.sources = allSources
|
||||
} else {
|
||||
// Add fake source which is only meant for testing. It will be enabled
|
||||
// only if listed explicitly.
|
||||
allSources = append(allSources, &fake.Source{})
|
||||
allSources = append(allSources, &panicfake.Source{})
|
||||
|
||||
nfd.sources = []source.FeatureSource{}
|
||||
for _, s := range allSources {
|
||||
if _, enabled := sourceWhiteList[s.Name()]; enabled {
|
||||
nfd.sources = append(nfd.sources, s)
|
||||
sourceWhiteList := map[string]struct{}{}
|
||||
for _, s := range args.Sources {
|
||||
sourceWhiteList[strings.TrimSpace(s)] = struct{}{}
|
||||
}
|
||||
|
||||
nfd.sources = []source.FeatureSource{}
|
||||
for _, s := range allSources {
|
||||
if _, enabled := sourceWhiteList[s.Name()]; enabled {
|
||||
nfd.sources = append(nfd.sources, s)
|
||||
delete(sourceWhiteList, s.Name())
|
||||
}
|
||||
}
|
||||
if len(sourceWhiteList) > 0 {
|
||||
names := make([]string, 0, len(sourceWhiteList))
|
||||
for n := range sourceWhiteList {
|
||||
names = append(names, n)
|
||||
}
|
||||
stderrLogger.Printf("WARNING: skipping unknown source(s) %q specified in --sources", strings.Join(names, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue