mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-15 17:50:49 +00:00
nfd-worker: rename nfdWorker.enabledSources to labelSources
Refactoring in head of adding new config option for feature sources.
This commit is contained in:
parent
14ab512588
commit
2c3a4d1588
2 changed files with 18 additions and 18 deletions
|
@ -308,7 +308,7 @@ func TestNewNfdWorker(t *testing.T) {
|
|||
worker := w.(*nfdWorker)
|
||||
So(worker.configure("", ""), ShouldBeNil)
|
||||
Convey("all sources should be enabled and the whitelist regexp should be empty", func() {
|
||||
So(len(worker.enabledSources), ShouldEqual, len(source.GetAllLabelSources())-1)
|
||||
So(len(worker.labelSources), ShouldEqual, len(source.GetAllLabelSources())-1)
|
||||
So(worker.config.Core.LabelWhiteList, ShouldResemble, emptyRegexp)
|
||||
})
|
||||
})
|
||||
|
@ -322,8 +322,8 @@ func TestNewNfdWorker(t *testing.T) {
|
|||
worker := w.(*nfdWorker)
|
||||
So(worker.configure("", ""), ShouldBeNil)
|
||||
Convey("proper sources should be enabled", func() {
|
||||
So(len(worker.enabledSources), ShouldEqual, 1)
|
||||
So(worker.enabledSources[0].Name(), ShouldEqual, "fake")
|
||||
So(len(worker.labelSources), ShouldEqual, 1)
|
||||
So(worker.labelSources[0].Name(), ShouldEqual, "fake")
|
||||
So(worker.config.Core.LabelWhiteList, ShouldResemble, emptyRegexp)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -105,7 +105,7 @@ type nfdWorker struct {
|
|||
configFilePath string
|
||||
config *NFDConfig
|
||||
stop chan struct{} // channel for signaling stop
|
||||
enabledSources []source.LabelSource
|
||||
labelSources []source.LabelSource
|
||||
}
|
||||
|
||||
type duration struct {
|
||||
|
@ -186,7 +186,7 @@ func (w *nfdWorker) Run() error {
|
|||
}
|
||||
|
||||
// Get the set of feature labels.
|
||||
labels := createFeatureLabels(w.enabledSources, w.config.Core.LabelWhiteList.Regexp)
|
||||
labels := createFeatureLabels(w.labelSources, w.config.Core.LabelWhiteList.Regexp)
|
||||
|
||||
// Update the node with the feature labels.
|
||||
if w.client != nil {
|
||||
|
@ -293,13 +293,13 @@ func (w *nfdWorker) configureCore(c coreConfig) error {
|
|||
}
|
||||
}
|
||||
|
||||
// Determine enabled feature sources
|
||||
enabled := make(map[string]source.LabelSource)
|
||||
// Determine enabled label sources
|
||||
labelSources := make(map[string]source.LabelSource)
|
||||
for _, name := range c.LabelSources {
|
||||
if name == "all" {
|
||||
for n, s := range source.GetAllLabelSources() {
|
||||
if ts, ok := s.(source.TestSource); !ok || !ts.IsTestSource() {
|
||||
enabled[n] = s
|
||||
labelSources[n] = s
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -311,9 +311,9 @@ func (w *nfdWorker) configureCore(c coreConfig) error {
|
|||
}
|
||||
if s := source.GetLabelSource(strippedName); s != nil {
|
||||
if !disable {
|
||||
enabled[strippedName] = s
|
||||
labelSources[name] = s
|
||||
} else {
|
||||
delete(enabled, strippedName)
|
||||
delete(labelSources, strippedName)
|
||||
}
|
||||
} else {
|
||||
klog.Warningf("skipping unknown source %q specified in core.sources (or -sources)", name)
|
||||
|
@ -321,22 +321,22 @@ func (w *nfdWorker) configureCore(c coreConfig) error {
|
|||
}
|
||||
}
|
||||
|
||||
w.enabledSources = make([]source.LabelSource, 0, len(enabled))
|
||||
for _, s := range enabled {
|
||||
w.enabledSources = append(w.enabledSources, s)
|
||||
w.labelSources = make([]source.LabelSource, 0, len(labelSources))
|
||||
for _, s := range labelSources {
|
||||
w.labelSources = append(w.labelSources, s)
|
||||
}
|
||||
|
||||
sort.Slice(w.enabledSources, func(i, j int) bool {
|
||||
iP, jP := w.enabledSources[i].Priority(), w.enabledSources[j].Priority()
|
||||
sort.Slice(w.labelSources, func(i, j int) bool {
|
||||
iP, jP := w.labelSources[i].Priority(), w.labelSources[j].Priority()
|
||||
if iP != jP {
|
||||
return iP < jP
|
||||
}
|
||||
return w.enabledSources[i].Name() < w.enabledSources[j].Name()
|
||||
return w.labelSources[i].Name() < w.labelSources[j].Name()
|
||||
})
|
||||
|
||||
if klog.V(1).Enabled() {
|
||||
n := make([]string, len(w.enabledSources))
|
||||
for i, s := range w.enabledSources {
|
||||
n := make([]string, len(w.labelSources))
|
||||
for i, s := range w.labelSources {
|
||||
n[i] = s.Name()
|
||||
}
|
||||
klog.Infof("enabled label sources: %s", strings.Join(n, ", "))
|
||||
|
|
Loading…
Reference in a new issue