mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
Merge pull request #1574 from ozhuraki/system-vendor
source/system: Add reading vendor information
This commit is contained in:
commit
2914bff8b3
3 changed files with 32 additions and 0 deletions
|
@ -979,6 +979,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.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 |
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue