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
type MatchRule struct {
PciId *rules.PciIdRule `json:"pciId,omitempty""`
UsbId *rules.UsbIdRule `json:"usbId,omitempty""`
LoadedKMod *rules.LoadedKModRule `json:"loadedKMod,omitempty""`
PciID *rules.PciIDRule `json:"pciId,omitempty"`
UsbID *rules.UsbIDRule `json:"usbId,omitempty"`
LoadedKMod *rules.LoadedKModRule `json:"loadedKMod,omitempty"`
}
type CustomFeature struct {
type FeatureSpec struct {
Name string `json:"name"`
MatchOn []MatchRule `json:"matchOn"`
}
type NFDConfig []CustomFeature
type NFDConfig []FeatureSpec
var Config = NFDConfig{}
@ -66,11 +66,11 @@ func (s Source) Discover() (source.Features, error) {
// Process a single feature by Matching on the defined rules.
// 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 {
// PCI ID rule
if rule.PciId != nil {
match, err := rule.PciId.Match()
if rule.PciID != nil {
match, err := rule.PciID.Match()
if err != nil {
return false, err
}
@ -79,8 +79,8 @@ func (s Source) discoverFeature(feature CustomFeature) (bool, error) {
}
}
// USB ID rule
if rule.UsbId != nil {
match, err := rule.UsbId.Match()
if rule.UsbID != nil {
match, err := rule.UsbID.Match()
if err != nil {
return false, err
}

View file

@ -25,18 +25,18 @@ import (
// each device attribute will be a list elements(strings).
// 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.
type PciIdRuleInput struct {
type PciIDRuleInput struct {
Class []string `json:"class,omitempty"`
Vendor []string `json:"vendor,omitempty"`
Device []string `json:"device,omitempty"`
}
type PciIdRule struct {
PciIdRuleInput
type PciIDRule struct {
PciIDRuleInput
}
// Match PCI devices on provided PCI device attributes
func (r *PciIdRule) Match() (bool, error) {
func (r *PciIDRule) Match() (bool, error) {
devAttr := map[string]bool{}
for _, attr := range []string{"class", "vendor", "device"} {
devAttr[attr] = true
@ -57,7 +57,7 @@ func (r *PciIdRule) Match() (bool, error) {
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 {
return false
}

View file

@ -25,18 +25,18 @@ import (
// each device attribute will be a list elements(strings).
// 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.
type UsbIdRuleInput struct {
type UsbIDRuleInput struct {
Class []string `json:"class,omitempty"`
Vendor []string `json:"vendor,omitempty"`
Device []string `json:"device,omitempty"`
}
type UsbIdRule struct {
UsbIdRuleInput
type UsbIDRule struct {
UsbIDRuleInput
}
// Match USB devices on provided USB device attributes
func (r *UsbIdRule) Match() (bool, error) {
func (r *UsbIDRule) Match() (bool, error) {
devAttr := map[string]bool{}
for _, attr := range []string{"class", "vendor", "device"} {
devAttr[attr] = true
@ -57,7 +57,7 @@ func (r *UsbIdRule) Match() (bool, error) {
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 {
return false
}
@ -76,4 +76,3 @@ func (r *UsbIdRule) matchDevOnRule(dev usbutils.UsbDeviceInfo) bool {
return true
}

View file

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