Skip to content

Commit

Permalink
source/system: Add reading vendor information
Browse files Browse the repository at this point in the history
Add reading vendor information from /sys/devices/virtual/dmi/id/sys_vendor

Closes #1057

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
  • Loading branch information
ozhuraki committed Jan 30, 2024
1 parent 5c99ae8 commit 933fa79
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/usage/customization-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,8 @@ The following features are available for matching:
| | | **`<sysfs-attribute>`** | string | Sysfs network interface attribute, available attributes: `dax`, `rotational`, `nr_zones`, `zoned` |
| **`system.osrelease`** | attribute | | | System identification data from `/etc/os-release` |
| | | **`<parameter>`** | 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 |
Expand Down
3 changes: 3 additions & 0 deletions examples/nodefeature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions source/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const Name = "system"
const (
OsReleaseFeature = "osrelease"
NameFeature = "name"
VendorFeature = "vendor"
)

// systemSource implements the FeatureSource and LabelSource interfaces.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

0 comments on commit 933fa79

Please sign in to comment.