Skip to content

Commit

Permalink
Merge pull request #1574 from ozhuraki/system-vendor
Browse files Browse the repository at this point in the history
source/system: Add reading vendor information
  • Loading branch information
k8s-ci-robot authored Feb 19, 2024
2 parents b593e68 + 2f62aed commit 2914bff
Show file tree
Hide file tree
Showing 3 changed files with 32 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 @@ -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 |
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.dmiid:
elements:
sys_vendor: VendorUnknown
flags:
cpu.cpuid:
elements:
Expand Down
27 changes: 27 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"
DmiIdFeature = "dmiid"
)

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

0 comments on commit 2914bff

Please sign in to comment.