diff --git a/docs/usage/customization-guide.md b/docs/usage/customization-guide.md index 6fecdb8055..0df20a61d7 100644 --- a/docs/usage/customization-guide.md +++ b/docs/usage/customization-guide.md @@ -979,6 +979,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.dmiid`** | attribute | | | DMI identification data from `/sys/devices/virtual/dmi/id/` | +| | | **`sys_vendor`** | 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..7ef4dd56c5 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.dmiid: + elements: + sys_vendor: VendorUnknown flags: cpu.cpuid: elements: diff --git a/source/system/system.go b/source/system/system.go index 1a5c5aa7ec..e1cfaff62c 100644 --- a/source/system/system.go +++ b/source/system/system.go @@ -43,6 +43,7 @@ const Name = "system" const ( OsReleaseFeature = "osrelease" NameFeature = "name" + DmiIdFeature = "dmiid" ) // systemSource implements the FeatureSource and LabelSource interfaces. @@ -101,6 +102,22 @@ func (s *systemSource) Discover() error { } } + // Get DMI ID attributes + dmiIDAttributeNames := []string{"sys_vendor"} + dmiAttrs := make(map[string]string) + for _, name := range dmiIDAttributeNames { + val, err := getDmiIDAttribute(name) + if err != nil { + klog.ErrorS(err, "failed to get DMI entry", "attributeName", name) + } else { + dmiAttrs[name] = val + } + } + + if len(dmiAttrs) > 0 { + s.features.Attributes[DmiIdFeature] = nfdv1alpha1.NewAttributeFeatures(dmiAttrs) + } + klog.V(3).InfoS("discovered features", "featureSource", s.Name(), "features", utils.DelayedDumper(s.features)) return nil @@ -153,6 +170,16 @@ func splitVersion(version string) map[string]string { return components } +// Read /sys/devices/virtual/dmi/id attribute +func getDmiIDAttribute(name string) (string, error) { + s, err := os.ReadFile(hostpath.SysfsDir.Path("devices/virtual/dmi/id/", name)) + if err != nil { + return "", err + } + + return strings.TrimSpace(string(s)), nil +} + func init() { source.Register(&src) }