mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #80486 from liyanhui1228/systemuuid
Set the systemUUID for windows nodes
This commit is contained in:
commit
70521fbf32
@ -20,8 +20,11 @@ package winstats
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
@ -136,10 +139,16 @@ func (p *perfCounterNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
systemUUID, err := getSystemUUID()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &cadvisorapi.MachineInfo{
|
||||
NumCores: runtime.NumCPU(),
|
||||
MemoryCapacity: p.nodeInfo.memoryPhysicalCapacityBytes,
|
||||
MachineID: hostname,
|
||||
SystemUUID: systemUUID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -212,6 +221,18 @@ func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 {
|
||||
return cpuUsageNanoCores
|
||||
}
|
||||
|
||||
func getSystemUUID() (string, error) {
|
||||
result, err := exec.Command("wmic", "csproduct", "get", "UUID").Output()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
fields := strings.Fields(string(result))
|
||||
if len(fields) != 2 {
|
||||
return "", fmt.Errorf("received unexpected value retrieving vm uuid: %q", string(result))
|
||||
}
|
||||
return fields[1], nil
|
||||
}
|
||||
|
||||
func getPhysicallyInstalledSystemMemoryBytes() (uint64, error) {
|
||||
// We use GlobalMemoryStatusEx instead of GetPhysicallyInstalledSystemMemory
|
||||
// on Windows node for the following reasons:
|
||||
|
@ -56,6 +56,7 @@ func (f fakeWinNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo, erro
|
||||
NumCores: 4,
|
||||
MemoryCapacity: 1.6e+10,
|
||||
MachineID: "somehostname",
|
||||
SystemUUID: "E6C8AC43-582B-3575-4E1F-6DA170888906",
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -118,7 +119,8 @@ func TestWinMachineInfo(t *testing.T) {
|
||||
assert.Equal(t, machineInfo, &cadvisorapi.MachineInfo{
|
||||
NumCores: 4,
|
||||
MemoryCapacity: 1.6e+10,
|
||||
MachineID: "somehostname"})
|
||||
MachineID: "somehostname",
|
||||
SystemUUID: "E6C8AC43-582B-3575-4E1F-6DA170888906"})
|
||||
}
|
||||
|
||||
func TestWinVersionInfo(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user