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:
parent
9059b5dbec
commit
19a57789ad
16 changed files with 34 additions and 13 deletions
|
@ -29,11 +29,12 @@ import (
|
|||
"k8s.io/client-go/tools/clientcmd"
|
||||
)
|
||||
|
||||
// Implements APIHelpers
|
||||
// K8sHelpers implements APIHelpers
|
||||
type K8sHelpers struct {
|
||||
Kubeconfig *restclient.Config
|
||||
}
|
||||
|
||||
// GetClient creates and returns a new clientset from given config
|
||||
func (h K8sHelpers) GetClient() (*k8sclient.Clientset, error) {
|
||||
clientset, err := k8sclient.NewForConfig(h.Kubeconfig)
|
||||
if err != nil {
|
||||
|
@ -50,6 +51,7 @@ func (h K8sHelpers) GetTopologyClient() (*topologyclientset.Clientset, error) {
|
|||
return topologyClient, nil
|
||||
}
|
||||
|
||||
// GetNode retrieves one node object.
|
||||
func (h K8sHelpers) GetNode(cli *k8sclient.Clientset, nodeName string) (*api.Node, error) {
|
||||
// Get the node object using node name
|
||||
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
|
||||
}
|
||||
|
||||
// GetNodes retrieves all the node objects.
|
||||
func (h K8sHelpers) GetNodes(cli *k8sclient.Clientset) (*api.NodeList, error) {
|
||||
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 {
|
||||
// Send the updated node to the apiserver.
|
||||
_, 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
|
||||
}
|
||||
|
||||
// GetKubeconfig returns the kubeconfig for the cluster
|
||||
func GetKubeconfig(path string) (*restclient.Config, error) {
|
||||
if path == "" {
|
||||
return restclient.InClusterConfig()
|
||||
|
|
|
@ -45,7 +45,7 @@ func TestRule(t *testing.T) {
|
|||
assert.Equal(t, r1.Labels, m.Labels, "empty matcher should have matched empty features")
|
||||
|
||||
_, 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
|
||||
d := feature.NewDomainFeatures()
|
||||
|
@ -57,7 +57,7 @@ func TestRule(t *testing.T) {
|
|||
assert.Empty(t, r1.Vars, "vars should be empty")
|
||||
|
||||
_, 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
|
||||
d.Keys["kf-1"] = feature.NewKeyFeatures()
|
||||
|
|
|
@ -64,7 +64,7 @@ func init() {
|
|||
// NodeName returns the name of the k8s node we're running on.
|
||||
func NodeName() string { return nodeName }
|
||||
|
||||
// Create new NfdWorker instance.
|
||||
// NewNfdBaseClient creates a new NfdBaseClient instance.
|
||||
func NewNfdBaseClient(args *Args) (NfdBaseClient, error) {
|
||||
nfd := NfdBaseClient{args: *args}
|
||||
|
||||
|
@ -134,7 +134,7 @@ func (w *NfdBaseClient) Connect() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// disconnect closes the connection to NFD master
|
||||
// Disconnect closes the connection to NFD master
|
||||
func (w *NfdBaseClient) Disconnect() {
|
||||
if w.clientConn != nil {
|
||||
klog.Infof("closing connection to nfd-master ...")
|
||||
|
|
|
@ -34,7 +34,7 @@ import (
|
|||
"sigs.k8s.io/node-feature-discovery/pkg/version"
|
||||
)
|
||||
|
||||
// Command line arguments
|
||||
// Args are the command line arguments
|
||||
type Args struct {
|
||||
nfdclient.Args
|
||||
NoPublish bool
|
||||
|
@ -61,7 +61,7 @@ type nfdTopologyUpdater struct {
|
|||
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) {
|
||||
base, err := nfdclient.NewNfdBaseClient(&args.Args)
|
||||
if err != nil {
|
||||
|
|
|
@ -120,7 +120,7 @@ type nfdMaster struct {
|
|||
kubeconfig *restclient.Config
|
||||
}
|
||||
|
||||
// Create new NfdMaster server instance.
|
||||
// NewNfdMaster creates a new NfdMaster server instance.
|
||||
func NewNfdMaster(args *Args) (NfdMaster, error) {
|
||||
nfd := &nfdMaster{args: *args,
|
||||
nodeName: os.Getenv("NODE_NAME"),
|
||||
|
|
|
@ -35,6 +35,7 @@ type PodResourcesScanner struct {
|
|||
apihelper apihelper.APIHelpers
|
||||
}
|
||||
|
||||
// NewPodResourcesScanner creates a new ResourcesScanner instance
|
||||
func NewPodResourcesScanner(namespace string, podResourceClient podresourcesapi.PodResourcesListerClient, kubeApihelper apihelper.APIHelpers) (ResourcesScanner, error) {
|
||||
resourcemonitorInstance := &PodResourcesScanner{
|
||||
namespace: namespace,
|
||||
|
|
|
@ -57,7 +57,7 @@ type ResourcesScanner interface {
|
|||
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 {
|
||||
Aggregate(podResData []PodResources) topologyv1alpha1.ZoneList
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ type cpuidConfig struct {
|
|||
AttributeWhitelist []string `json:"attributeWhitelist,omitempty"`
|
||||
}
|
||||
|
||||
// Config holds configuration for the cpu source.
|
||||
type Config struct {
|
||||
Cpuid cpuidConfig `json:"cpuid,omitempty"`
|
||||
}
|
||||
|
|
|
@ -63,9 +63,9 @@ func detectCstate() (map[string]string, error) {
|
|||
cstates, err := strconv.Atoi(strings.TrimSpace(string(data)))
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// CPUID EAX input values
|
||||
// LEAF_PROCESSOR_FREQUENCY_INFORMATION is the cpuid leaf to get processor frequency information
|
||||
LEAF_PROCESSOR_FREQUENCY_INFORMATION = 0x16
|
||||
)
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ type KconfigRule struct {
|
|||
nfdv1alpha1.MatchExpressionSet
|
||||
}
|
||||
|
||||
// Match compares the values of Kernel config provided and legacy config
|
||||
func (r *KconfigRule) Match() (bool, error) {
|
||||
options := kernel.GetLegacyKconfig()
|
||||
if options == nil {
|
||||
|
|
|
@ -30,6 +30,7 @@ type NodenameRule struct {
|
|||
nfdv1alpha1.MatchExpression
|
||||
}
|
||||
|
||||
// Match checks if node name matches the rule.
|
||||
func (r *NodenameRule) Match() (bool, error) {
|
||||
nodeName, ok := source.GetFeatureSource("system").GetFeatures().Values[system.NameFeature].Elements["nodename"]
|
||||
if !ok || nodeName == "" {
|
||||
|
@ -38,6 +39,7 @@ func (r *NodenameRule) Match() (bool, error) {
|
|||
return r.MatchExpression.Match(true, nodeName)
|
||||
}
|
||||
|
||||
// UnmarshalJSON unmarshals and validates the data provided
|
||||
func (r *NodenameRule) UnmarshalJSON(data []byte) error {
|
||||
if err := json.Unmarshal(data, &r.MatchExpression); err != nil {
|
||||
return err
|
||||
|
|
|
@ -27,11 +27,16 @@ import (
|
|||
// Name of this feature source
|
||||
const Name = "fake"
|
||||
|
||||
// FlagFeature of this feature source
|
||||
const FlagFeature = "flag"
|
||||
|
||||
// AttributeFeature of this feature source
|
||||
const AttributeFeature = "attribute"
|
||||
|
||||
// InstanceFeature of this feature source
|
||||
const InstanceFeature = "instance"
|
||||
|
||||
// Configuration file options
|
||||
// Config contains the configuration parameters of this source.
|
||||
type Config struct {
|
||||
Labels map[string]string `json:"labels"`
|
||||
FlagFeatures []string `json:"flagFeatures"`
|
||||
|
|
|
@ -35,6 +35,7 @@ import (
|
|||
// Name of this feature source
|
||||
const Name = "local"
|
||||
|
||||
// LabelFeature of this feature source
|
||||
const LabelFeature = "label"
|
||||
|
||||
// Config
|
||||
|
|
|
@ -34,7 +34,10 @@ import (
|
|||
// Name of this feature source
|
||||
const Name = "memory"
|
||||
|
||||
// NvFeature is the name of the feature set that holds all discovered NVDIMM devices.
|
||||
const NvFeature = "nv"
|
||||
|
||||
// NumaFeature is the name of the feature set that holds all NUMA related features.
|
||||
const NumaFeature = "numa"
|
||||
|
||||
// memorySource implements the FeatureSource and LabelSource interfaces.
|
||||
|
|
|
@ -30,8 +30,10 @@ import (
|
|||
// Name of this feature source
|
||||
const Name = "pci"
|
||||
|
||||
// DeviceFeature is the name of the feature set that holds all discovered PCI devices.
|
||||
const DeviceFeature = "device"
|
||||
|
||||
// Config holds the configuration parameters of this source.
|
||||
type Config struct {
|
||||
DeviceClassWhitelist []string `json:"deviceClassWhitelist,omitempty"`
|
||||
DeviceLabelFields []string `json:"deviceLabelFields,omitempty"`
|
||||
|
|
Loading…
Add table
Reference in a new issue