From 192b3d7bdd6be38d255303dadaa439a82050ed29 Mon Sep 17 00:00:00 2001 From: Adrian Chiris Date: Sun, 16 Feb 2020 17:43:12 +0200 Subject: [PATCH] Add 'custom' feature Source to nfd-worker --- cmd/nfd-worker/main.go | 2 +- cmd/nfd-worker/main_test.go | 6 ++++-- pkg/nfd-worker/nfd-worker.go | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/nfd-worker/main.go b/cmd/nfd-worker/main.go index b11b2f4c9..48a8ac3a7 100644 --- a/cmd/nfd-worker/main.go +++ b/cmd/nfd-worker/main.go @@ -91,7 +91,7 @@ func argsParse(argv []string) (worker.Args, error) { in testing [Default: ] --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 cluster-local Kubernetes API server. --label-whitelist= Regular expression to filter label names to diff --git a/cmd/nfd-worker/main_test.go b/cmd/nfd-worker/main_test.go index 05824fa8d..90b51727c 100644 --- a/cmd/nfd-worker/main_test.go +++ b/cmd/nfd-worker/main_test.go @@ -23,6 +23,8 @@ import ( . "github.com/smartystreets/goconvey/convey" ) +var allSources = []string{"cpu", "custom", "iommu", "kernel", "local", "memory", "network", "pci", "storage", "system"} + func TestArgsParse(t *testing.T) { Convey("When parsing command line arguments", t, 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.NoPublish, 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(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() { 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(err, ShouldBeNil) }) diff --git a/pkg/nfd-worker/nfd-worker.go b/pkg/nfd-worker/nfd-worker.go index e46e1421e..a353f8585 100644 --- a/pkg/nfd-worker/nfd-worker.go +++ b/pkg/nfd-worker/nfd-worker.go @@ -36,6 +36,7 @@ import ( "sigs.k8s.io/node-feature-discovery/pkg/version" "sigs.k8s.io/node-feature-discovery/source" "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/iommu" "sigs.k8s.io/node-feature-discovery/source/kernel" @@ -61,6 +62,7 @@ type NFDConfig struct { Cpu *cpu.NFDConfig `json:"cpu,omitempty"` Kernel *kernel.NFDConfig `json:"kernel,omitempty"` Pci *pci.NFDConfig `json:"pci,omitempty"` + Custom *custom.NFDConfig `json:"custom,omitempty"` } `json:"sources,omitempty"` } @@ -234,6 +236,7 @@ func configParse(filepath string, overrides string) error { config.Sources.Cpu = &cpu.Config config.Sources.Kernel = &kernel.Config config.Sources.Pci = &pci.Config + config.Sources.Custom = &custom.Config data, err := ioutil.ReadFile(filepath) if err != nil { @@ -276,6 +279,7 @@ func configureParameters(sourcesWhiteList []string, labelWhiteListStr string) (e pci.Source{}, storage.Source{}, system.Source{}, + custom.Source{}, // local needs to be the last source so that it is able to override // labels from other sources local.Source{},