From 933fa79c05d1fe1d76e97e101e59fe9320e0fcfe Mon Sep 17 00:00:00 2001 From: Oleg Zhurakivskyy Date: Tue, 30 Jan 2024 13:29:12 +0200 Subject: [PATCH] source/system: Add reading vendor information Add reading vendor information from /sys/devices/virtual/dmi/id/sys_vendor Closes #1057 Signed-off-by: Oleg Zhurakivskyy --- docs/usage/customization-guide.md | 2 ++ examples/nodefeature.yaml | 3 +++ source/system/system.go | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/docs/usage/customization-guide.md b/docs/usage/customization-guide.md index 86be11269a..2e654abd92 100644 --- a/docs/usage/customization-guide.md +++ b/docs/usage/customization-guide.md @@ -976,6 +976,8 @@ The following features are available for matching: | | | **``** | string | Sysfs network interface attribute, available attributes: `dax`, `rotational`, `nr_zones`, `zoned` | | **`system.osrelease`** | attribute | | | System identification data from `/etc/os-release` | | | | **``** | string | One parameter from `/etc/os-release` | +| **`system.vendor`** | attribute | | | System vendor identification data from `/sys/devices/virtual/dmi/id/` | +| | | **`name`** | string | Vendor name from `/sys/devices/virtual/dmi/id/sys_vendor` | | **`system.name`** | attribute | | | System name information | | | | **`nodename`** | string | Name of the kubernetes node object | | **`usb.device`** | instance | | | USB devices present in the system | diff --git a/examples/nodefeature.yaml b/examples/nodefeature.yaml index 3048d48f0c..589d2e01da 100644 --- a/examples/nodefeature.yaml +++ b/examples/nodefeature.yaml @@ -65,6 +65,9 @@ spec: VERSION_ID: "22.04" VERSION_ID.major: "22" VERSION_ID.minor: "04" + system.vendor: + elements: + name: VendorUnknown flags: cpu.cpuid: elements: diff --git a/source/system/system.go b/source/system/system.go index 1a5c5aa7ec..5c29f4bee6 100644 --- a/source/system/system.go +++ b/source/system/system.go @@ -43,6 +43,7 @@ const Name = "system" const ( OsReleaseFeature = "osrelease" NameFeature = "name" + VendorFeature = "vendor" ) // systemSource implements the FeatureSource and LabelSource interfaces. @@ -101,6 +102,14 @@ func (s *systemSource) Discover() error { } } + // Get vendor information + vendor, err := getVendor() + if err != nil { + klog.ErrorS(err, "failed to get vendor") + } else { + s.features.Attributes[VendorFeature].Elements["name"] = vendor + } + klog.V(3).InfoS("discovered features", "featureSource", s.Name(), "features", utils.DelayedDumper(s.features)) return nil @@ -153,6 +162,16 @@ func splitVersion(version string) map[string]string { return components } +// Read /sys/devices/virtual/dmi/id/sys_vendor +func getVendor() (string, error) { + vendor, err := os.ReadFile("/sys/devices/virtual/dmi/id/sys_vendor") + if err != nil { + return "", err + } + + return strings.TrimSpace(string(vendor)), nil +} + func init() { source.Register(&src) }