1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-05 08:17:04 +00:00

nfd-worker: rename config option 'sources' to 'labelSources'

The goal is to make the name more descriptive. Also keeping in mind a
possible future addition a 'featureSources' option (or similar) for
controlling the feature discovery.
This commit is contained in:
Markus Lehtonen 2021-11-25 10:58:08 +02:00
parent 5ae7b8bb7a
commit ad9c7dfa1e
7 changed files with 26 additions and 26 deletions

View file

@ -88,7 +88,7 @@ func parseArgs(flags *flag.FlagSet, osArgs ...string) *worker.Args {
args.Overrides.SleepInterval = overrides.SleepInterval
case "sources":
klog.Warningf("-sources is deprecated, use 'core.sources' option in the config file, instead")
args.Overrides.Sources = overrides.Sources
args.Overrides.LabelSources = overrides.LabelSources
}
})
@ -121,7 +121,7 @@ func initFlags(flagset *flag.FlagSet) (*worker.Args, *worker.ConfigOverrideArgs)
// Flags overlapping with config file options
overrides := &worker.ConfigOverrideArgs{
LabelWhiteList: &utils.RegexpVal{},
Sources: &utils.StringSliceVal{},
LabelSources: &utils.StringSliceVal{},
}
overrides.NoPublish = flagset.Bool("no-publish", false,
"Do not publish discovered features, disable connection to nfd-master.")
@ -132,7 +132,7 @@ func initFlags(flagset *flag.FlagSet) (*worker.Args, *worker.ConfigOverrideArgs)
overrides.SleepInterval = flagset.Duration("sleep-interval", 0,
"Time to sleep between re-labeling. Non-positive value implies no re-labeling (i.e. infinite sleep). "+
"DEPRECATED: This parameter should be set via the config file")
flagset.Var(overrides.Sources, "sources",
flagset.Var(overrides.LabelSources, "sources",
"Comma separated list of feature sources. Special value 'all' enables all feature sources. "+
"DEPRECATED: This parameter should be set via the config file")

View file

@ -38,7 +38,7 @@ func TestParseArgs(t *testing.T) {
So(args.Overrides.NoPublish, ShouldBeNil)
So(args.Overrides.LabelWhiteList, ShouldBeNil)
So(args.Overrides.SleepInterval, ShouldBeNil)
So(args.Overrides.Sources, ShouldBeNil)
So(args.Overrides.LabelSources, ShouldBeNil)
})
})
@ -53,7 +53,7 @@ func TestParseArgs(t *testing.T) {
So(args.Oneshot, ShouldBeFalse)
So(*args.Overrides.NoPublish, ShouldBeTrue)
So(*args.Overrides.SleepInterval, ShouldEqual, 30*time.Second)
So(*args.Overrides.Sources, ShouldResemble, utils.StringSliceVal{"fake1", "fake2", "fake3"})
So(*args.Overrides.LabelSources, ShouldResemble, utils.StringSliceVal{"fake1", "fake2", "fake3"})
So(args.Overrides.LabelWhiteList.Regexp.String(), ShouldResemble, ".*rdt.*")
})
})

View file

@ -2,7 +2,7 @@
# labelWhiteList:
# noPublish: false
# sleepInterval: 60s
# sources: [all]
# labelSources: [all]
# klog:
# addDirHeader: false
# alsologtostderr: false

View file

@ -91,7 +91,7 @@ worker:
# labelWhiteList:
# noPublish: false
# sleepInterval: 60s
# sources: [all]
# labelSources: [all]
# klog:
# addDirHeader: false
# alsologtostderr: false

View file

