mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50: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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
@ -136,10 +139,16 @@ func (p *perfCounterNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
systemUUID, err := getSystemUUID()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &cadvisorapi.MachineInfo{
|
return &cadvisorapi.MachineInfo{
|
||||||
NumCores: runtime.NumCPU(),
|
NumCores: runtime.NumCPU(),
|
||||||
MemoryCapacity: p.nodeInfo.memoryPhysicalCapacityBytes,
|
MemoryCapacity: p.nodeInfo.memoryPhysicalCapacityBytes,
|
||||||
MachineID: hostname,
|
MachineID: hostname,
|
||||||
|
SystemUUID: systemUUID,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,6 +221,18 @@ func (p *perfCounterNodeStatsClient) getCPUUsageNanoCores() uint64 {
|
|||||||
return cpuUsageNanoCores
|
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) {
|
func getPhysicallyInstalledSystemMemoryBytes() (uint64, error) {
|
||||||
// We use GlobalMemoryStatusEx instead of GetPhysicallyInstalledSystemMemory
|
// We use GlobalMemoryStatusEx instead of GetPhysicallyInstalledSystemMemory
|
||||||
// on Windows node for the following reasons:
|
// on Windows node for the following reasons:
|
||||||
|
@ -56,6 +56,7 @@ func (f fakeWinNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo, erro
|
|||||||
NumCores: 4,
|
NumCores: 4,
|
||||||
MemoryCapacity: 1.6e+10,
|
MemoryCapacity: 1.6e+10,
|
||||||
MachineID: "somehostname",
|
MachineID: "somehostname",
|
||||||
|
SystemUUID: "E6C8AC43-582B-3575-4E1F-6DA170888906",
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +119,8 @@ func TestWinMachineInfo(t *testing.T) {
|
|||||||
assert.Equal(t, machineInfo, &cadvisorapi.MachineInfo{
|
assert.Equal(t, machineInfo, &cadvisorapi.MachineInfo{
|
||||||
NumCores: 4,
|
NumCores: 4,
|
||||||
MemoryCapacity: 1.6e+10,
|
MemoryCapacity: 1.6e+10,
|
||||||
MachineID: "somehostname"})
|
MachineID: "somehostname",
|
||||||
|
SystemUUID: "E6C8AC43-582B-3575-4E1F-6DA170888906"})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWinVersionInfo(t *testing.T) {
|
func TestWinVersionInfo(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user