1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-05 16:27:05 +00:00

Additional Lint Fixes in Codebase (#779)

* fix comments and conditonals to fix lint issues

* more linter fixes and spelling fixes

* fix linter issues based on feedback
This commit is contained in:
Dipto Chakrabarty 2022-03-03 06:42:46 +05:30 committed by GitHub
parent 9059b5dbec
commit 19a57789ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 34 additions and 13 deletions

View file

@ -29,11 +29,12 @@ import (
"k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd"
) )
// Implements APIHelpers // K8sHelpers implements APIHelpers
type K8sHelpers struct { type K8sHelpers struct {
Kubeconfig *restclient.Config Kubeconfig *restclient.Config
} }
// GetClient creates and returns a new clientset from given config
func (h K8sHelpers) GetClient() (*k8sclient.Clientset, error) { func (h K8sHelpers) GetClient() (*k8sclient.Clientset, error) {
clientset, err := k8sclient.NewForConfig(h.Kubeconfig) clientset, err := k8sclient.NewForConfig(h.Kubeconfig)
if err != nil { if err != nil {
@ -50,6 +51,7 @@ func (h K8sHelpers) GetTopologyClient() (*topologyclientset.Clientset, error) {
return topologyClient, nil return topologyClient, nil
} }
// GetNode retrieves one node object.
func (h K8sHelpers) GetNode(cli *k8sclient.Clientset, nodeName string) (*api.Node, error) { func (h K8sHelpers) GetNode(cli *k8sclient.Clientset, nodeName string) (*api.Node, error) {
// Get the node object using node name // Get the node object using node name
node, err := cli.CoreV1().Nodes().Get(context.TODO(), nodeName, meta_v1.GetOptions{}) node, err := cli.CoreV1().Nodes().Get(context.TODO(), nodeName, meta_v1.GetOptions{})
@ -60,10 +62,12 @@ func (h K8sHelpers) GetNode(cli *k8sclient.Clientset, nodeName string) (*api.Nod
return node, nil return node, nil
} }
// GetNodes retrieves all the node objects.
func (h K8sHelpers) GetNodes(cli *k8sclient.Clientset) (*api.NodeList, error) { func (h K8sHelpers) GetNodes(cli *k8sclient.Clientset) (*api.NodeList, error) {
return cli.CoreV1().Nodes().List(context.TODO(), meta_v1.ListOptions{}) return cli.CoreV1().Nodes().List(context.TODO(), meta_v1.ListOptions{})
} }
// UpdateNode sends updated node object to the apiserver
func (h K8sHelpers) UpdateNode(c *k8sclient.Clientset, n *api.Node) error { func (h K8sHelpers) UpdateNode(c *k8sclient.Clientset, n *api.Node) error {
// Send the updated node to the apiserver. // Send the updated node to the apiserver.
_, err := c.CoreV1().Nodes().Update(context.TODO(), n, meta_v1.UpdateOptions{}) _, err := c.CoreV1().Nodes().Update(context.TODO(), n, meta_v1.UpdateOptions{})
@ -107,6 +111,7 @@ func (h K8sHelpers) GetPod(cli *k8sclient.Clientset, namespace string, podName s
return pod, nil return pod, nil
} }
// GetKubeconfig returns the kubeconfig for the cluster
func GetKubeconfig(path string) (*restclient.Config, error) { func GetKubeconfig(path string) (*restclient.Config, error) {
if path == "" { if path == "" {
return restclient.InClusterConfig() return restclient.InClusterConfig()

View file

@ -45,7 +45,7 @@ func TestRule(t *testing.T) {
assert.Equal(t, r1.Labels, m.Labels, "empty matcher should have matched empty features") assert.Equal(t, r1.Labels, m.Labels, "empty matcher should have matched empty features")
_, err = r2.Execute(f) _, err = r2.Execute(f)
assert.Error(t, err, "matching agains a missing domain should have returned an error") assert.Error(t, err, "matching against a missing domain should have returned an error")
// Test empty domain // Test empty domain
d := feature.NewDomainFeatures() d := feature.NewDomainFeatures()
@ -57,7 +57,7 @@ func TestRule(t *testing.T) {
assert.Empty(t, r1.Vars, "vars should be empty") assert.Empty(t, r1.Vars, "vars should be empty")
_, err = r2.Execute(f) _, err = r2.Execute(f)
assert.Error(t, err, "matching agains a missing feature type should have returned an error") assert.Error(t, err, "matching against a missing feature type should have returned an error")
// Test empty feature sets // Test empty feature sets
d.Keys["kf-1"] = feature.NewKeyFeatures() d.Keys["kf-1"] = feature.NewKeyFeatures()

View file

@ -64,7 +64,7 @@ func init() {
// NodeName returns the name of the k8s node we're running on. // NodeName returns the name of the k8s node we're running on.
func NodeName() string { return nodeName } func NodeName() string { return nodeName }
// Create new NfdWorker instance. // NewNfdBaseClient creates a new NfdBaseClient instance.
func NewNfdBaseClient(args *Args) (NfdBaseClient, error) { func NewNfdBaseClient(args *Args) (NfdBaseClient, error) {
nfd := NfdBaseClient{args: *args} nfd := NfdBaseClient{args: *args}
@ -134,7 +134,7 @@ func (w *NfdBaseClient) Connect() error {
return nil return nil
} }
// disconnect closes the connection to NFD master // Disconnect closes the connection to NFD master
func (w *NfdBaseClient) Disconnect() { func (w *NfdBaseClient) Disconnect() {
if w.clientConn != nil { if w.clientConn != nil {
klog.Infof("closing connection to nfd-master ...") klog.Infof("closing connection to nfd-master ...")

View file

@ -34,7 +34,7 @@ import (
"sigs.k8s.io/node-feature-discovery/pkg/version" "sigs.k8s.io/node-feature-discovery/pkg/version"
) )
// Command line arguments // Args are the command line arguments
type Args struct { type Args struct {
nfdclient.Args nfdclient.Args
NoPublish bool NoPublish bool
@ -61,7 +61,7 @@ type nfdTopologyUpdater struct {
stop chan struct{} // channel for signaling stop stop chan struct{} // channel for signaling stop
} }
// Create new NewTopologyUpdater instance. // NewTopologyUpdater creates a new NfdTopologyUpdater instance.
func NewTopologyUpdater(args Args, resourcemonitorArgs resourcemonitor.Args, policy string) (NfdTopologyUpdater, error) { func NewTopologyUpdater(args Args, resourcemonitorArgs resourcemonitor.Args, policy string) (NfdTopologyUpdater, error) {
base, err := nfdclient.NewNfdBaseClient(&args.Args) base, err := nfdclient.NewNfdBaseClient(&args.Args)
if err != nil { if err != nil {

View file

@ -120,7 +120,7 @@ type nfdMaster struct {
kubeconfig *restclient.Config kubeconfig *restclient.Config
} }
// Create new NfdMaster server instance. // NewNfdMaster creates a new NfdMaster server instance.
func NewNfdMaster(args *Args) (NfdMaster, error) { func NewNfdMaster(args *Args) (NfdMaster, error) {
nfd := &nfdMaster{args: *args, nfd := &nfdMaster{args: *args,
nodeName: os.Getenv("NODE_NAME"), nodeName: os.Getenv("NODE_NAME"),

View file

@ -35,6 +35,7 @@ type PodResourcesScanner struct {
apihelper apihelper.APIHelpers apihelper apihelper.APIHelpers
} }
// NewPodResourcesScanner creates a new ResourcesScanner instance
func NewPodResourcesScanner(namespace string, podResourceClient podresourcesapi.PodResourcesListerClient, kubeApihelper apihelper.APIHelpers) (ResourcesScanner, error) { func NewPodResourcesScanner(namespace string, podResourceClient podresourcesapi.PodResourcesListerClient, kubeApihelper apihelper.APIHelpers) (ResourcesScanner, error) {
resourcemonitorInstance := &PodResourcesScanner{ resourcemonitorInstance := &PodResourcesScanner{
namespace: namespace, namespace: namespace,

View file

@ -57,7 +57,7 @@ type ResourcesScanner interface {
Scan() ([]PodResources, error) Scan() ([]PodResources, error)
} }
// ResourceAggregator aggregates resource information based on the received data from underlying hardware and podresource API // ResourcesAggregator aggregates resource information based on the received data from underlying hardware and podresource API
type ResourcesAggregator interface { type ResourcesAggregator interface {
Aggregate(podResData []PodResources) topologyv1alpha1.ZoneList Aggregate(podResData []PodResources) topologyv1alpha1.ZoneList
} }

View file

@ -46,6 +46,7 @@ type cpuidConfig struct {
AttributeWhitelist []string `json:"attributeWhitelist,omitempty"` AttributeWhitelist []string `json:"attributeWhitelist,omitempty"`
} }
// Config holds configuration for the cpu source.
type Config struct { type Config struct {
Cpuid cpuidConfig `json:"cpuid,omitempty"` Cpuid cpuidConfig `json:"cpuid,omitempty"`
} }

View file

@ -63,9 +63,9 @@ func detectCstate() (map[string]string, error) {
cstates, err := strconv.Atoi(strings.TrimSpace(string(data))) cstates, err := strconv.Atoi(strings.TrimSpace(string(data)))
if err != nil { if err != nil {
return cstate, fmt.Errorf("non-integer value of cstates: %w", err) return cstate, fmt.Errorf("non-integer value of cstates: %w", err)
} else {
cstate["enabled"] = strconv.FormatBool(cstates > 0)
} }
cstate["enabled"] = strconv.FormatBool(cstates > 0)
return cstate, nil return cstate, nil
} }

View file

@ -30,7 +30,7 @@ import (
) )
const ( const (
// CPUID EAX input values // LEAF_PROCESSOR_FREQUENCY_INFORMATION is the cpuid leaf to get processor frequency information
LEAF_PROCESSOR_FREQUENCY_INFORMATION = 0x16 LEAF_PROCESSOR_FREQUENCY_INFORMATION = 0x16
) )

View file

@ -28,6 +28,7 @@ type KconfigRule struct {
nfdv1alpha1.MatchExpressionSet nfdv1alpha1.MatchExpressionSet
} }
// Match compares the values of Kernel config provided and legacy config
func (r *KconfigRule) Match() (bool, error) { func (r *KconfigRule) Match() (bool, error) {
options := kernel.GetLegacyKconfig() options := kernel.GetLegacyKconfig()
if options == nil { if options == nil {

View file

@ -30,6 +30,7 @@ type NodenameRule struct {
nfdv1alpha1.MatchExpression nfdv1alpha1.MatchExpression
} }
// Match checks if node name matches the rule.
func (r *NodenameRule) Match() (bool, error) { func (r *NodenameRule) Match() (bool, error) {
nodeName, ok := source.GetFeatureSource("system").GetFeatures().Values[system.NameFeature].Elements["nodename"] nodeName, ok := source.GetFeatureSource("system").GetFeatures().Values[system.NameFeature].Elements["nodename"]
if !ok || nodeName == "" { if !ok || nodeName == "" {
@ -38,6 +39,7 @@ func (r *NodenameRule) Match() (bool, error) {
return r.MatchExpression.Match(true, nodeName) return r.MatchExpression.Match(true, nodeName)
} }
// UnmarshalJSON unmarshals and validates the data provided
func (r *NodenameRule) UnmarshalJSON(data []byte) error { func (r *NodenameRule) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &r.MatchExpression); err != nil { if err := json.Unmarshal(data, &r.MatchExpression); err != nil {
return err return err

View file

@ -27,11 +27,16 @@ import (
// Name of this feature source // Name of this feature source
const Name = "fake" const Name = "fake"
// FlagFeature of this feature source
const FlagFeature = "flag" const FlagFeature = "flag"
// AttributeFeature of this feature source
const AttributeFeature = "attribute" const AttributeFeature = "attribute"
// InstanceFeature of this feature source
const InstanceFeature = "instance" const InstanceFeature = "instance"
// Configuration file options // Config contains the configuration parameters of this source.
type Config struct { type Config struct {
Labels map[string]string `json:"labels"` Labels map[string]string `json:"labels"`
FlagFeatures []string `json:"flagFeatures"` FlagFeatures []string `json:"flagFeatures"`

View file

@ -35,6 +35,7 @@ import (
// Name of this feature source // Name of this feature source
const Name = "local" const Name = "local"
// LabelFeature of this feature source
const LabelFeature = "label" const LabelFeature = "label"
// Config // Config

View file

@ -34,7 +34,10 @@ import (
// Name of this feature source // Name of this feature source
const Name = "memory" const Name = "memory"
// NvFeature is the name of the feature set that holds all discovered NVDIMM devices.
const NvFeature = "nv" const NvFeature = "nv"
// NumaFeature is the name of the feature set that holds all NUMA related features.
const NumaFeature = "numa" const NumaFeature = "numa"
// memorySource implements the FeatureSource and LabelSource interfaces. // memorySource implements the FeatureSource and LabelSource interfaces.

View file

@ -30,8 +30,10 @@ import (
// Name of this feature source // Name of this feature source
const Name = "pci" const Name = "pci"
// DeviceFeature is the name of the feature set that holds all discovered PCI devices.
const DeviceFeature = "device" const DeviceFeature = "device"
// Config holds the configuration parameters of this source.
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"`