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 'custom' feature Source to nfd-worker

This commit is contained in:
Adrian Chiris 2020-02-16 17:43:12 +02:00
parent e4e3a9f68e
commit 192b3d7bdd
3 changed files with 9 additions and 3 deletions

View file

@ -91,7 +91,7 @@ func argsParse(argv []string) (worker.Args, error) {
in testing in testing
[Default: ] [Default: ]
--sources=<sources> Comma separated list of feature sources. --sources=<sources> Comma separated list of feature sources.
[Default: cpu,iommu,kernel,local,memory,network,pci,storage,system] [Default: cpu,custom,iommu,kernel,local,memory,network,pci,storage,system]
--no-publish Do not publish discovered features to the --no-publish Do not publish discovered features to the
cluster-local Kubernetes API server. cluster-local Kubernetes API server.
--label-whitelist=<pattern> Regular expression to filter label names to --label-whitelist=<pattern> Regular expression to filter label names to

View file

@ -23,6 +23,8 @@ import (
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
) )
var allSources = []string{"cpu", "custom", "iommu", "kernel", "local", "memory", "network", "pci", "storage", "system"}
func TestArgsParse(t *testing.T) { func TestArgsParse(t *testing.T) {
Convey("When parsing command line arguments", t, func() { Convey("When parsing command line arguments", t, func() {
Convey("When --no-publish and --oneshot flags are passed", func() { Convey("When --no-publish and --oneshot flags are passed", func() {
@ -32,7 +34,7 @@ func TestArgsParse(t *testing.T) {
So(args.SleepInterval, ShouldEqual, 60*time.Second) So(args.SleepInterval, ShouldEqual, 60*time.Second)
So(args.NoPublish, ShouldBeTrue) So(args.NoPublish, ShouldBeTrue)
So(args.Oneshot, ShouldBeTrue) So(args.Oneshot, ShouldBeTrue)
So(args.Sources, ShouldResemble, []string{"cpu", "iommu", "kernel", "local", "memory", "network", "pci", "storage", "system"}) So(args.Sources, ShouldResemble, allSources)
So(len(args.LabelWhiteList), ShouldEqual, 0) So(len(args.LabelWhiteList), ShouldEqual, 0)
So(err, ShouldBeNil) So(err, ShouldBeNil)
}) })
@ -56,7 +58,7 @@ func TestArgsParse(t *testing.T) {
Convey("args.labelWhiteList is set to appropriate value and args.sources is set to default value", func() { Convey("args.labelWhiteList is set to appropriate value and args.sources is set to default value", func() {
So(args.NoPublish, ShouldBeFalse) So(args.NoPublish, ShouldBeFalse)
So(args.Sources, ShouldResemble, []string{"cpu", "iommu", "kernel", "local", "memory", "network", "pci", "storage", "system"}) So(args.Sources, ShouldResemble, allSources)
So(args.LabelWhiteList, ShouldResemble, ".*rdt.*") So(args.LabelWhiteList, ShouldResemble, ".*rdt.*")
So(err, ShouldBeNil) So(err, ShouldBeNil)
}) })

View file

@ -36,6 +36,7 @@ import (
"sigs.k8s.io/node-feature-discovery/pkg/version" "sigs.k8s.io/node-feature-discovery/pkg/version"
"sigs.k8s.io/node-feature-discovery/source" "sigs.k8s.io/node-feature-discovery/source"
"sigs.k8s.io/node-feature-discovery/source/cpu" "sigs.k8s.io/node-feature-discovery/source/cpu"
"sigs.k8s.io/node-feature-discovery/source/custom"
"sigs.k8s.io/node-feature-discovery/source/fake" "sigs.k8s.io/node-feature-discovery/source/fake"
"sigs.k8s.io/node-feature-discovery/source/iommu" "sigs.k8s.io/node-feature-discovery/source/iommu"
"sigs.k8s.io/node-feature-discovery/source/kernel" "sigs.k8s.io/node-feature-discovery/source/kernel"
@ -61,6 +62,7 @@ type NFDConfig struct {
Cpu *cpu.NFDConfig `json:"cpu,omitempty"` Cpu *cpu.NFDConfig `json:"cpu,omitempty"`
Kernel *kernel.NFDConfig `json:"kernel,omitempty"` Kernel *kernel.NFDConfig `json:"kernel,omitempty"`
Pci *pci.NFDConfig `json:"pci,omitempty"` Pci *pci.NFDConfig `json:"pci,omitempty"`
Custom *custom.NFDConfig `json:"custom,omitempty"`
} `json:"sources,omitempty"` } `json:"sources,omitempty"`
} }
@ -234,6 +236,7 @@ func configParse(filepath string, overrides string) error {
config.Sources.Cpu = &cpu.Config config.Sources.Cpu = &cpu.Config
config.Sources.Kernel = &kernel.Config config.Sources.Kernel = &kernel.Config
config.Sources.Pci = &pci.Config config.Sources.Pci = &pci.Config
config.Sources.Custom = &custom.Config
data, err := ioutil.ReadFile(filepath) data, err := ioutil.ReadFile(filepath)
if err != nil { if err != nil {
@ -276,6 +279,7 @@ func configureParameters(sourcesWhiteList []string, labelWhiteListStr string) (e
pci.Source{}, pci.Source{},
storage.Source{}, storage.Source{},
system.Source{}, system.Source{},
custom.Source{},
// local needs to be the last source so that it is able to override // local needs to be the last source so that it is able to override
// labels from other sources // labels from other sources
local.Source{}, local.Source{},