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: migrate to structured logging

The custom.d config file parsing is made a bit less verbose.
This commit is contained in:
Markus Lehtonen 2023-05-16 20:26:18 +03:00
parent 4947ebf336
commit fe267a634b
20 changed files with 81 additions and 87 deletions

View file

@ -34,7 +34,7 @@ func discoverCoprocessor() map[string]string {
_, err := os.Stat(nxGzipPath)
if err != nil {
klog.V(5).Infof("Failed to detect nx_gzip for Nest Accelerator: %v", err)
klog.V(5).ErrorS(err, "Failed to detect nx_gzip for Nest Accelerator")
} else {
features["nx_gzip"] = strconv.FormatBool(true)
}

View file

@ -17,6 +17,7 @@ limitations under the License.
package cpu
import (
"fmt"
"os"
"strconv"
@ -130,7 +131,7 @@ func (s *cpuSource) SetConfig(conf source.Config) {
s.config = v
s.initCpuidFilter()
default:
klog.Fatalf("invalid config type: %T", conf)
panic(fmt.Sprintf("invalid config type: %T", conf))
}
}
@ -228,7 +229,7 @@ func (s *cpuSource) Discover() error {
// Detect cstate configuration
cstate, err := detectCstate()
if err != nil {
klog.Errorf("failed to detect cstate: %v", err)
klog.ErrorS(err, "failed to detect cstate")
} else {
s.features.Attributes[CstateFeature] = nfdv1alpha1.NewAttributeFeatures(cstate)
}
@ -236,7 +237,7 @@ func (s *cpuSource) Discover() error {
// Detect pstate features
pstate, err := detectPstate()
if err != nil {
klog.Error(err)
klog.ErrorS(err, "failed to detect pstate")
}
s.features.Attributes[PstateFeature] = nfdv1alpha1.NewAttributeFeatures(pstate)
@ -295,7 +296,7 @@ func discoverTopology() map[string]string {
features := make(map[string]string)
if ht, err := haveThreadSiblings(); err != nil {
klog.Errorf("failed to detect hyper-threading: %v", err)
klog.ErrorS(err, "failed to detect hyper-threading")
} else {
features["hardware_multithreading"] = strconv.FormatBool(ht)
}

View file

@ -39,7 +39,7 @@ func detectCstate() (map[string]string, error) {
}
cpuidleDir := filepath.Join(sysfsBase, "cpuidle")
if _, err := os.Stat(cpuidleDir); os.IsNotExist(err) {
klog.V(1).Info("cpuidle disabled in the kernel")
klog.V(1).InfoS("cpuidle disabled in the kernel")
return cstate, nil
}
@ -51,7 +51,7 @@ func detectCstate() (map[string]string, error) {
if d := strings.TrimSpace(string(driver)); d != "intel_idle" {
// Currently only checking intel_idle driver for cstates
klog.V(1).Infof("intel_idle driver is not in use (%s is active)", d)
klog.V(1).InfoS("intel_idle driver is not in use", "currentIdleDriver", d)
return cstate, nil
}

View file

@ -37,7 +37,7 @@ func discoverSST() map[string]string {
features := make(map[string]string)
if bf, err := discoverSSTBF(); err != nil {
klog.Errorf("failed to detect SST-BF: %v", err)
klog.ErrorS(err, "failed to detect SST-BF")
} else if bf {
features["bf.enabled"] = strconv.FormatBool(bf)
}

View file

@ -17,7 +17,6 @@ limitations under the License.
package cpu
import (
"fmt"
"os"
"path/filepath"
"strings"
@ -32,23 +31,23 @@ func detectPstate() (map[string]string, error) {
// Check that sysfs is available
sysfsBase := hostpath.SysfsDir.Path("devices/system/cpu")
if _, err := os.Stat(sysfsBase); err != nil {
return nil, fmt.Errorf("unable to detect pstate status: %w", err)
return nil, err
}
pstateDir := filepath.Join(sysfsBase, "intel_pstate")
if _, err := os.Stat(pstateDir); os.IsNotExist(err) {
klog.V(1).Info("intel pstate driver not enabled")
klog.V(1).InfoS("intel pstate driver not enabled")
return nil, nil
}
// Get global pstate status
data, err := os.ReadFile(filepath.Join(pstateDir, "status"))
if err != nil {
return nil, fmt.Errorf("could not read pstate status: %w", err)
return nil, err
}
status := strings.TrimSpace(string(data))
if status == "off" {
// No need to check other pstate features
klog.Infof("intel_pstate driver is not in use")
klog.InfoS("intel_pstate driver is not in use")
return nil, nil
}
features := map[string]string{"status": status}
@ -56,7 +55,7 @@ func detectPstate() (map[string]string, error) {
// Check turbo boost
bytes, err := os.ReadFile(filepath.Join(pstateDir, "no_turbo"))
if err != nil {
klog.Errorf("can't detect whether turbo boost is enabled: %s", err.Error())
klog.ErrorS(err, "can't detect whether turbo boost is enabled")
} else {
features["turbo"] = "false"
if bytes[0] == byte('0') {
@ -73,7 +72,7 @@ func detectPstate() (map[string]string, error) {
cpufreqDir := filepath.Join(sysfsBase, "cpufreq")
policies, err := os.ReadDir(cpufreqDir)
if err != nil {
klog.Errorf("failed to read cpufreq directory: %s", err.Error())
klog.ErrorS(err, "failed to read cpufreq directory")
return features, nil
}
@ -82,23 +81,23 @@ func detectPstate() (map[string]string, error) {
// Ensure at least one cpu is using this policy
cpus, err := os.ReadFile(filepath.Join(cpufreqDir, policy.Name(), "affected_cpus"))
if err != nil {
klog.Errorf("could not read cpufreq policy %s affected_cpus", policy.Name())
klog.InfoS("could not read cpufreq affected_cpus", "cpufreqPolicyName", policy.Name())
continue
}
if strings.TrimSpace(string(cpus)) == "" {
klog.Infof("policy %s has no associated cpus", policy.Name())
klog.InfoS("cpufreq policy has no associated cpus", "cpufreqPolicyName", policy.Name())
continue
}
data, err := os.ReadFile(filepath.Join(cpufreqDir, policy.Name(), "scaling_governor"))
if err != nil {
klog.Errorf("could not read cpufreq policy %s scaling_governor", policy.Name())
klog.InfoS("could not read cpufreq scaling_governor", "cpufreqPolicyName", policy.Name())
continue
}
policy_scaling := strings.TrimSpace(string(data))
// Check that all of the policies have the same scaling governor, if not don't set feature
if scaling != "" && scaling != policy_scaling {
klog.Infof("scaling_governor for policy %s doesn't match prior policy", policy.Name())
klog.InfoS("scaling_governor for cpufreq policy doesn't match prior policy", "cpufreqPolicyName", policy.Name())
scaling = ""
break
}

View file

@ -112,19 +112,19 @@ func getNumClosID(level string) int64 {
closidFile := filepath.Join(resctrlRootDir, "info", level, "num_closids")
if _, err := os.Stat(closidFile); err != nil {
klog.V(4).ErrorS(err, "failed to stat file", "fileName", closidFile)
klog.V(4).ErrorS(err, "failed to stat file", "path", closidFile)
return -1
}
closidsBytes, err := os.ReadFile(filepath.Join(resctrlRootDir, "info", level, "num_closids"))
if err != nil {
klog.V(4).ErrorS(err, "failed to read file", "fileName", closidFile)
klog.V(4).ErrorS(err, "failed to read file", "path", closidFile)
return -1
}
numClosIDs, err := strconv.ParseInt(string(bytes.TrimSpace(closidsBytes)), 10, 64)
if err != nil {
klog.V(4).ErrorS(err, "failed to ParseInt", "num_closids", string(bytes.TrimSpace(closidsBytes)))
klog.V(4).ErrorS(err, "failed to parse num_closids", "value", string(bytes.TrimSpace(closidsBytes)))
return -1
}

View file

@ -97,7 +97,7 @@ func (s *customSource) SetConfig(conf source.Config) {
case *config:
s.config = v
default:
klog.Fatalf("invalid config type: %T", conf)
panic(fmt.Sprintf("invalid config type: %T", conf))
}
}
@ -117,7 +117,7 @@ func (s *customSource) GetLabels() (source.FeatureLabels, error) {
for _, rule := range allFeatureConfig {
ruleOut, err := rule.execute(features)
if err != nil {
klog.Error(err)
klog.ErrorS(err, "failed to execute rule")
continue
}

View file

@ -32,20 +32,20 @@ const Directory = "/etc/kubernetes/node-feature-discovery/custom.d"
// host directory and its 1st level subdirectories, which can be populated e.g. by ConfigMaps
func getDirectoryFeatureConfig() []CustomRule {
features := readDir(Directory, true)
klog.V(1).Infof("all configmap based custom feature specs: %+v", features)
klog.V(3).InfoS("all custom feature specs from config dir", "featureSpecs", features)
return features
}
func readDir(dirName string, recursive bool) []CustomRule {
features := make([]CustomRule, 0)
klog.V(1).Infof("getting files in %s", dirName)
klog.V(4).InfoS("reading directory", "path", dirName)
files, err := os.ReadDir(dirName)
if err != nil {
if os.IsNotExist(err) {
klog.V(1).Infof("custom config directory %q does not exist", dirName)
klog.V(4).InfoS("directory does not exist", "path", dirName)
} else {
klog.Errorf("unable to access custom config directory %q, %v", dirName, err)
klog.ErrorS(err, "unable to access directory", "path", dirName)
}
return features
}
@ -55,30 +55,29 @@ func readDir(dirName string, recursive bool) []CustomRule {
if file.IsDir() {
if recursive {
klog.V(1).Infof("processing dir %q", fileName)
klog.V(4).InfoS("processing directory", "path", fileName)
features = append(features, readDir(fileName, false)...)
} else {
klog.V(2).Infof("skipping dir %q", fileName)
klog.V(4).InfoS("skipping directory", "path", fileName)
}
continue
}
if strings.HasPrefix(file.Name(), ".") {
klog.V(2).Infof("skipping hidden file %q", fileName)
klog.V(4).InfoS("skipping hidden file", "path", fileName)
continue
}
klog.V(2).Infof("processing file %q", fileName)
klog.V(4).InfoS("processing file", "path", fileName)
bytes, err := os.ReadFile(fileName)
if err != nil {
klog.Errorf("could not read custom config file %q, %v", fileName, err)
klog.ErrorS(err, "could not read file", "path", fileName)
continue
}
klog.V(2).Infof("custom config rules raw: %s", string(bytes))
config := &[]CustomRule{}
err = yaml.UnmarshalStrict(bytes, config)
if err != nil {
klog.Errorf("could not parse custom config file %q, %v", fileName, err)
klog.ErrorS(err, "could not parse file", "path", fileName)
continue
}

View file

@ -17,6 +17,7 @@ limitations under the License.
package kernel
import (
"fmt"
"strconv"
"k8s.io/klog/v2"
@ -87,7 +88,7 @@ func (s *kernelSource) SetConfig(conf source.Config) {
case *Config:
s.config = v
default:
klog.Fatalf("invalid config type: %T", conf)
panic(fmt.Sprintf("invalid config type: %T", conf))
}
}
@ -122,7 +123,7 @@ func (s *kernelSource) Discover() error {
// Read kernel version
if version, err := parseVersion(); err != nil {
klog.Errorf("failed to get kernel version: %s", err)
klog.ErrorS(err, "failed to get kernel version")
} else {
s.features.Attributes[VersionFeature] = nfdv1alpha1.NewAttributeFeatures(version)
}
@ -130,7 +131,7 @@ func (s *kernelSource) Discover() error {
// Read kconfig
if realKconfig, legacyKconfig, err := parseKconfig(s.config.KconfigFile); err != nil {
s.legacyKconfig = nil
klog.Errorf("failed to read kconfig: %s", err)
klog.ErrorS(err, "failed to read kconfig")
} else {
s.features.Attributes[ConfigFeature] = nfdv1alpha1.NewAttributeFeatures(realKconfig)
s.legacyKconfig = legacyKconfig
@ -138,21 +139,21 @@ func (s *kernelSource) Discover() error {
var enabledModules []string
if kmods, err := getLoadedModules(); err != nil {
klog.Errorf("failed to get loaded kernel modules: %v", err)
klog.ErrorS(err, "failed to get loaded kernel modules")
} else {
enabledModules = append(enabledModules, kmods...)
s.features.Flags[LoadedModuleFeature] = nfdv1alpha1.NewFlagFeatures(kmods...)
}
if builtinMods, err := getBuiltinModules(); err != nil {
klog.Errorf("failed to get builtin kernel modules: %v", err)
klog.ErrorS(err, "failed to get builtin kernel modules")
} else {
enabledModules = append(enabledModules, builtinMods...)
s.features.Flags[EnabledModuleFeature] = nfdv1alpha1.NewFlagFeatures(enabledModules...)
}
if selinux, err := SelinuxEnabled(); err != nil {
klog.Warning(err)
klog.ErrorS(err, "failed to detect selinux status")
} else {
s.features.Attributes[SelinuxFeature] = nfdv1alpha1.NewAttributeFeatures(nil)
s.features.Attributes[SelinuxFeature].Elements["enabled"] = strconv.FormatBool(selinux)

View file

@ -17,7 +17,6 @@ limitations under the License.
package kernel
import (
"fmt"
"os"
"path/filepath"
@ -30,18 +29,18 @@ import (
func SelinuxEnabled() (bool, error) {
sysfsBase := hostpath.SysfsDir.Path("fs")
if _, err := os.Stat(sysfsBase); err != nil {
return false, fmt.Errorf("unable to detect selinux status: %w", err)
return false, err
}
selinuxBase := filepath.Join(sysfsBase, "selinux")
if _, err := os.Stat(selinuxBase); os.IsNotExist(err) {
klog.V(1).Info("selinux not available on the system")
klog.V(1).InfoS("selinux not available on the system")
return false, nil
}
status, err := os.ReadFile(filepath.Join(selinuxBase, "enforce"))
if err != nil {
return false, fmt.Errorf("failed to detect the status of selinux: %w", err)
return false, err
}
if status[0] == byte('1') {
// selinux is enabled.

View file

@ -76,7 +76,7 @@ func (s *localSource) SetConfig(conf source.Config) {
case *Config:
s.config = v
default:
klog.Fatalf("invalid config type: %T", conf)
panic(fmt.Sprintf("invalid config type: %T", conf))
}
}
@ -107,23 +107,22 @@ func (s *localSource) Discover() error {
featuresFromFiles, err := getFeaturesFromFiles()
if err != nil {
klog.Error(err)
klog.ErrorS(err, "failed to read feature files")
}
if s.config.HooksEnabled {
klog.Info("starting hooks...")
klog.InfoS("starting hooks...")
featuresFromHooks, err := getFeaturesFromHooks()
if err != nil {
klog.Error(err)
klog.ErrorS(err, "failed to run hooks")
}
// Merge features from hooks and files
for k, v := range featuresFromHooks {
if old, ok := featuresFromFiles[k]; ok {
klog.Warningf("overriding '%s': value changed from '%s' to '%s'",
k, old, v)
klog.InfoS("overriding label value", "labelKey", k, "oldValue", old, "newValue", v)
}
featuresFromFiles[k] = v
}
@ -173,20 +172,20 @@ func getFeaturesFromHooks() (map[string]string, error) {
files, err := os.ReadDir(hookDir)
if err != nil {
if os.IsNotExist(err) {
klog.Infof("hook directory %v does not exist", hookDir)
klog.InfoS("hook directory does not exist", "path", hookDir)
return features, nil
}
return features, fmt.Errorf("unable to access %v: %v", hookDir, err)
}
if len(files) > 0 {
klog.Warning("hooks are DEPRECATED since v0.12.0 and support will be removed in a future release; use feature files instead")
klog.InfoS("hooks are DEPRECATED since v0.12.0 and support will be removed in a future release; use feature files instead")
}
for _, file := range files {
fileName := file.Name()
lines, err := runHook(fileName)
if err != nil {
klog.Errorf("source local failed running hook '%v': %v", fileName, err)
klog.ErrorS(err, "failed to run hook", "fileName", fileName)
continue
}
@ -195,8 +194,7 @@ func getFeaturesFromHooks() (map[string]string, error) {
utils.KlogDump(4, fmt.Sprintf("features from hook %q:", fileName), " ", fileFeatures)
for k, v := range fileFeatures {
if old, ok := features[k]; ok {
klog.Warningf("overriding label '%s' from another hook (%s): value changed from '%s' to '%s'",
k, fileName, old, v)
klog.InfoS("overriding label value from another hook", "labelKey", k, "oldValue", old, "newValue", v, "fileName", fileName)
}
features[k] = v
}
@ -212,7 +210,7 @@ func runHook(file string) ([][]byte, error) {
path := filepath.Join(hookDir, file)
filestat, err := os.Stat(path)
if err != nil {
klog.Errorf("skipping %v, failed to get stat: %v", path, err)
klog.ErrorS(err, "failed to get filestat, skipping hook", "path", path)
return lines, err
}
@ -233,7 +231,7 @@ func runHook(file string) ([][]byte, error) {
// Don't print the last empty string
break
}
klog.Errorf("%v: %s", file, line)
klog.InfoS(fmt.Sprintf("%s: %s", file, line))
}
// Do not return any lines if an error occurred
@ -253,7 +251,7 @@ func getFeaturesFromFiles() (map[string]string, error) {
files, err := os.ReadDir(featureFilesDir)
if err != nil {
if os.IsNotExist(err) {
klog.Infof("features directory %v does not exist", featureFilesDir)
klog.InfoS("features directory does not exist", "path", featureFilesDir)
return features, nil
}
return features, fmt.Errorf("unable to access %v: %v", featureFilesDir, err)
@ -263,7 +261,7 @@ func getFeaturesFromFiles() (map[string]string, error) {
fileName := file.Name()
lines, err := getFileContent(fileName)
if err != nil {
klog.Errorf("source local failed reading file '%v': %v", fileName, err)
klog.ErrorS(err, "failed to read file", "fileName", fileName)
continue
}
@ -272,8 +270,7 @@ func getFeaturesFromFiles() (map[string]string, error) {
utils.KlogDump(4, fmt.Sprintf("features from feature file %q:", fileName), " ", fileFeatures)
for k, v := range fileFeatures {
if old, ok := features[k]; ok {
klog.Warningf("overriding label '%s' from another features.d file (%s): value changed from '%s' to '%s'",
k, fileName, old, v)
klog.InfoS("overriding label value from another feature file", "labelKey", k, "oldValue", old, "newValue", v, "fileName", fileName)
}
features[k] = v
}
@ -289,7 +286,7 @@ func getFileContent(fileName string) ([][]byte, error) {
path := filepath.Join(featureFilesDir, fileName)
filestat, err := os.Stat(path)
if err != nil {
klog.Errorf("skipping %v, failed to get stat: %v", path, err)
klog.ErrorS(err, "failed to get filestat, skipping features file", "path", path)
return lines, err
}

View file

@ -88,14 +88,14 @@ func (s *memorySource) Discover() error {
// Detect NUMA
if numa, err := detectNuma(); err != nil {
klog.Errorf("failed to detect NUMA nodes: %v", err)
klog.ErrorS(err, "failed to detect NUMA nodes")
} else {
s.features.Attributes[NumaFeature] = nfdv1alpha1.AttributeFeatureSet{Elements: numa}
}
// Detect NVDIMM
if nv, err := detectNv(); err != nil {
klog.Errorf("failed to detect nvdimm devices: %v", err)
klog.ErrorS(err, "failed to detect nvdimm devices")
} else {
s.features.Instances[NvFeature] = nfdv1alpha1.InstanceFeatureSet{Elements: nv}
}
@ -135,7 +135,7 @@ func detectNv() ([]nfdv1alpha1.InstanceFeature, error) {
devices, err := os.ReadDir(sysfsBasePath)
if os.IsNotExist(err) {
klog.V(1).Info("No NVDIMM devices present")
klog.V(1).InfoS("No NVDIMM devices present")
return info, nil
} else if err != nil {
return nil, fmt.Errorf("failed to list nvdimm devices: %w", err)
@ -158,7 +158,7 @@ func readNdDeviceInfo(path string) nfdv1alpha1.InstanceFeature {
for _, attrName := range ndDevAttrs {
data, err := os.ReadFile(filepath.Join(path, attrName))
if err != nil {
klog.V(3).Infof("failed to read nd device attribute %s: %w", attrName, err)
klog.V(3).ErrorS(err, "failed to read nd device attribute", "attributeName", attrName)
continue
}
attrs[attrName] = strings.TrimSpace(string(data))

View file

@ -77,7 +77,7 @@ func (s *networkSource) GetLabels() (source.FeatureLabels, error) {
if v, ok := attrs[attr]; ok {
t, err := strconv.Atoi(v)
if err != nil {
klog.Errorf("failed to parse %s of %s: %v", attr, attrs["name"])
klog.ErrorS(err, "failed to parse sriov attribute", "attributeName", attr, "deviceName", attrs["name"])
continue
}
if t > 0 {
@ -126,8 +126,8 @@ func detectNetDevices() ([]nfdv1alpha1.InstanceFeature, error) {
name := iface.Name()
if _, err := os.Stat(filepath.Join(sysfsBasePath, name, "device")); err == nil {
info = append(info, readIfaceInfo(filepath.Join(sysfsBasePath, name)))
} else if klog.V(3).Enabled() {
klog.Infof("skipping non-device iface %q", name)
} else if klogV := klog.V(3); klogV.Enabled() {
klogV.InfoS("skipping non-device iface", "interfaceName", name)
}
}
@ -140,7 +140,7 @@ func readIfaceInfo(path string) nfdv1alpha1.InstanceFeature {
data, err := os.ReadFile(filepath.Join(path, attrName))
if err != nil {
if !os.IsNotExist(err) {
klog.Errorf("failed to read net iface attribute %s: %v", attrName, err)
klog.ErrorS(err, "failed to read net iface attribute", "attributeName", attrName)
}
continue
}
@ -151,7 +151,7 @@ func readIfaceInfo(path string) nfdv1alpha1.InstanceFeature {
data, err := os.ReadFile(filepath.Join(path, "device", attrName))
if err != nil {
if !os.IsNotExist(err) {
klog.Errorf("failed to read net device attribute %s: %v", attrName, err)
klog.ErrorS(err, "failed to read net device attribute", "attributeName", attrName)
}
continue
}

View file

@ -76,7 +76,7 @@ func (s *pciSource) SetConfig(conf source.Config) {
case *Config:
s.config = v
default:
klog.Fatalf("invalid config type: %T", conf)
panic(fmt.Sprintf("invalid config type: %T", conf))
}
}
@ -106,11 +106,11 @@ func (s *pciSource) GetLabels() (source.FeatureLabels, error) {
for key := range configLabelFields {
keys = append(keys, key)
}
klog.Warningf("invalid fields (%s) in deviceLabelFields, ignoring...", strings.Join(keys, ", "))
klog.InfoS("ignoring invalid fields in deviceLabelFields", "invalidFieldNames", keys)
}
if len(deviceLabelFields) == 0 {
klog.Warningf("no valid fields in deviceLabelFields defined, using the defaults")
deviceLabelFields = []string{"class", "vendor"}
klog.InfoS("no valid fields in deviceLabelFields defined, using the defaults", "defaultFieldNames", deviceLabelFields)
}
// Iterate over all device classes

View file

@ -83,7 +83,7 @@ func detectPci() ([]nfdv1alpha1.InstanceFeature, error) {
for _, device := range devices {
info, err := readPciDevInfo(filepath.Join(sysfsBasePath, device.Name()))
if err != nil {
klog.Error(err)
klog.ErrorS(err, "failed to read PCI device info")
continue
}
devInfo = append(devInfo, *info)

View file

@ -21,8 +21,6 @@ package source
import (
"fmt"
"k8s.io/klog/v2"
nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/pkg/apis/nfd/v1alpha1"
)
@ -167,7 +165,7 @@ func GetAllFeatures() *nfdv1alpha1.Features {
// Prefix feature with the name of the source
k = n + "." + k
if typ := features.Exists(k); typ != "" {
klog.Exitf("feature source %q returned flag feature %q which already exists (type %q)", n, k, typ)
panic(fmt.Sprintf("feature source %q returned flag feature %q which already exists (type %q)", n, k, typ))
}
features.Flags[k] = v
}
@ -175,7 +173,7 @@ func GetAllFeatures() *nfdv1alpha1.Features {
// Prefix feature with the name of the source
k = n + "." + k
if typ := features.Exists(k); typ != "" {
klog.Exitf("feature source %q returned attribute feature %q which already exists (type %q)", n, k, typ)
panic(fmt.Sprintf("feature source %q returned attribute feature %q which already exists (type %q)", n, k, typ))
}
features.Attributes[k] = v
}
@ -183,7 +181,7 @@ func GetAllFeatures() *nfdv1alpha1.Features {
// Prefix feature with the name of the source
k = n + "." + k
if typ := features.Exists(k); typ != "" {
klog.Exitf("feature source %q returned instance feature %q which already exists (type %q)", n, k, typ)
panic(fmt.Sprintf("feature source %q returned instance feature %q which already exists (type %q)", n, k, typ))
}
features.Instances[k] = v
}

View file

@ -116,7 +116,7 @@ func readBlockDevQueueInfo(path string) *nfdv1alpha1.InstanceFeature {
for _, attrName := range queueAttrs {
data, err := os.ReadFile(filepath.Join(path, "queue", attrName))
if err != nil {
klog.V(3).Infof("failed to read block device queue attribute %s: %w", attrName, err)
klog.V(3).ErrorS(err, "failed to read block device queue attribute", "attributeName", attrName)
continue
}
attrs[attrName] = strings.TrimSpace(string(data))

View file

@ -87,7 +87,7 @@ func (s *systemSource) Discover() error {
// Get os-release information
release, err := parseOSRelease()
if err != nil {
klog.Errorf("failed to get os-release: %s", err)
klog.ErrorS(err, "failed to get os-release")
} else {
s.features.Attributes[OsReleaseFeature] = nfdv1alpha1.NewAttributeFeatures(release)

View file

@ -79,7 +79,7 @@ func (s *usbSource) SetConfig(conf source.Config) {
case *Config:
s.config = v
default:
klog.Fatalf("invalid config type: %T", conf)
panic(fmt.Sprintf("invalid config type: %T", conf))
}
}
@ -109,11 +109,11 @@ func (s *usbSource) GetLabels() (source.FeatureLabels, error) {
for key := range configLabelFields {
keys = append(keys, key)
}
klog.Warningf("invalid fields (%s) in deviceLabelFields, ignoring...", strings.Join(keys, ", "))
klog.InfoS("ignoring invalid fields in deviceLabelFields", "invalidFieldNames", keys)
}
if len(deviceLabelFields) == 0 {
klog.Warningf("no valid fields in deviceLabelFields defined, using the defaults")
deviceLabelFields = defaultDeviceLabelFields()
klog.InfoS("no valid fields in deviceLabelFields defined, using the defaults", "defaultFieldNames", deviceLabelFields)
}
// Iterate over all device classes

View file

@ -118,7 +118,7 @@ func detectUsb() ([]nfdv1alpha1.InstanceFeature, error) {
for _, devPath := range devPaths {
devs, err := readUsbDevInfo(filepath.Dir(devPath))
if err != nil {
klog.Error(err)
klog.ErrorS(err, "failed to read USB device info")
continue
}