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/custom: make linter happy

Might not agree with all that naming arbitrariness but it's easier just
to bend over.
This commit is contained in:
Markus Lehtonen 2020-05-19 16:01:43 +03:00
parent 523aa894a3
commit 80becea590
4 changed files with 26 additions and 27 deletions

View file

@ -26,17 +26,17 @@ import (
// Custom Features Configurations // Custom Features Configurations
type MatchRule struct { type MatchRule struct {
PciId *rules.PciIdRule `json:"pciId,omitempty""` PciID *rules.PciIDRule `json:"pciId,omitempty"`
UsbId *rules.UsbIdRule `json:"usbId,omitempty""` UsbID *rules.UsbIDRule `json:"usbId,omitempty"`
LoadedKMod *rules.LoadedKModRule `json:"loadedKMod,omitempty""` LoadedKMod *rules.LoadedKModRule `json:"loadedKMod,omitempty"`
} }
type CustomFeature struct { type FeatureSpec struct {
Name string `json:"name"` Name string `json:"name"`
MatchOn []MatchRule `json:"matchOn"` MatchOn []MatchRule `json:"matchOn"`
} }
type NFDConfig []CustomFeature type NFDConfig []FeatureSpec
var Config = NFDConfig{} var Config = NFDConfig{}
@ -66,11 +66,11 @@ func (s Source) Discover() (source.Features, error) {
// Process a single feature by Matching on the defined rules. // Process a single feature by Matching on the defined rules.
// A feature is present if all defined Rules in a MatchRule return a match. // A feature is present if all defined Rules in a MatchRule return a match.
func (s Source) discoverFeature(feature CustomFeature) (bool, error) { func (s Source) discoverFeature(feature FeatureSpec) (bool, error) {
for _, rule := range feature.MatchOn { for _, rule := range feature.MatchOn {
// PCI ID rule // PCI ID rule
if rule.PciId != nil { if rule.PciID != nil {
match, err := rule.PciId.Match() match, err := rule.PciID.Match()
if err != nil { if err != nil {
return false, err return false, err
} }
@ -79,8 +79,8 @@ func (s Source) discoverFeature(feature CustomFeature) (bool, error) {
} }
} }
// USB ID rule // USB ID rule
if rule.UsbId != nil { if rule.UsbID != nil {
match, err := rule.UsbId.Match() match, err := rule.UsbID.Match()
if err != nil { if err != nil {
return false, err return false, err
} }

View file

@ -25,18 +25,18 @@ import (
// each device attribute will be a list elements(strings). // each device attribute will be a list elements(strings).
// Match operation: OR will be performed per element and AND will be performed per attribute. // Match operation: OR will be performed per element and AND will be performed per attribute.
// An empty attribute will not be included in the matching process. // An empty attribute will not be included in the matching process.
type PciIdRuleInput struct { type PciIDRuleInput struct {
Class []string `json:"class,omitempty"` Class []string `json:"class,omitempty"`
Vendor []string `json:"vendor,omitempty"` Vendor []string `json:"vendor,omitempty"`
Device []string `json:"device,omitempty"` Device []string `json:"device,omitempty"`
} }
type PciIdRule struct { type PciIDRule struct {
PciIdRuleInput PciIDRuleInput
} }
// Match PCI devices on provided PCI device attributes // Match PCI devices on provided PCI device attributes
func (r *PciIdRule) Match() (bool, error) { func (r *PciIDRule) Match() (bool, error) {
devAttr := map[string]bool{} devAttr := map[string]bool{}
for _, attr := range []string{"class", "vendor", "device"} { for _, attr := range []string{"class", "vendor", "device"} {
devAttr[attr] = true devAttr[attr] = true
@ -57,7 +57,7 @@ func (r *PciIdRule) Match() (bool, error) {
return false, nil return false, nil
} }
func (r *PciIdRule) matchDevOnRule(dev pciutils.PciDeviceInfo) bool { func (r *PciIDRule) matchDevOnRule(dev pciutils.PciDeviceInfo) bool {
if len(r.Class) == 0 && len(r.Vendor) == 0 && len(r.Device) == 0 { if len(r.Class) == 0 && len(r.Vendor) == 0 && len(r.Device) == 0 {
return false return false
} }

View file

@ -25,18 +25,18 @@ import (
// each device attribute will be a list elements(strings). // each device attribute will be a list elements(strings).
// Match operation: OR will be performed per element and AND will be performed per attribute. // Match operation: OR will be performed per element and AND will be performed per attribute.
// An empty attribute will not be included in the matching process. // An empty attribute will not be included in the matching process.
type UsbIdRuleInput struct { type UsbIDRuleInput struct {
Class []string `json:"class,omitempty"` Class []string `json:"class,omitempty"`
Vendor []string `json:"vendor,omitempty"` Vendor []string `json:"vendor,omitempty"`
Device []string `json:"device,omitempty"` Device []string `json:"device,omitempty"`
} }
type UsbIdRule struct { type UsbIDRule struct {
UsbIdRuleInput UsbIDRuleInput
} }
// Match USB devices on provided USB device attributes // Match USB devices on provided USB device attributes
func (r *UsbIdRule) Match() (bool, error) { func (r *UsbIDRule) Match() (bool, error) {
devAttr := map[string]bool{} devAttr := map[string]bool{}
for _, attr := range []string{"class", "vendor", "device"} { for _, attr := range []string{"class", "vendor", "device"} {
devAttr[attr] = true devAttr[attr] = true
@ -57,7 +57,7 @@ func (r *UsbIdRule) Match() (bool, error) {
return false, nil return false, nil
} }
func (r *UsbIdRule) matchDevOnRule(dev usbutils.UsbDeviceInfo) bool { func (r *UsbIDRule) matchDevOnRule(dev usbutils.UsbDeviceInfo) bool {
if len(r.Class) == 0 && len(r.Vendor) == 0 && len(r.Device) == 0 { if len(r.Class) == 0 && len(r.Vendor) == 0 && len(r.Device) == 0 {
return false return false
} }
@ -76,4 +76,3 @@ func (r *UsbIdRule) matchDevOnRule(dev usbutils.UsbDeviceInfo) bool {
return true return true
} }

View file

@ -22,19 +22,19 @@ import (
// getStaticFeatures returns statically configured custom features to discover // getStaticFeatures returns statically configured custom features to discover
// e.g RMDA related features. NFD configuration file may extend these custom features by adding rules. // e.g RMDA related features. NFD configuration file may extend these custom features by adding rules.
func getStaticFeatureConfig() []CustomFeature { func getStaticFeatureConfig() []FeatureSpec {
return []CustomFeature{ return []FeatureSpec{
CustomFeature{ FeatureSpec{
Name: "rdma.capable", Name: "rdma.capable",
MatchOn: []MatchRule{ MatchOn: []MatchRule{
MatchRule{ MatchRule{
PciId: &rules.PciIdRule{ PciID: &rules.PciIDRule{
rules.PciIdRuleInput{Vendor: []string{"15b3"}}, PciIDRuleInput: rules.PciIDRuleInput{Vendor: []string{"15b3"}},
}, },
}, },
}, },
}, },
CustomFeature{ FeatureSpec{
Name: "rdma.available", Name: "rdma.available",
MatchOn: []MatchRule{ MatchOn: []MatchRule{
MatchRule{ MatchRule{