Skip to content

Commit

Permalink
Merge pull request kubernetes#55496 from JiangtianLi/jiangtli-fixserv…
Browse files Browse the repository at this point in the history
…ercore

Automatic merge from submit-queue (batch tested with PRs 55642, 55897, 55835, 55496, 55313). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Fix issue kubernetes#55031 to remove dependence on package lxn/win

**What this PR does / why we need it**:
This PR fixes issue kubernetes#55031 where kubelet.exe crashes on Windows Server Core. The root cause is that kubelet.exe depends on package lxn/win pdh and kernel32 wrapper for node metrics. However, opengl32.dll is not available in Server Core and lxn/win requires the presence of all win32 DLLs. 

This PR uses a slim win32 package JeffAshton/win_pdh since most win32 APIs needed are PDH API. Also this PR makes own implementation of GetPhysicallyInstalledSystemMemory until golang Windows syscall has it or lxn/win fixes opengl32 issue. Also this PR modifies the way to get Windows version.

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes kubernetes#55031

**Special notes for your reviewer**:

**Release note**:

```release-note

```
/sig windows
/sig node
  • Loading branch information
Kubernetes Submit Queue authored Nov 18, 2017
2 parents 941c6aa + 5fe8757 commit 786c69d
Show file tree
Hide file tree
Showing 48 changed files with 152 additions and 10,110 deletions.
8 changes: 4 additions & 4 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 31 additions & 31 deletions Godeps/LICENSES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/kubelet/winstats/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ go_library(
"//vendor/github.com/google/cadvisor/info/v2:go_default_library",
] + select({
"@io_bazel_rules_go//go/platform:windows_amd64": [
"//vendor/github.com/JeffAshton/win_pdh:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/lxn/win:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
],
"//conditions:default": [],
Expand Down
19 changes: 17 additions & 2 deletions pkg/kubelet/winstats/perfcounter_nodestats.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,20 @@ import (
"runtime"
"strings"
"sync"
"syscall"
"time"
"unsafe"

"github.com/golang/glog"
cadvisorapi "github.com/google/cadvisor/info/v1"
"github.com/lxn/win"
"k8s.io/apimachinery/pkg/util/wait"
)

var (
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
procGetPhysicallyInstalledSystemMemory = modkernel32.NewProc("GetPhysicallyInstalledSystemMemory")
)

// NewPerfCounterClient creates a client using perf counters
func NewPerfCounterClient() (Client, error) {
return newClient(&perfCounterNodeStatsClient{})
Expand Down Expand Up @@ -158,9 +164,18 @@ func (p *perfCounterNodeStatsClient) convertCPUValue(cpuValue uint64) uint64 {
func getPhysicallyInstalledSystemMemoryBytes() (uint64, error) {
var physicalMemoryKiloBytes uint64

if ok := win.GetPhysicallyInstalledSystemMemory(&physicalMemoryKiloBytes); !ok {
if ok := getPhysicallyInstalledSystemMemory(&physicalMemoryKiloBytes); !ok {
return 0, errors.New("unable to read physical memory")
}

return physicalMemoryKiloBytes * 1024, nil // convert kilobytes to bytes
}

func getPhysicallyInstalledSystemMemory(totalMemoryInKilobytes *uint64) bool {
ret, _, _ := syscall.Syscall(procGetPhysicallyInstalledSystemMemory.Addr(), 1,
uintptr(unsafe.Pointer(totalMemoryInKilobytes)),
0,
0)

return ret != 0
}
44 changes: 22 additions & 22 deletions pkg/kubelet/winstats/perfcounters.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"time"
"unsafe"

"github.com/lxn/win"
"github.com/JeffAshton/win_pdh"
)

const (
Expand All @@ -37,31 +37,31 @@ const (
)

type perfCounter struct {
queryHandle win.PDH_HQUERY
counterHandle win.PDH_HCOUNTER
queryHandle win_pdh.PDH_HQUERY
counterHandle win_pdh.PDH_HCOUNTER
}

func newPerfCounter(counter string) (*perfCounter, error) {
var queryHandle win.PDH_HQUERY
var counterHandle win.PDH_HCOUNTER
var queryHandle win_pdh.PDH_HQUERY
var counterHandle win_pdh.PDH_HCOUNTER

ret := win.PdhOpenQuery(0, 0, &queryHandle)
if ret != win.ERROR_SUCCESS {
ret := win_pdh.PdhOpenQuery(0, 0, &queryHandle)
if ret != win_pdh.ERROR_SUCCESS {
return nil, errors.New("unable to open query through DLL call")
}

ret = win.PdhValidatePath(counter)
if ret != win.ERROR_SUCCESS {
ret = win_pdh.PdhValidatePath(counter)
if ret != win_pdh.ERROR_SUCCESS {
return nil, fmt.Errorf("unable to valid path to counter. Error code is %x", ret)
}

ret = win.PdhAddEnglishCounter(queryHandle, counter, 0, &counterHandle)
if ret != win.ERROR_SUCCESS {
ret = win_pdh.PdhAddEnglishCounter(queryHandle, counter, 0, &counterHandle)
if ret != win_pdh.ERROR_SUCCESS {
return nil, fmt.Errorf("unable to add process counter. Error code is %x", ret)
}

ret = win.PdhCollectQueryData(queryHandle)
if ret != win.ERROR_SUCCESS {
ret = win_pdh.PdhCollectQueryData(queryHandle)
if ret != win_pdh.ERROR_SUCCESS {
return nil, fmt.Errorf("unable to collect data from counter. Error code is %x", ret)
}

Expand All @@ -72,24 +72,24 @@ func newPerfCounter(counter string) (*perfCounter, error) {
}

func (p *perfCounter) getData() (uint64, error) {
ret := win.PdhCollectQueryData(p.queryHandle)
if ret != win.ERROR_SUCCESS {
ret := win_pdh.PdhCollectQueryData(p.queryHandle)
if ret != win_pdh.ERROR_SUCCESS {
return 0, fmt.Errorf("unable to collect data from counter. Error code is %x", ret)
}

var bufSize, bufCount uint32
var size = uint32(unsafe.Sizeof(win.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE{}))
var emptyBuf [1]win.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE // need at least 1 addressable null ptr.
var size = uint32(unsafe.Sizeof(win_pdh.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE{}))
var emptyBuf [1]win_pdh.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE // need at least 1 addressable null ptr.
var data uint64

ret = win.PdhGetFormattedCounterArrayDouble(p.counterHandle, &bufSize, &bufCount, &emptyBuf[0])
if ret != win.PDH_MORE_DATA {
ret = win_pdh.PdhGetFormattedCounterArrayDouble(p.counterHandle, &bufSize, &bufCount, &emptyBuf[0])
if ret != win_pdh.PDH_MORE_DATA {
return 0, fmt.Errorf("unable to collect data from counter. Error code is %x", ret)
}

filledBuf := make([]win.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE, bufCount*size)
ret = win.PdhGetFormattedCounterArrayDouble(p.counterHandle, &bufSize, &bufCount, &filledBuf[0])
if ret != win.ERROR_SUCCESS {
filledBuf := make([]win_pdh.PDH_FMT_COUNTERVALUE_ITEM_DOUBLE, bufCount*size)
ret = win_pdh.PdhGetFormattedCounterArrayDouble(p.counterHandle, &bufSize, &bufCount, &filledBuf[0])
if ret != win_pdh.ERROR_SUCCESS {
return 0, fmt.Errorf("unable to collect data from counter. Error code is %x", ret)
}

Expand Down
2 changes: 1 addition & 1 deletion vendor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ filegroup(
"//vendor/github.com/Azure/azure-sdk-for-go/storage:all-srcs",
"//vendor/github.com/Azure/go-ansiterm:all-srcs",
"//vendor/github.com/Azure/go-autorest/autorest:all-srcs",
"//vendor/github.com/JeffAshton/win_pdh:all-srcs",
"//vendor/github.com/MakeNowJust/heredoc:all-srcs",
"//vendor/github.com/Microsoft/go-winio:all-srcs",
"//vendor/github.com/Microsoft/hcsshim:all-srcs",
Expand Down Expand Up @@ -264,7 +265,6 @@ filegroup(
"//vendor/github.com/libopenstorage/openstorage/pkg/units:all-srcs",
"//vendor/github.com/libopenstorage/openstorage/volume:all-srcs",
"//vendor/github.com/lpabon/godbc:all-srcs",
"//vendor/github.com/lxn/win:all-srcs",
"//vendor/github.com/magiconair/properties:all-srcs",
"//vendor/github.com/mailru/easyjson/buffer:all-srcs",
"//vendor/github.com/mailru/easyjson/jlexer:all-srcs",
Expand Down
14 changes: 14 additions & 0 deletions vendor/github.com/JeffAshton/win_pdh/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/github.com/JeffAshton/win_pdh/BUILD

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/github.com/JeffAshton/win_pdh/README.mdown

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions vendor/github.com/lxn/win/AUTHORS

This file was deleted.

Loading

0 comments on commit 786c69d

Please sign in to comment.