@ -100,22 +100,22 @@ func TestConfigParse(t *testing.T) {
w, err := NewNfdWorker(&Args{})
So(err, ShouldBeNil)
worker := w.(*nfdWorker)
overrides := `{"core": {"sources": ["fake"],"noPublish": true},"sources": {"cpu": {"cpuid": {"attributeBlacklist": ["foo","bar"]}}}}`
overrides := `{"core": {"labelSources": ["fake"],"noPublish": true},"sources": {"cpu": {"cpuid": {"attributeBlacklist": ["foo","bar"]}}}}`
Convey("and no core cmdline flags have been specified", func() {
So(worker.configure("non-existing-file", overrides), ShouldBeNil)
Convey("core overrides should be in effect", func() {
So(worker.config.Core.Sources, ShouldResemble, []string{"fake"})
So(worker.config.Core.LabelSources, ShouldResemble, []string{"fake"})
So(worker.config.Core.NoPublish, ShouldBeTrue)
})
})
Convey("and a non-accessible file, but core cmdline flags and some overrides are specified", func() {
worker.args = Args{Overrides: ConfigOverrideArgs{Sources: &utils.StringSliceVal{"cpu", "kernel", "pci"}}}
worker.args = Args{Overrides: ConfigOverrideArgs{LabelSources: &utils.StringSliceVal{"cpu", "kernel", "pci"}}}
So(worker.configure("non-existing-file", overrides), ShouldBeNil)
Convey("core cmdline flags should be in effect instead overrides", func() {
So(worker.config.Core.Sources, ShouldResemble, []string{"cpu", "kernel", "pci"})
So(worker.config.Core.LabelSources, ShouldResemble, []string{"cpu", "kernel", "pci"})
})
Convey("overrides should take effect", func() {
So(worker.config.Core.NoPublish, ShouldBeTrue)
@ -145,13 +145,13 @@ sources:
So(err, ShouldBeNil)
Convey("and a proper config file is specified", func() {
worker.args = Args{Overrides: ConfigOverrideArgs{Sources: &utils.StringSliceVal{"cpu", "kernel", "pci"}}}
worker.args = Args{Overrides: ConfigOverrideArgs{LabelSources: &utils.StringSliceVal{"cpu", "kernel", "pci"}}}
So(worker.configure(f.Name(), ""), ShouldBeNil)
Convey("specified configuration should take effect", func() {
// Verify core config
So(worker.config.Core.NoPublish, ShouldBeFalse)
So(worker.config.Core.Sources, ShouldResemble, []string{"cpu", "kernel", "pci"}) // from cmdline
So(worker.config.Core.LabelSources, ShouldResemble, []string{"cpu", "kernel", "pci"}) // from cmdline
So(worker.config.Core.LabelWhiteList.String(), ShouldEqual, "foo")
So(worker.config.Core.SleepInterval.Duration, ShouldEqual, 10*time.Second)
@ -167,13 +167,13 @@ sources:
Convey("and a proper config file and overrides are given", func() {
sleepIntervalArg := 15 * time.Second
worker.args = Args{Overrides: ConfigOverrideArgs{SleepInterval: &sleepIntervalArg}}
overrides := `{"core": {"sources": ["fake"],"noPublish": true},"sources": {"pci": {"deviceClassWhitelist": ["03"]}}}`
overrides := `{"core": {"labelSources": ["fake"],"noPublish": true},"sources": {"pci": {"deviceClassWhitelist": ["03"]}}}`
So(worker.configure(f.Name(), overrides), ShouldBeNil)
Convey("overrides should take precedence over the config file", func() {
// Verify core config
So(worker.config.Core.NoPublish, ShouldBeTrue)
So(worker.config.Core.Sources, ShouldResemble, []string{"fake"}) // from overrides
So(worker.config.Core.LabelSources, ShouldResemble, []string{"fake"}) // from overrides
So(worker.config.Core.LabelWhiteList.String(), ShouldEqual, "foo")
So(worker.config.Core.SleepInterval.Duration, ShouldEqual, 15*time.Second) // from cmdline
@ -220,8 +220,8 @@ core:
w, err := NewNfdWorker(&Args{
ConfigFile: configFile,
Overrides: ConfigOverrideArgs{
Sources: &utils.StringSliceVal{"fake"},
NoPublish: &noPublish},
LabelSources: &utils.StringSliceVal{"fake"},
NoPublish: &noPublish},
})
So(err, ShouldBeNil)
worker := w.(*nfdWorker)
@ -314,7 +314,7 @@ func TestNewNfdWorker(t *testing.T) {
})
Convey("with non-empty Sources arg specified", func() {
args := &Args{Overrides: ConfigOverrideArgs{Sources: &utils.StringSliceVal{"fake"}}}
args := &Args{Overrides: ConfigOverrideArgs{LabelSources: &utils.StringSliceVal{"fake"}}}
w, err := NewNfdWorker(args)
Convey("no error should be returned", func() {
So(err, ShouldBeNil)

View file

@ -64,7 +64,7 @@ type coreConfig struct {
Klog map[string]string
LabelWhiteList utils.RegexpVal
NoPublish bool
Sources []string
LabelSources []string
SleepInterval duration
}
@ -92,7 +92,7 @@ type ConfigOverrideArgs struct {
// Deprecated
LabelWhiteList *utils.RegexpVal
SleepInterval *time.Duration
Sources *utils.StringSliceVal
LabelSources *utils.StringSliceVal
}
type nfdWorker struct {
@ -138,7 +138,7 @@ func newDefaultConfig() *NFDConfig {
Core: coreConfig{
LabelWhiteList: utils.RegexpVal{Regexp: *regexp.MustCompile("")},
SleepInterval: duration{60 * time.Second},
Sources: []string{"all"},
LabelSources: []string{"all"},
Klog: make(map[string]string),
},
}
@ -294,7 +294,7 @@ func (w *nfdWorker) configureCore(c coreConfig) error {
// Determine enabled feature sources
enabled := make(map[string]source.LabelSource)
for _, name := range c.Sources {
for _, name := range c.LabelSources {
if name == "all" {
for n, s := range source.GetAllLabelSources() {
if ts, ok := s.(source.TestSource); !ok || !ts.IsTestSource() {
@ -376,8 +376,8 @@ func (w *nfdWorker) configure(filepath string, overrides string) error {
if w.args.Overrides.SleepInterval != nil {
c.Core.SleepInterval = duration{*w.args.Overrides.SleepInterval}
}
if w.args.Overrides.Sources != nil {
c.Core.Sources = *w.args.Overrides.Sources
if w.args.Overrides.LabelSources != nil {
c.Core.LabelSources = *w.args.Overrides.LabelSources
}
c.Core.sanitize()

View file

@ -97,7 +97,7 @@ func TestRun(t *testing.T) {
Args: nfdclient.Args{
Server: "localhost:8192"},
Oneshot: true,
Overrides: worker.ConfigOverrideArgs{Sources: &utils.StringSliceVal{"fake"}},
Overrides: worker.ConfigOverrideArgs{LabelSources: &utils.StringSliceVal{"fake"}},
}
fooasdf, _ := worker.NewNfdWorker(args)
err := fooasdf.Run()
@ -128,7 +128,7 @@ func TestRunTls(t *testing.T) {
ServerNameOverride: "nfd-test-master",
},
Oneshot: true,
Overrides: worker.ConfigOverrideArgs{Sources: &utils.StringSliceVal{"fake"}},
Overrides: worker.ConfigOverrideArgs{LabelSources: &utils.StringSliceVal{"fake"}},
}
w, _ := worker.NewNfdWorker(&workerArgs)
err := w.Run()