mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-31 04:04:51 +00:00
Merge d6a7238709
into 242a4f439f
This commit is contained in:
commit
7d31bbd0b0
1 changed files with 33 additions and 0 deletions
|
@ -263,9 +263,42 @@ func getCPUModel() map[string]string {
|
|||
cpuModelInfo["family"] = strconv.Itoa(cpuid.CPU.Family)
|
||||
cpuModelInfo["id"] = strconv.Itoa(cpuid.CPU.Model)
|
||||
|
||||
hypervisor, err := getHypervisor()
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "failed to detect hypervisor")
|
||||
} else if hypervisor != "" {
|
||||
cpuModelInfo["hypervisor"] = hypervisor
|
||||
}
|
||||
|
||||
return cpuModelInfo
|
||||
}
|
||||
|
||||
// getHypervisor detects the hypervisor on s390x by reading /proc/sysinfo.
|
||||
// If the file does not exist, it returns an empty string with no error.
|
||||
func getHypervisor() (string, error) {
|
||||
if _, err := os.Stat("/proc/sysinfo"); os.IsNotExist(err) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
data, err := os.ReadFile("/proc/sysinfo")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
hypervisor := "PR/SM"
|
||||
for _, line := range strings.Split(string(data), "\n") {
|
||||
if strings.Contains(line, "Control Program:") {
|
||||
parts := strings.SplitN(line, ":", 2)
|
||||
if len(parts) == 2 {
|
||||
hypervisor = strings.TrimSpace(parts[1])
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return hypervisor, nil
|
||||
}
|
||||
|
||||
func discoverTopology() map[string]string {
|
||||
features := make(map[string]string)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue