mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
add bootid support for windows node.
Signed-off-by: MartinForReal <fanshangxiang@gmail.com>
This commit is contained in:
parent
02b1ec5b0b
commit
d529b7e10b
@ -25,6 +25,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -33,10 +34,16 @@ import (
|
|||||||
|
|
||||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
|
"golang.org/x/sys/windows/registry"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
bootIdRegistry = `SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters`
|
||||||
|
bootIdKey = `BootId`
|
||||||
|
)
|
||||||
|
|
||||||
// MemoryStatusEx is the same as Windows structure MEMORYSTATUSEX
|
// MemoryStatusEx is the same as Windows structure MEMORYSTATUSEX
|
||||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa366770(v=vs.85).aspx
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa366770(v=vs.85).aspx
|
||||||
type MemoryStatusEx struct {
|
type MemoryStatusEx struct {
|
||||||
@ -144,11 +151,17 @@ func (p *perfCounterNodeStatsClient) getMachineInfo() (*cadvisorapi.MachineInfo,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bootId, err := getBootID()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &cadvisorapi.MachineInfo{
|
return &cadvisorapi.MachineInfo{
|
||||||
NumCores: processorCount(),
|
NumCores: processorCount(),
|
||||||
MemoryCapacity: p.nodeInfo.memoryPhysicalCapacityBytes,
|
MemoryCapacity: p.nodeInfo.memoryPhysicalCapacityBytes,
|
||||||
MachineID: hostname,
|
MachineID: hostname,
|
||||||
SystemUUID: systemUUID,
|
SystemUUID: systemUUID,
|
||||||
|
BootID: bootId,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,3 +288,16 @@ func getPhysicallyInstalledSystemMemoryBytes() (uint64, error) {
|
|||||||
|
|
||||||
return statex.TotalPhys, nil
|
return statex.TotalPhys, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBootID() (string, error) {
|
||||||
|
regKey, err := registry.OpenKey(registry.LOCAL_MACHINE, bootIdRegistry, registry.READ)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
defer regKey.Close()
|
||||||
|
regValue, _, err := regKey.GetIntegerValue(bootIdKey)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return strconv.FormatUint(regValue, 10), nil
|
||||||
|
}
|
||||||
|
@ -39,6 +39,7 @@ var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats [Serial]", func() {
|
|||||||
f := framework.NewDefaultFramework("kubelet-stats-test-windows-serial")
|
f := framework.NewDefaultFramework("kubelet-stats-test-windows-serial")
|
||||||
|
|
||||||
ginkgo.Describe("Kubelet stats collection for Windows nodes", func() {
|
ginkgo.Describe("Kubelet stats collection for Windows nodes", func() {
|
||||||
|
|
||||||
ginkgo.Context("when running 10 pods", func() {
|
ginkgo.Context("when running 10 pods", func() {
|
||||||
// 10 seconds is the default scrape timeout for metrics-server and kube-prometheus
|
// 10 seconds is the default scrape timeout for metrics-server and kube-prometheus
|
||||||
ginkgo.It("should return within 10 seconds", func() {
|
ginkgo.It("should return within 10 seconds", func() {
|
||||||
@ -113,6 +114,19 @@ var _ = SIGDescribe("[Feature:Windows] Kubelet-Stats", func() {
|
|||||||
f := framework.NewDefaultFramework("kubelet-stats-test-windows")
|
f := framework.NewDefaultFramework("kubelet-stats-test-windows")
|
||||||
|
|
||||||
ginkgo.Describe("Kubelet stats collection for Windows nodes", func() {
|
ginkgo.Describe("Kubelet stats collection for Windows nodes", func() {
|
||||||
|
|
||||||
|
ginkgo.Context("when windows is booted", func() {
|
||||||
|
ginkgo.It("should return bootid within 10 seconds", func() {
|
||||||
|
ginkgo.By("Selecting a Windows node")
|
||||||
|
targetNode, err := findWindowsNode(f)
|
||||||
|
framework.ExpectNoError(err, "Error finding Windows node")
|
||||||
|
framework.Logf("Using node: %v", targetNode.Name)
|
||||||
|
|
||||||
|
ginkgo.By("Getting bootid")
|
||||||
|
framework.ExpectEqual(len(targetNode.Status.NodeInfo.BootID) != 0, true, "Should find bootId in kubelet stats")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
ginkgo.Context("when running 3 pods", func() {
|
ginkgo.Context("when running 3 pods", func() {
|
||||||
// 10 seconds is the default scrape timeout for metrics-server and kube-prometheus
|
// 10 seconds is the default scrape timeout for metrics-server and kube-prometheus
|
||||||
ginkgo.It("should return within 10 seconds", func() {
|
ginkgo.It("should return within 10 seconds", func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user