1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

source: define source names as consts

Paves the way for future work on more general representation of
feature data and looser coupling of the data and feature source
interface.
This commit is contained in:
Markus Lehtonen 2021-05-12 16:27:29 +03:00
parent aa2cbad3a9
commit 610b1c696c
12 changed files with 36 additions and 12 deletions

View file

@ -25,6 +25,8 @@ import (
"sigs.k8s.io/node-feature-discovery/source/internal/cpuidutils" "sigs.k8s.io/node-feature-discovery/source/internal/cpuidutils"
) )
const Name = "cpu"
// Configuration file options // Configuration file options
type cpuidConfig struct { type cpuidConfig struct {
AttributeBlacklist []string `json:"attributeBlacklist,omitempty"` AttributeBlacklist []string `json:"attributeBlacklist,omitempty"`
@ -82,7 +84,7 @@ type Source struct {
cpuidFilter *keyFilter cpuidFilter *keyFilter
} }
func (s Source) Name() string { return "cpu" } func (s Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return newDefaultConfig() } func (s *Source) NewConfig() source.Config { return newDefaultConfig() }

View file

@ -26,6 +26,8 @@ import (
"sigs.k8s.io/node-feature-discovery/source/custom/rules" "sigs.k8s.io/node-feature-discovery/source/custom/rules"
) )
const Name = "custom"
// Custom Features Configurations // Custom Features Configurations
type MatchRule struct { type MatchRule struct {
PciID *rules.PciIDRule `json:"pciId,omitempty"` PciID *rules.PciIDRule `json:"pciId,omitempty"`
@ -55,7 +57,7 @@ type Source struct {
} }
// Return name of the feature source // Return name of the feature source
func (s Source) Name() string { return "custom" } func (s Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return newDefaultConfig() } func (s *Source) NewConfig() source.Config { return newDefaultConfig() }

View file

@ -22,6 +22,8 @@ import (
"sigs.k8s.io/node-feature-discovery/source" "sigs.k8s.io/node-feature-discovery/source"
) )
const Name = "fake"
// Configuration file options // Configuration file options
type Config struct { type Config struct {
Labels map[string]string `json:"labels"` Labels map[string]string `json:"labels"`
@ -44,7 +46,7 @@ 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 "fake" } func (s Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return newDefaultConfig() } func (s *Source) NewConfig() source.Config { return newDefaultConfig() }

View file

@ -23,10 +23,12 @@ import (
"sigs.k8s.io/node-feature-discovery/source" "sigs.k8s.io/node-feature-discovery/source"
) )
const Name = "iommu"
// Implement FeatureSource interface // Implement FeatureSource interface
type Source struct{} type Source struct{}
func (s Source) Name() string { return "iommu" } func (s Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return nil } func (s *Source) NewConfig() source.Config { return nil }

View file

@ -26,6 +26,8 @@ import (
"sigs.k8s.io/node-feature-discovery/source/internal/kernelutils" "sigs.k8s.io/node-feature-discovery/source/internal/kernelutils"
) )
const Name = "kernel"
// Configuration file options // Configuration file options
type Config struct { type Config struct {
KconfigFile string KconfigFile string
@ -50,7 +52,7 @@ type Source struct {
config *Config config *Config
} }
func (s *Source) Name() string { return "kernel" } func (s *Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return newDefaultConfig() } func (s *Source) NewConfig() source.Config { return newDefaultConfig() }

View file

@ -30,6 +30,8 @@ import (
"sigs.k8s.io/node-feature-discovery/source" "sigs.k8s.io/node-feature-discovery/source"
) )
const Name = "local"
// Config // Config
var ( var (
featureFilesDir = "/etc/kubernetes/node-feature-discovery/features.d/" featureFilesDir = "/etc/kubernetes/node-feature-discovery/features.d/"
@ -39,7 +41,7 @@ var (
// Implement FeatureSource interface // Implement FeatureSource interface
type Source struct{} type Source struct{}
func (s Source) Name() string { return "local" } func (s Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return nil } func (s *Source) NewConfig() source.Config { return nil }

View file

@ -26,11 +26,13 @@ import (
"sigs.k8s.io/node-feature-discovery/source" "sigs.k8s.io/node-feature-discovery/source"
) )
const Name = "memory"
// Source implements FeatureSource. // Source implements FeatureSource.
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 "memory" } func (s Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return nil } func (s *Source) NewConfig() source.Config { return nil }

View file

@ -28,6 +28,8 @@ import (
"sigs.k8s.io/node-feature-discovery/source" "sigs.k8s.io/node-feature-discovery/source"
) )
const Name = "network"
// Linux net iface flags (we only specify the first few) // Linux net iface flags (we only specify the first few)
const ( const (
flagUp = 1 << iota flagUp = 1 << iota
@ -42,7 +44,7 @@ const sysfsBaseDir = "class/net"
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 "network" } func (s Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return nil } func (s *Source) NewConfig() source.Config { return nil }

View file

@ -26,6 +26,8 @@ import (
pciutils "sigs.k8s.io/node-feature-discovery/source/internal" pciutils "sigs.k8s.io/node-feature-discovery/source/internal"
) )
const Name = "pci"
type Config struct { type Config struct {
DeviceClassWhitelist []string `json:"deviceClassWhitelist,omitempty"` DeviceClassWhitelist []string `json:"deviceClassWhitelist,omitempty"`
DeviceLabelFields []string `json:"deviceLabelFields,omitempty"` DeviceLabelFields []string `json:"deviceLabelFields,omitempty"`
@ -45,7 +47,7 @@ type Source struct {
} }
// Return name of the feature source // Return name of the feature source
func (s Source) Name() string { return "pci" } func (s Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return newDefaultConfig() } func (s *Source) NewConfig() source.Config { return newDefaultConfig() }

View file

@ -23,11 +23,13 @@ import (
"sigs.k8s.io/node-feature-discovery/source" "sigs.k8s.io/node-feature-discovery/source"
) )
const Name = "storage"
// Source implements FeatureSource. // Source implements FeatureSource.
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 "storage" } func (s Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return nil } func (s *Source) NewConfig() source.Config { return nil }

View file

@ -32,10 +32,12 @@ var osReleaseFields = [...]string{
"VERSION_ID", "VERSION_ID",
} }
const Name = "system"
// Implement FeatureSource interface // Implement FeatureSource interface
type Source struct{} type Source struct{}
func (s Source) Name() string { return "system" } func (s Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return nil } func (s *Source) NewConfig() source.Config { return nil }

View file

@ -26,6 +26,8 @@ import (
usbutils "sigs.k8s.io/node-feature-discovery/source/internal" usbutils "sigs.k8s.io/node-feature-discovery/source/internal"
) )
const Name = "usb"
type Config struct { type Config struct {
DeviceClassWhitelist []string `json:"deviceClassWhitelist,omitempty"` DeviceClassWhitelist []string `json:"deviceClassWhitelist,omitempty"`
DeviceLabelFields []string `json:"deviceLabelFields,omitempty"` DeviceLabelFields []string `json:"deviceLabelFields,omitempty"`
@ -48,7 +50,7 @@ type Source struct {
} }
// Return name of the feature source // Return name of the feature source
func (s Source) Name() string { return "usb" } func (s Source) Name() string { return Name }
// NewConfig method of the FeatureSource interface // NewConfig method of the FeatureSource interface
func (s *Source) NewConfig() source.Config { return newDefaultConfig() } func (s *Source) NewConfig() source.Config { return newDefaultConfig() }