diff --git a/pkg/nfd-master/nfd-master-internal_test.go b/pkg/nfd-master/nfd-master-internal_test.go index ccd673ecf..4e957cba8 100644 --- a/pkg/nfd-master/nfd-master-internal_test.go +++ b/pkg/nfd-master/nfd-master-internal_test.go @@ -365,7 +365,7 @@ func TestSetLabels(t *testing.T) { apihelper.NewJsonPatch("add", "/metadata/labels", "valid.ns/feature-2", mockLabels["valid.ns/feature-2"]), } - mockMaster.args.ExtraLabelNs = map[string]struct{}{"valid.ns": struct{}{}} + mockMaster.args.ExtraLabelNs = map[string]struct{}{"valid.ns": {}} mockMaster.annotationNs = instance + "." + AnnotationNsBase mockHelper.On("GetClient").Return(mockClient, nil) mockHelper.On("GetNode", mockClient, workerName).Return(mockNode, nil) @@ -391,7 +391,7 @@ func TestSetLabels(t *testing.T) { apihelper.NewJsonPatch("add", "/status/capacity", LabelNs+"/feature-3", mockLabels["feature-3"]), } - mockMaster.args.ResourceLabels = map[string]struct{}{"feature-3": struct{}{}, "feature-1": struct{}{}} + mockMaster.args.ResourceLabels = map[string]struct{}{"feature-3": {}, "feature-1": {}} mockHelper.On("GetClient").Return(mockClient, nil) mockHelper.On("GetNode", mockClient, workerName).Return(mockNode, nil) mockHelper.On("PatchNode", mockClient, mockNodeName, mock.MatchedBy(jsonPatchMatcher(expectedPatches))).Return(nil) diff --git a/pkg/nfd-master/nfd-master.go b/pkg/nfd-master/nfd-master.go index 2b9d1d9c6..508450fd4 100644 --- a/pkg/nfd-master/nfd-master.go +++ b/pkg/nfd-master/nfd-master.go @@ -43,10 +43,10 @@ import ( ) const ( - // Namespace for feature labels + // LabelNs defines the Namespace for feature labels LabelNs = "feature.node.kubernetes.io" - // Base namespace for all NFD-related annotations + // AnnotationNsBase namespace for all NFD-related annotations AnnotationNsBase = "nfd.node.kubernetes.io" // NFD Annotations @@ -65,7 +65,7 @@ type ExtendedResources map[string]string // Annotations are used for NFD-related node metadata type Annotations map[string]string -// Command line arguments +// Args holds command line arguments type Args struct { CaFile string CertFile string diff --git a/source/custom/custom.go b/source/custom/custom.go index 9100f56b1..f336b49ff 100644 --- a/source/custom/custom.go +++ b/source/custom/custom.go @@ -51,13 +51,13 @@ func newDefaultConfig() *config { return &config{} } -// Implements FeatureSource Interface +// Source implements FeatureSource Interface type Source struct { config *config } -// Return name of the feature source -func (s Source) Name() string { return Name } +// Name returns the name of the feature source +func (s Source) Name() string { return "custom" } // NewConfig method of the FeatureSource interface func (s *Source) NewConfig() source.Config { return newDefaultConfig() } diff --git a/source/custom/directory_features.go b/source/custom/directory_features.go index f2aa2f01e..d2a725ac6 100644 --- a/source/custom/directory_features.go +++ b/source/custom/directory_features.go @@ -26,6 +26,7 @@ import ( "sigs.k8s.io/yaml" ) +// Directory stores the full path for the custom sources folder const Directory = "/etc/kubernetes/node-feature-discovery/custom.d" // getDirectoryFeatureConfig returns features configured in the "/etc/kubernetes/node-feature-discovery/custom.d" diff --git a/source/custom/rules/loaded_kmod_rule.go b/source/custom/rules/loaded_kmod_rule.go index 2bfb8c32f..f2a9c84d2 100644 --- a/source/custom/rules/loaded_kmod_rule.go +++ b/source/custom/rules/loaded_kmod_rule.go @@ -22,7 +22,7 @@ import ( "strings" ) -// Rule that matches on loaded kernel modules in the system +// LoadedKModRule matches loaded kernel modules in the system type LoadedKModRule []string const kmodProcfsPath = "/proc/modules" diff --git a/source/custom/rules/nodename_rule.go b/source/custom/rules/nodename_rule.go index 7c32d9b36..02199a095 100644 --- a/source/custom/rules/nodename_rule.go +++ b/source/custom/rules/nodename_rule.go @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ + package rules import ( @@ -26,7 +27,7 @@ var ( nodeName = os.Getenv("NODE_NAME") ) -// Rule that matches on nodenames configured in a ConfigMap +// NodenameRule matches on nodenames configured in a ConfigMap type NodenameRule []string // Force implementation of Rule diff --git a/source/custom/static_features.go b/source/custom/static_features.go index 1e32379bd..c3e48165b 100644 --- a/source/custom/static_features.go +++ b/source/custom/static_features.go @@ -24,20 +24,20 @@ import ( // e.g RMDA related features. NFD configuration file may extend these custom features by adding rules. func getStaticFeatureConfig() []FeatureSpec { return []FeatureSpec{ - FeatureSpec{ + { Name: "rdma.capable", MatchOn: []MatchRule{ - MatchRule{ + { PciID: &rules.PciIDRule{ PciIDRuleInput: rules.PciIDRuleInput{Vendor: []string{"15b3"}}, }, }, }, }, - FeatureSpec{ + { Name: "rdma.available", MatchOn: []MatchRule{ - MatchRule{ + { LoadedKMod: &rules.LoadedKModRule{"ib_uverbs", "rdma_ucm"}, }, }, diff --git a/source/internal/cpuidutils/cpuid_amd64.go b/source/internal/cpuidutils/cpuid_amd64.go index 29c2aad03..49d1b6dd7 100644 --- a/source/internal/cpuidutils/cpuid_amd64.go +++ b/source/internal/cpuidutils/cpuid_amd64.go @@ -20,7 +20,7 @@ import ( "github.com/klauspost/cpuid/v2" ) -// Discover returns feature names for all the supported CPU features. +// GetCpuidFlags returns feature names for all the supported CPU features. func GetCpuidFlags() []string { return cpuid.CPU.FeatureSet() } diff --git a/source/internal/pci_utils.go b/source/internal/pci_utils.go index 4358087f3..a0c11743a 100644 --- a/source/internal/pci_utils.go +++ b/source/internal/pci_utils.go @@ -68,12 +68,12 @@ func readPciDevInfo(devPath string, deviceAttrSpec map[string]bool) (PciDeviceIn return info, nil } -// List available PCI devices and retrieve device attributes. +// DetectPci lists available PCI devices and retrieve device attributes. // deviceAttrSpec is a map which specifies which attributes to retrieve. // a false value for a specific attribute marks the attribute as optional. // a true value for a specific attribute marks the attribute as mandatory. // "class" attribute is considered mandatory. -// DetectPci() will fail if the retrieval of a mandatory attribute fails. +// will fail if the retrieval of a mandatory attribute fails. func DetectPci(deviceAttrSpec map[string]bool) (map[string][]PciDeviceInfo, error) { sysfsBasePath := source.SysfsDir.Path("bus/pci/devices") devInfo := make(map[string][]PciDeviceInfo) diff --git a/source/iommu/iommu.go b/source/iommu/iommu.go index 20558d815..89da1684e 100644 --- a/source/iommu/iommu.go +++ b/source/iommu/iommu.go @@ -26,6 +26,7 @@ import ( const Name = "iommu" // Implement FeatureSource interface +// Source implements FeatureSource interface type Source struct{} func (s Source) Name() string { return Name } diff --git a/source/local/local.go b/source/local/local.go index d7d3dbdb9..38e0c147d 100644 --- a/source/local/local.go +++ b/source/local/local.go @@ -38,10 +38,11 @@ var ( hookDir = "/etc/kubernetes/node-feature-discovery/source.d/" ) -// Implement FeatureSource interface +// Source implements FeatureSource interface type Source struct{} -func (s Source) Name() string { return Name } +// Name returns the name of the feature source +func (s Source) Name() string { return "local" } // NewConfig method of the FeatureSource interface func (s *Source) NewConfig() source.Config { return nil } @@ -52,6 +53,7 @@ func (s *Source) GetConfig() source.Config { return nil } // SetConfig method of the FeatureSource interface func (s *Source) SetConfig(source.Config) {} +// Discover returns features from hooks and files func (s Source) Discover() (source.Features, error) { featuresFromHooks, err := getFeaturesFromHooks() if err != nil { diff --git a/source/pci/pci.go b/source/pci/pci.go index 9e6f6ecca..fe2702e65 100644 --- a/source/pci/pci.go +++ b/source/pci/pci.go @@ -41,13 +41,13 @@ func newDefaultConfig() *Config { } } -// Implement FeatureSource interface +// Source implements FeatureSource interface type Source struct { config *Config } -// Return name of the feature source -func (s Source) Name() string { return Name } +// Name returns the name of the feature source +func (s Source) Name() string { return "pci" } // NewConfig method of the FeatureSource interface func (s *Source) NewConfig() source.Config { return newDefaultConfig() } diff --git a/source/usb/usb.go b/source/usb/usb.go index bb5f917fa..e9566ef4c 100644 --- a/source/usb/usb.go +++ b/source/usb/usb.go @@ -44,13 +44,13 @@ func newDefaultConfig() *Config { } } -// Implement FeatureSource interface +// Source implements FeatureSource interface type Source struct { config *Config } -// Return name of the feature source -func (s Source) Name() string { return Name } +// Name returns the name of the feature source +func (s Source) Name() string { return "usb" } // NewConfig method of the FeatureSource interface func (s *Source) NewConfig() source.Config { return newDefaultConfig() }