mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-14 20:56:42 +00:00
source: rename FeatureSource to LabelSource
Prepare for separating feature detection from label creation.
This commit is contained in:
parent
795a7e543e
commit
befa7e9796
17 changed files with 124 additions and 123 deletions
2
Makefile
2
Makefile
|
@ -99,7 +99,7 @@ templates:
|
||||||
@rm nfd-worker.conf.tmp
|
@rm nfd-worker.conf.tmp
|
||||||
|
|
||||||
mock:
|
mock:
|
||||||
mockery --name=FeatureSource --dir=source --inpkg --note="Re-generate by running 'make mock'"
|
mockery --name=LabelSource --dir=source --inpkg --note="Re-generate by running 'make mock'"
|
||||||
mockery --name=APIHelpers --dir=pkg/apihelper --inpkg --note="Re-generate by running 'make mock'"
|
mockery --name=APIHelpers --dir=pkg/apihelper --inpkg --note="Re-generate by running 'make mock'"
|
||||||
mockery --name=LabelerClient --dir=pkg/labeler --inpkg --note="Re-generate by running 'make mock'"
|
mockery --name=LabelerClient --dir=pkg/labeler --inpkg --note="Re-generate by running 'make mock'"
|
||||||
|
|
||||||
|
|
|
@ -38,26 +38,26 @@ import (
|
||||||
"sigs.k8s.io/node-feature-discovery/source/pci"
|
"sigs.k8s.io/node-feature-discovery/source/pci"
|
||||||
)
|
)
|
||||||
|
|
||||||
const fakeFeatureSourceName string = "testSource"
|
const fakeLabelSourceName string = "testSource"
|
||||||
|
|
||||||
func TestDiscoveryWithMockSources(t *testing.T) {
|
func TestDiscoveryWithMockSources(t *testing.T) {
|
||||||
Convey("When I discover features from fake source and update the node using fake client", t, func() {
|
Convey("When I discover features from fake source and update the node using fake client", t, func() {
|
||||||
mockFeatureSource := new(source.MockFeatureSource)
|
mockLabelSource := new(source.MockLabelSource)
|
||||||
allFeatureNames := []string{"testfeature1", "testfeature2", "test.ns/test", "test.ns/foo", "/no-ns-label", "invalid/test/feature"}
|
allFeatureNames := []string{"testfeature1", "testfeature2", "test.ns/test", "test.ns/foo", "/no-ns-label", "invalid/test/feature"}
|
||||||
whiteListFeatureNames := []string{"testfeature1", "testfeature2", "test.ns/test"}
|
whiteListFeatureNames := []string{"testfeature1", "testfeature2", "test.ns/test"}
|
||||||
|
|
||||||
fakeFeatures, _ := makeFakeFeatures(allFeatureNames)
|
fakeFeatures, _ := makeFakeFeatures(allFeatureNames)
|
||||||
_, fakeFeatureLabels := makeFakeFeatures(whiteListFeatureNames)
|
_, fakeFeatureLabels := makeFakeFeatures(whiteListFeatureNames)
|
||||||
|
|
||||||
fakeFeatureSource := source.FeatureSource(mockFeatureSource)
|
fakeLabelSource := source.LabelSource(mockLabelSource)
|
||||||
|
|
||||||
labelWhiteList := utils.RegexpVal{Regexp: *regexp.MustCompile("^test")}
|
labelWhiteList := utils.RegexpVal{Regexp: *regexp.MustCompile("^test")}
|
||||||
|
|
||||||
Convey("When I successfully get the labels from the mock source", func() {
|
Convey("When I successfully get the labels from the mock source", func() {
|
||||||
mockFeatureSource.On("Name").Return(fakeFeatureSourceName)
|
mockLabelSource.On("Name").Return(fakeLabelSourceName)
|
||||||
mockFeatureSource.On("Discover").Return(fakeFeatures, nil)
|
mockLabelSource.On("Discover").Return(fakeFeatures, nil)
|
||||||
|
|
||||||
returnedLabels, err := getFeatureLabels(fakeFeatureSource, labelWhiteList.Regexp)
|
returnedLabels, err := getFeatureLabels(fakeLabelSource, labelWhiteList.Regexp)
|
||||||
Convey("Proper label is returned", func() {
|
Convey("Proper label is returned", func() {
|
||||||
So(returnedLabels, ShouldResemble, fakeFeatureLabels)
|
So(returnedLabels, ShouldResemble, fakeFeatureLabels)
|
||||||
})
|
})
|
||||||
|
@ -68,9 +68,9 @@ func TestDiscoveryWithMockSources(t *testing.T) {
|
||||||
|
|
||||||
Convey("When I fail to get the labels from the mock source", func() {
|
Convey("When I fail to get the labels from the mock source", func() {
|
||||||
expectedError := errors.New("fake error")
|
expectedError := errors.New("fake error")
|
||||||
mockFeatureSource.On("Discover").Return(nil, expectedError)
|
mockLabelSource.On("Discover").Return(nil, expectedError)
|
||||||
|
|
||||||
returnedLabels, err := getFeatureLabels(fakeFeatureSource, labelWhiteList.Regexp)
|
returnedLabels, err := getFeatureLabels(fakeLabelSource, labelWhiteList.Regexp)
|
||||||
Convey("No label is returned", func() {
|
Convey("No label is returned", func() {
|
||||||
So(returnedLabels, ShouldBeNil)
|
So(returnedLabels, ShouldBeNil)
|
||||||
})
|
})
|
||||||
|
@ -81,12 +81,12 @@ func TestDiscoveryWithMockSources(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeFakeFeatures(names []string) (source.Features, Labels) {
|
func makeFakeFeatures(names []string) (source.FeatureLabels, Labels) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
labels := Labels{}
|
labels := Labels{}
|
||||||
for _, f := range names {
|
for _, f := range names {
|
||||||
features[f] = true
|
features[f] = true
|
||||||
labelName := fakeFeatureSourceName + "-" + f
|
labelName := fakeLabelSourceName + "-" + f
|
||||||
if strings.IndexByte(f, '/') >= 0 {
|
if strings.IndexByte(f, '/') >= 0 {
|
||||||
labelName = f
|
labelName = f
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ func makeFakeFeatures(names []string) (source.Features, Labels) {
|
||||||
return features, labels
|
return features, labels
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *nfdWorker) getSource(name string) source.FeatureSource {
|
func (w *nfdWorker) getSource(name string) source.LabelSource {
|
||||||
for _, s := range w.realSources {
|
for _, s := range w.realSources {
|
||||||
if s.Name() == name {
|
if s.Name() == name {
|
||||||
return s
|
return s
|
||||||
|
@ -356,9 +356,9 @@ func TestNewNfdWorker(t *testing.T) {
|
||||||
|
|
||||||
func TestCreateFeatureLabels(t *testing.T) {
|
func TestCreateFeatureLabels(t *testing.T) {
|
||||||
Convey("When creating feature labels from the configured sources", t, func() {
|
Convey("When creating feature labels from the configured sources", t, func() {
|
||||||
fakeFeatureSource := source.FeatureSource(new(fake.Source))
|
fakeLabelSource := source.LabelSource(new(fake.Source))
|
||||||
fakeFeatureSource.SetConfig(fakeFeatureSource.NewConfig())
|
fakeLabelSource.SetConfig(fakeLabelSource.NewConfig())
|
||||||
sources := []source.FeatureSource{fakeFeatureSource}
|
sources := []source.LabelSource{fakeLabelSource}
|
||||||
|
|
||||||
Convey("When fake feature source is configured", func() {
|
Convey("When fake feature source is configured", func() {
|
||||||
emptyLabelWL := regexp.MustCompile("")
|
emptyLabelWL := regexp.MustCompile("")
|
||||||
|
|
|
@ -99,10 +99,10 @@ type nfdWorker struct {
|
||||||
client pb.LabelerClient
|
client pb.LabelerClient
|
||||||
configFilePath string
|
configFilePath string
|
||||||
config *NFDConfig
|
config *NFDConfig
|
||||||
realSources []source.FeatureSource
|
realSources []source.LabelSource
|
||||||
stop chan struct{} // channel for signaling stop
|
stop chan struct{} // channel for signaling stop
|
||||||
testSources []source.FeatureSource
|
testSources []source.LabelSource
|
||||||
enabledSources []source.FeatureSource
|
enabledSources []source.LabelSource
|
||||||
}
|
}
|
||||||
|
|
||||||
type duration struct {
|
type duration struct {
|
||||||
|
@ -121,7 +121,7 @@ func NewNfdWorker(args *Args) (nfdclient.NfdClient, error) {
|
||||||
|
|
||||||
args: *args,
|
args: *args,
|
||||||
config: &NFDConfig{},
|
config: &NFDConfig{},
|
||||||
realSources: []source.FeatureSource{
|
realSources: []source.LabelSource{
|
||||||
&cpu.Source{},
|
&cpu.Source{},
|
||||||
&iommu.Source{},
|
&iommu.Source{},
|
||||||
&kernel.Source{},
|
&kernel.Source{},
|
||||||
|
@ -136,7 +136,7 @@ func NewNfdWorker(args *Args) (nfdclient.NfdClient, error) {
|
||||||
// labels from other sources
|
// labels from other sources
|
||||||
&local.Source{},
|
&local.Source{},
|
||||||
},
|
},
|
||||||
testSources: []source.FeatureSource{
|
testSources: []source.LabelSource{
|
||||||
&fake.Source{},
|
&fake.Source{},
|
||||||
},
|
},
|
||||||
stop: make(chan struct{}, 1),
|
stop: make(chan struct{}, 1),
|
||||||
|
@ -311,7 +311,7 @@ func (w *nfdWorker) configureCore(c coreConfig) error {
|
||||||
sourceList[strings.TrimSpace(s)] = struct{}{}
|
sourceList[strings.TrimSpace(s)] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.enabledSources = []source.FeatureSource{}
|
w.enabledSources = []source.LabelSource{}
|
||||||
for _, s := range w.realSources {
|
for _, s := range w.realSources {
|
||||||
if _, enabled := sourceList[s.Name()]; all || enabled {
|
if _, enabled := sourceList[s.Name()]; all || enabled {
|
||||||
w.enabledSources = append(w.enabledSources, s)
|
w.enabledSources = append(w.enabledSources, s)
|
||||||
|
@ -400,7 +400,7 @@ func (w *nfdWorker) configure(filepath string, overrides string) error {
|
||||||
|
|
||||||
// createFeatureLabels returns the set of feature labels from the enabled
|
// createFeatureLabels returns the set of feature labels from the enabled
|
||||||
// sources and the whitelist argument.
|
// sources and the whitelist argument.
|
||||||
func createFeatureLabels(sources []source.FeatureSource, labelWhiteList regexp.Regexp) (labels Labels) {
|
func createFeatureLabels(sources []source.LabelSource, labelWhiteList regexp.Regexp) (labels Labels) {
|
||||||
labels = Labels{}
|
labels = Labels{}
|
||||||
|
|
||||||
// Do feature discovery from all configured sources.
|
// Do feature discovery from all configured sources.
|
||||||
|
@ -423,7 +423,7 @@ func createFeatureLabels(sources []source.FeatureSource, labelWhiteList regexp.R
|
||||||
|
|
||||||
// getFeatureLabels returns node labels for features discovered by the
|
// getFeatureLabels returns node labels for features discovered by the
|
||||||
// supplied source.
|
// supplied source.
|
||||||
func getFeatureLabels(source source.FeatureSource, labelWhiteList regexp.Regexp) (labels Labels, err error) {
|
func getFeatureLabels(source source.LabelSource, labelWhiteList regexp.Regexp) (labels Labels, err error) {
|
||||||
labels = Labels{}
|
labels = Labels{}
|
||||||
features, err := source.Discover()
|
features, err := source.Discover()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -78,7 +78,7 @@ type keyFilter struct {
|
||||||
whitelist bool
|
whitelist bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement FeatureSource interface
|
// Source implements LabelSource.
|
||||||
type Source struct {
|
type Source struct {
|
||||||
config *Config
|
config *Config
|
||||||
cpuidFilter *keyFilter
|
cpuidFilter *keyFilter
|
||||||
|
@ -86,13 +86,13 @@ type Source struct {
|
||||||
|
|
||||||
func (s Source) Name() string { return Name }
|
func (s Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return s.config }
|
func (s *Source) GetConfig() source.Config { return s.config }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(conf source.Config) {
|
func (s *Source) SetConfig(conf source.Config) {
|
||||||
switch v := conf.(type) {
|
switch v := conf.(type) {
|
||||||
case *Config:
|
case *Config:
|
||||||
|
@ -103,8 +103,8 @@ func (s *Source) SetConfig(conf source.Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) Discover() (source.Features, error) {
|
func (s *Source) Discover() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
// Check if hyper-threading seems to be enabled
|
// Check if hyper-threading seems to be enabled
|
||||||
found, err := haveThreadSiblings()
|
found, err := haveThreadSiblings()
|
||||||
|
|
|
@ -51,7 +51,7 @@ func newDefaultConfig() *config {
|
||||||
return &config{}
|
return &config{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source implements FeatureSource Interface
|
// Source implements LabelSource.
|
||||||
type Source struct {
|
type Source struct {
|
||||||
config *config
|
config *config
|
||||||
}
|
}
|
||||||
|
@ -59,13 +59,13 @@ type Source struct {
|
||||||
// Name returns the name of the feature source
|
// Name returns the name of the feature source
|
||||||
func (s Source) Name() string { return Name }
|
func (s Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return s.config }
|
func (s *Source) GetConfig() source.Config { return s.config }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(conf source.Config) {
|
func (s *Source) SetConfig(conf source.Config) {
|
||||||
switch v := conf.(type) {
|
switch v := conf.(type) {
|
||||||
case *config:
|
case *config:
|
||||||
|
@ -76,8 +76,8 @@ func (s *Source) SetConfig(conf source.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discover features
|
// Discover features
|
||||||
func (s Source) Discover() (source.Features, error) {
|
func (s Source) Discover() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
allFeatureConfig := append(getStaticFeatureConfig(), *s.config...)
|
allFeatureConfig := append(getStaticFeatureConfig(), *s.config...)
|
||||||
allFeatureConfig = append(allFeatureConfig, getDirectoryFeatureConfig()...)
|
allFeatureConfig = append(allFeatureConfig, getDirectoryFeatureConfig()...)
|
||||||
utils.KlogDump(2, "custom features configuration:", " ", allFeatureConfig)
|
utils.KlogDump(2, "custom features configuration:", " ", allFeatureConfig)
|
||||||
|
|
|
@ -40,7 +40,7 @@ func newDefaultConfig() *Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source implements FeatureSource.
|
// Source implements LabelSource.
|
||||||
type Source struct {
|
type Source struct {
|
||||||
config *Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
@ -48,13 +48,13 @@ type Source struct {
|
||||||
// Name returns an identifier string for this feature source.
|
// Name returns an identifier string for this feature source.
|
||||||
func (s Source) Name() string { return Name }
|
func (s Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return s.config }
|
func (s *Source) GetConfig() source.Config { return s.config }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(conf source.Config) {
|
func (s *Source) SetConfig(conf source.Config) {
|
||||||
switch v := conf.(type) {
|
switch v := conf.(type) {
|
||||||
case *Config:
|
case *Config:
|
||||||
|
@ -64,13 +64,13 @@ func (s *Source) SetConfig(conf source.Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure method of the FeatureSource interface
|
// Configure method of the LabelSource interface
|
||||||
func (s Source) Configure([]byte) error { return nil }
|
func (s Source) Configure([]byte) error { return nil }
|
||||||
|
|
||||||
// Discover returns feature names for some fake features.
|
// Discover returns feature names for some fake features.
|
||||||
func (s Source) Discover() (source.Features, error) {
|
func (s Source) Discover() (source.FeatureLabels, error) {
|
||||||
// Adding three fake features.
|
// Adding three fake features.
|
||||||
features := make(source.Features, len(s.config.Labels))
|
features := make(source.FeatureLabels, len(s.config.Labels))
|
||||||
for k, v := range s.config.Labels {
|
for k, v := range s.config.Labels {
|
||||||
features[k] = v
|
features[k] = v
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,23 +25,22 @@ import (
|
||||||
|
|
||||||
const Name = "iommu"
|
const Name = "iommu"
|
||||||
|
|
||||||
// Implement FeatureSource interface
|
// Source implements LabelSource.
|
||||||
// Source implements FeatureSource interface
|
|
||||||
type Source struct{}
|
type Source struct{}
|
||||||
|
|
||||||
func (s Source) Name() string { return Name }
|
func (s Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return nil }
|
func (s *Source) NewConfig() source.Config { return nil }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return nil }
|
func (s *Source) GetConfig() source.Config { return nil }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(source.Config) {}
|
func (s *Source) SetConfig(source.Config) {}
|
||||||
|
|
||||||
func (s Source) Discover() (source.Features, error) {
|
func (s Source) Discover() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
// Check if any iommu devices are available
|
// Check if any iommu devices are available
|
||||||
devices, err := ioutil.ReadDir(source.SysfsDir.Path("class/iommu/"))
|
devices, err := ioutil.ReadDir(source.SysfsDir.Path("class/iommu/"))
|
||||||
|
|
|
@ -47,20 +47,20 @@ func newDefaultConfig() *Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement FeatureSource interface
|
// Source implements LabelSource.
|
||||||
type Source struct {
|
type Source struct {
|
||||||
config *Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) Name() string { return Name }
|
func (s *Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return s.config }
|
func (s *Source) GetConfig() source.Config { return s.config }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(conf source.Config) {
|
func (s *Source) SetConfig(conf source.Config) {
|
||||||
switch v := conf.(type) {
|
switch v := conf.(type) {
|
||||||
case *Config:
|
case *Config:
|
||||||
|
@ -70,8 +70,8 @@ func (s *Source) SetConfig(conf source.Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Source) Discover() (source.Features, error) {
|
func (s *Source) Discover() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
// Read kernel version
|
// Read kernel version
|
||||||
version, err := parseVersion()
|
version, err := parseVersion()
|
||||||
|
|
|
@ -38,23 +38,23 @@ var (
|
||||||
hookDir = "/etc/kubernetes/node-feature-discovery/source.d/"
|
hookDir = "/etc/kubernetes/node-feature-discovery/source.d/"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Source implements FeatureSource interface
|
// Source implements LabelSource.
|
||||||
type Source struct{}
|
type Source struct{}
|
||||||
|
|
||||||
// Name returns the name of the feature source
|
// Name method of the LabelSource interface
|
||||||
func (s Source) Name() string { return Name }
|
func (s Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return nil }
|
func (s *Source) NewConfig() source.Config { return nil }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return nil }
|
func (s *Source) GetConfig() source.Config { return nil }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(source.Config) {}
|
func (s *Source) SetConfig(source.Config) {}
|
||||||
|
|
||||||
// Discover returns features from hooks and files
|
// Discover method of the LabelSource interface
|
||||||
func (s Source) Discover() (source.Features, error) {
|
func (s Source) Discover() (source.FeatureLabels, error) {
|
||||||
featuresFromHooks, err := getFeaturesFromHooks()
|
featuresFromHooks, err := getFeaturesFromHooks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Error(err)
|
klog.Error(err)
|
||||||
|
@ -77,8 +77,8 @@ func (s Source) Discover() (source.Features, error) {
|
||||||
return featuresFromFiles, nil
|
return featuresFromFiles, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseFeatures(lines [][]byte, prefix string) source.Features {
|
func parseFeatures(lines [][]byte, prefix string) source.FeatureLabels {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
if len(line) > 0 {
|
if len(line) > 0 {
|
||||||
|
@ -109,8 +109,8 @@ func parseFeatures(lines [][]byte, prefix string) source.Features {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run all hooks and get features
|
// Run all hooks and get features
|
||||||
func getFeaturesFromHooks() (source.Features, error) {
|
func getFeaturesFromHooks() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(hookDir)
|
files, err := ioutil.ReadDir(hookDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -184,8 +184,8 @@ func runHook(file string) ([][]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read all files to get features
|
// Read all files to get features
|
||||||
func getFeaturesFromFiles() (source.Features, error) {
|
func getFeaturesFromFiles() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(featureFilesDir)
|
files, err := ioutil.ReadDir(featureFilesDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -28,24 +28,24 @@ import (
|
||||||
|
|
||||||
const Name = "memory"
|
const Name = "memory"
|
||||||
|
|
||||||
// Source implements FeatureSource.
|
// Source implements LabelSource.
|
||||||
type Source struct{}
|
type Source struct{}
|
||||||
|
|
||||||
// Name returns an identifier string for this feature source.
|
// Name returns an identifier string for this feature source.
|
||||||
func (s Source) Name() string { return Name }
|
func (s Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return nil }
|
func (s *Source) NewConfig() source.Config { return nil }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return nil }
|
func (s *Source) GetConfig() source.Config { return nil }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(source.Config) {}
|
func (s *Source) SetConfig(source.Config) {}
|
||||||
|
|
||||||
// Discover returns feature names for memory: numa if more than one memory node is present.
|
// Discover returns feature names for memory: numa if more than one memory node is present.
|
||||||
func (s Source) Discover() (source.Features, error) {
|
func (s Source) Discover() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
// Detect NUMA
|
// Detect NUMA
|
||||||
numa, err := isNuma()
|
numa, err := isNuma()
|
||||||
|
|
|
@ -6,21 +6,21 @@ package source
|
||||||
|
|
||||||
import mock "github.com/stretchr/testify/mock"
|
import mock "github.com/stretchr/testify/mock"
|
||||||
|
|
||||||
// MockFeatureSource is an autogenerated mock type for the FeatureSource type
|
// MockLabelSource is an autogenerated mock type for the LabelSource type
|
||||||
type MockFeatureSource struct {
|
type MockLabelSource struct {
|
||||||
mock.Mock
|
mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discover provides a mock function with given fields:
|
// Discover provides a mock function with given fields:
|
||||||
func (_m *MockFeatureSource) Discover() (Features, error) {
|
func (_m *MockLabelSource) Discover() (FeatureLabels, error) {
|
||||||
ret := _m.Called()
|
ret := _m.Called()
|
||||||
|
|
||||||
var r0 Features
|
var r0 FeatureLabels
|
||||||
if rf, ok := ret.Get(0).(func() Features); ok {
|
if rf, ok := ret.Get(0).(func() FeatureLabels); ok {
|
||||||
r0 = rf()
|
r0 = rf()
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(Features)
|
r0 = ret.Get(0).(FeatureLabels)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ func (_m *MockFeatureSource) Discover() (Features, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConfig provides a mock function with given fields:
|
// GetConfig provides a mock function with given fields:
|
||||||
func (_m *MockFeatureSource) GetConfig() Config {
|
func (_m *MockLabelSource) GetConfig() Config {
|
||||||
ret := _m.Called()
|
ret := _m.Called()
|
||||||
|
|
||||||
var r0 Config
|
var r0 Config
|
||||||
|
@ -51,7 +51,7 @@ func (_m *MockFeatureSource) GetConfig() Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name provides a mock function with given fields:
|
// Name provides a mock function with given fields:
|
||||||
func (_m *MockFeatureSource) Name() string {
|
func (_m *MockLabelSource) Name() string {
|
||||||
ret := _m.Called()
|
ret := _m.Called()
|
||||||
|
|
||||||
var r0 string
|
var r0 string
|
||||||
|
@ -65,7 +65,7 @@ func (_m *MockFeatureSource) Name() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfig provides a mock function with given fields:
|
// NewConfig provides a mock function with given fields:
|
||||||
func (_m *MockFeatureSource) NewConfig() Config {
|
func (_m *MockLabelSource) NewConfig() Config {
|
||||||
ret := _m.Called()
|
ret := _m.Called()
|
||||||
|
|
||||||
var r0 Config
|
var r0 Config
|
||||||
|
@ -81,6 +81,6 @@ func (_m *MockFeatureSource) NewConfig() Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetConfig provides a mock function with given fields: _a0
|
// SetConfig provides a mock function with given fields: _a0
|
||||||
func (_m *MockFeatureSource) SetConfig(_a0 Config) {
|
func (_m *MockLabelSource) SetConfig(_a0 Config) {
|
||||||
_m.Called(_a0)
|
_m.Called(_a0)
|
||||||
}
|
}
|
|
@ -41,24 +41,24 @@ const (
|
||||||
|
|
||||||
const sysfsBaseDir = "class/net"
|
const sysfsBaseDir = "class/net"
|
||||||
|
|
||||||
// Source implements FeatureSource.
|
// Source implements LabelSource.
|
||||||
type Source struct{}
|
type Source struct{}
|
||||||
|
|
||||||
// Name returns an identifier string for this feature source.
|
// Name returns an identifier string for this feature source.
|
||||||
func (s Source) Name() string { return Name }
|
func (s Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return nil }
|
func (s *Source) NewConfig() source.Config { return nil }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return nil }
|
func (s *Source) GetConfig() source.Config { return nil }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(source.Config) {}
|
func (s *Source) SetConfig(source.Config) {}
|
||||||
|
|
||||||
// Discover returns feature names sriov-configured and sriov if SR-IOV capable NICs are present and/or SR-IOV virtual functions are configured on the node
|
// Discover returns feature names sriov-configured and sriov if SR-IOV capable NICs are present and/or SR-IOV virtual functions are configured on the node
|
||||||
func (s Source) Discover() (source.Features, error) {
|
func (s Source) Discover() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
netInterfaces, err := ioutil.ReadDir(source.SysfsDir.Path(sysfsBaseDir))
|
netInterfaces, err := ioutil.ReadDir(source.SysfsDir.Path(sysfsBaseDir))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -41,7 +41,7 @@ func newDefaultConfig() *Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source implements FeatureSource interface
|
// Source implements LabelSource.
|
||||||
type Source struct {
|
type Source struct {
|
||||||
config *Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
@ -49,13 +49,13 @@ type Source struct {
|
||||||
// Name returns the name of the feature source
|
// Name returns the name of the feature source
|
||||||
func (s Source) Name() string { return Name }
|
func (s Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return s.config }
|
func (s *Source) GetConfig() source.Config { return s.config }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(conf source.Config) {
|
func (s *Source) SetConfig(conf source.Config) {
|
||||||
switch v := conf.(type) {
|
switch v := conf.(type) {
|
||||||
case *Config:
|
case *Config:
|
||||||
|
@ -66,8 +66,8 @@ func (s *Source) SetConfig(conf source.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discover features
|
// Discover features
|
||||||
func (s Source) Discover() (source.Features, error) {
|
func (s Source) Discover() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
// Construct a device label format, a sorted list of valid attributes
|
// Construct a device label format, a sorted list of valid attributes
|
||||||
deviceLabelFields := []string{}
|
deviceLabelFields := []string{}
|
||||||
|
|
|
@ -16,18 +16,19 @@ limitations under the License.
|
||||||
|
|
||||||
package source
|
package source
|
||||||
|
|
||||||
// Value of a feature
|
// FeatureLabelValue represents the value of one feature label
|
||||||
type FeatureValue interface{}
|
type FeatureLabelValue interface{}
|
||||||
|
|
||||||
type Features map[string]FeatureValue
|
// FeatureLabels is a collection of feature labels
|
||||||
|
type FeatureLabels map[string]FeatureLabelValue
|
||||||
|
|
||||||
// FeatureSource represents a source of a discovered node feature.
|
// LabelSource represents a source of node feature labels
|
||||||
type FeatureSource interface {
|
type LabelSource interface {
|
||||||
// Name returns a friendly name for this source of node feature.
|
// Name returns a friendly name for this source
|
||||||
Name() string
|
Name() string
|
||||||
|
|
||||||
// Discover returns discovered features for this node.
|
// Discover returns discovered feature labels
|
||||||
Discover() (Features, error)
|
Discover() (FeatureLabels, error)
|
||||||
|
|
||||||
// NewConfig returns a new default config of the source
|
// NewConfig returns a new default config of the source
|
||||||
NewConfig() Config
|
NewConfig() Config
|
||||||
|
@ -39,5 +40,6 @@ type FeatureSource interface {
|
||||||
SetConfig(Config)
|
SetConfig(Config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config is the generic interface for source configuration data
|
||||||
type Config interface {
|
type Config interface {
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,24 +25,24 @@ import (
|
||||||
|
|
||||||
const Name = "storage"
|
const Name = "storage"
|
||||||
|
|
||||||
// Source implements FeatureSource.
|
// Source implements LabelSource.
|
||||||
type Source struct{}
|
type Source struct{}
|
||||||
|
|
||||||
// Name returns an identifier string for this feature source.
|
// Name returns an identifier string for this feature source.
|
||||||
func (s Source) Name() string { return Name }
|
func (s Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return nil }
|
func (s *Source) NewConfig() source.Config { return nil }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return nil }
|
func (s *Source) GetConfig() source.Config { return nil }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(source.Config) {}
|
func (s *Source) SetConfig(source.Config) {}
|
||||||
|
|
||||||
// Discover returns feature names for storage: nonrotationaldisk if any SSD drive present.
|
// Discover returns feature names for storage: nonrotationaldisk if any SSD drive present.
|
||||||
func (s Source) Discover() (source.Features, error) {
|
func (s Source) Discover() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
// Check if there is any non-rotational block devices attached to the node
|
// Check if there is any non-rotational block devices attached to the node
|
||||||
blockdevices, err := ioutil.ReadDir(source.SysfsDir.Path("block"))
|
blockdevices, err := ioutil.ReadDir(source.SysfsDir.Path("block"))
|
||||||
|
|
|
@ -34,22 +34,22 @@ var osReleaseFields = [...]string{
|
||||||
|
|
||||||
const Name = "system"
|
const Name = "system"
|
||||||
|
|
||||||
// Implement FeatureSource interface
|
// Source implements LabelSource.
|
||||||
type Source struct{}
|
type Source struct{}
|
||||||
|
|
||||||
func (s Source) Name() string { return Name }
|
func (s Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return nil }
|
func (s *Source) NewConfig() source.Config { return nil }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return nil }
|
func (s *Source) GetConfig() source.Config { return nil }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(source.Config) {}
|
func (s *Source) SetConfig(source.Config) {}
|
||||||
|
|
||||||
func (s Source) Discover() (source.Features, error) {
|
func (s Source) Discover() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
release, err := parseOSRelease()
|
release, err := parseOSRelease()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -44,7 +44,7 @@ func newDefaultConfig() *Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source implements FeatureSource interface
|
// Source implements LabelSource.
|
||||||
type Source struct {
|
type Source struct {
|
||||||
config *Config
|
config *Config
|
||||||
}
|
}
|
||||||
|
@ -52,13 +52,13 @@ type Source struct {
|
||||||
// Name returns the name of the feature source
|
// Name returns the name of the feature source
|
||||||
func (s Source) Name() string { return Name }
|
func (s Source) Name() string { return Name }
|
||||||
|
|
||||||
// NewConfig method of the FeatureSource interface
|
// NewConfig method of the LabelSource interface
|
||||||
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
func (s *Source) NewConfig() source.Config { return newDefaultConfig() }
|
||||||
|
|
||||||
// GetConfig method of the FeatureSource interface
|
// GetConfig method of the LabelSource interface
|
||||||
func (s *Source) GetConfig() source.Config { return s.config }
|
func (s *Source) GetConfig() source.Config { return s.config }
|
||||||
|
|
||||||
// SetConfig method of the FeatureSource interface
|
// SetConfig method of the LabelSource interface
|
||||||
func (s *Source) SetConfig(conf source.Config) {
|
func (s *Source) SetConfig(conf source.Config) {
|
||||||
switch v := conf.(type) {
|
switch v := conf.(type) {
|
||||||
case *Config:
|
case *Config:
|
||||||
|
@ -69,8 +69,8 @@ func (s *Source) SetConfig(conf source.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Discover features
|
// Discover features
|
||||||
func (s Source) Discover() (source.Features, error) {
|
func (s Source) Discover() (source.FeatureLabels, error) {
|
||||||
features := source.Features{}
|
features := source.FeatureLabels{}
|
||||||
|
|
||||||
// Construct a device label format, a sorted list of valid attributes
|
// Construct a device label format, a sorted list of valid attributes
|
||||||
deviceLabelFields := []string{}
|
deviceLabelFields := []string{}
|
||||||
|
|
Loading…
Add table
Reference in a new issue