Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source/system: Add reading vendor information #1574

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (
OsReleaseFeature = "osrelease"
NameFeature = "name"
DmiIdFeature = "dmiid"
)

// systemSource implements the FeatureSource and LabelSource interfaces.
Expand Down Expand Up @@ -101,6 +102,22 @@
}
}

// 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
}

Check warning on line 114 in source/system/system.go

View check run for this annotation

Codecov / codecov/patch

source/system/system.go#L106-L114

Added lines #L106 - L114 were not covered by tests
}

if len(dmiAttrs) > 0 {
s.features.Attributes[DmiIdFeature] = nfdv1alpha1.NewAttributeFeatures(dmiAttrs)
}

Check warning on line 119 in source/system/system.go

View check run for this annotation

Codecov / codecov/patch

source/system/system.go#L117-L119

Added lines #L117 - L119 were not covered by tests

klog.V(3).InfoS("discovered features", "featureSource", s.Name(), "features", utils.DelayedDumper(s.features))

return nil
Expand Down Expand Up @@ -153,6 +170,16 @@
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
}

Check warning on line 178 in source/system/system.go

View check run for this annotation

Codecov / codecov/patch

source/system/system.go#L174-L178

Added lines #L174 - L178 were not covered by tests

return strings.TrimSpace(string(s)), nil

Check warning on line 180 in source/system/system.go

View check run for this annotation

Codecov / codecov/patch

source/system/system.go#L180

Added line #L180 was not covered by tests
}

func init() {
source.Register(&src)
}