vendor updates

This commit is contained in:
Serguei Bezverkhi
2018-03-06 17:33:18 -05:00
parent 4b3ebc171b
commit e9033989a0
5854 changed files with 248382 additions and 119809 deletions

View File

@ -1,6 +1,51 @@
package(default_visibility = ["//visibility:public"])
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
licenses(["notice"])
go_library(
name = "go_default_library",
srcs = [
"doc.go",
] + select({
"@io_bazel_rules_go//go/platform:windows": [
"perfcounter_nodestats.go",
"perfcounters.go",
"version.go",
"winstats.go",
],
"//conditions:default": [],
}),
importpath = "k8s.io/kubernetes/pkg/kubelet/winstats",
visibility = ["//visibility:public"],
deps = select({
"@io_bazel_rules_go//go/platform:windows": [
"//vendor/github.com/JeffAshton/win_pdh:go_default_library",
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
"//vendor/github.com/google/cadvisor/info/v2:go_default_library",
"//vendor/golang.org/x/sys/windows:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
],
"//conditions:default": [],
}),
)
go_test(
name = "go_default_test",
srcs = select({
"@io_bazel_rules_go//go/platform:windows": [
"winstats_test.go",
],
"//conditions:default": [],
}),
embed = [":go_default_library"],
deps = select({
"@io_bazel_rules_go//go/platform:windows": [
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
"//vendor/github.com/google/cadvisor/info/v2:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
"//conditions:default": [],
}),
)
filegroup(
name = "package-srcs",
@ -13,45 +58,5 @@ filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"winstats.go",
] + select({
"@io_bazel_rules_go//go/platform:windows_amd64": [
"perfcounter_nodestats.go",
"perfcounters.go",
"version.go",
],
"//conditions:default": [],
}),
importpath = "k8s.io/kubernetes/pkg/kubelet/winstats",
deps = [
"//vendor/github.com/google/cadvisor/info/v1:go_default_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/golang.org/x/sys/windows:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
],
"//conditions:default": [],
}),
)
go_test(
name = "go_default_test",
srcs = ["winstats_test.go"],
importpath = "k8s.io/kubernetes/pkg/kubelet/winstats",
library = ":go_default_library",
deps = [
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
"//vendor/github.com/google/cadvisor/info/v2:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
visibility = ["//visibility:public"],
)

18
vendor/k8s.io/kubernetes/pkg/kubelet/winstats/doc.go generated vendored Normal file
View File

@ -0,0 +1,18 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package winstats provides a client to get node and pod level stats on windows
package winstats // import "k8s.io/kubernetes/pkg/kubelet/winstats"

View File

@ -23,18 +23,32 @@ import (
"os"
"runtime"
"sync"
"syscall"
"time"
"unsafe"
"github.com/golang/glog"
cadvisorapi "github.com/google/cadvisor/info/v1"
"golang.org/x/sys/windows"
"k8s.io/apimachinery/pkg/util/wait"
)
// MemoryStatusEx is the same as Windows structure MEMORYSTATUSEX
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa366770(v=vs.85).aspx
type MemoryStatusEx struct {
Length uint32
MemoryLoad uint32
TotalPhys uint64
AvailPhys uint64
TotalPageFile uint64
AvailPageFile uint64
TotalVirtual uint64
AvailVirtual uint64
AvailExtendedVirtual uint64
}
var (
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
procGetPhysicallyInstalledSystemMemory = modkernel32.NewProc("GetPhysicallyInstalledSystemMemory")
modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
procGlobalMemoryStatusEx = modkernel32.NewProc("GlobalMemoryStatusEx")
)
// NewPerfCounterClient creates a client using perf counters
@ -163,20 +177,24 @@ func (p *perfCounterNodeStatsClient) convertCPUValue(cpuValue uint64) uint64 {
}
func getPhysicallyInstalledSystemMemoryBytes() (uint64, error) {
var physicalMemoryKiloBytes uint64
// We use GlobalMemoryStatusEx instead of GetPhysicallyInstalledSystemMemory
// on Windows node for the following reasons:
// 1. GetPhysicallyInstalledSystemMemory retrieves the amount of physically
// installed RAM from the computer's SMBIOS firmware tables.
// https://msdn.microsoft.com/en-us/library/windows/desktop/cc300158(v=vs.85).aspx
// On some VM, it is unable to read data from SMBIOS and fails with ERROR_INVALID_DATA.
// 2. On Linux node, total physical memory is read from MemTotal in /proc/meminfo.
// GlobalMemoryStatusEx returns the amount of physical memory that is available
// for the operating system to use. The amount returned by GlobalMemoryStatusEx
// is closer in parity with Linux
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt
var statex MemoryStatusEx
statex.Length = uint32(unsafe.Sizeof(statex))
ret, _, _ := procGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(&statex)))
if ok := getPhysicallyInstalledSystemMemory(&physicalMemoryKiloBytes); !ok {
if ret == 0 {
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
return statex.TotalPhys, nil
}

View File

@ -25,7 +25,7 @@ import (
"golang.org/x/sys/windows"
)
// getCurrentVersionVal gets value of speficied key from registry.
// getCurrentVersionVal gets value of specified key from registry.
func getCurrentVersionVal(key string) (string, error) {
var h windows.Handle
if err := windows.RegOpenKeyEx(windows.HKEY_LOCAL_MACHINE,
@ -69,20 +69,39 @@ func getVersionRevision() (uint16, error) {
// getKernelVersion gets the version of windows kernel.
func getKernelVersion() (string, error) {
ver, err := windows.GetVersion()
// Get CurrentBuildNumber.
buildNumber, err := getCurrentVersionVal("CurrentBuildNumber")
if err != nil {
return "", err
}
// Get CurrentMajorVersionNumber.
majorVersionNumberString, err := getCurrentVersionVal("CurrentMajorVersionNumber")
if err != nil {
return "", err
}
majorVersionNumber, err := windows.UTF16FromString(majorVersionNumberString)
if err != nil {
return "", err
}
// Get CurrentMinorVersionNumber.
minorVersionNumberString, err := getCurrentVersionVal("CurrentMinorVersionNumber")
if err != nil {
return "", err
}
minorVersionNumber, err := windows.UTF16FromString(minorVersionNumberString)
if err != nil {
return "", err
}
// Get UBR.
revision, err := getVersionRevision()
if err != nil {
return "", err
}
major := ver & 0xFF
minor := (ver >> 8) & 0xFF
build := (ver >> 16) & 0xFFFF
return fmt.Sprintf("%d.%d.%05d.%d\n", major, minor, build, revision), nil
return fmt.Sprintf("%d.%d.%s.%d\n", majorVersionNumber[0], minorVersionNumber[0], buildNumber, revision), nil
}
// getOSImageVersion gets the osImage name and version.

View File

@ -1,3 +1,5 @@
// +build windows
/*
Copyright 2017 The Kubernetes Authors.
@ -18,21 +20,28 @@ limitations under the License.
package winstats
import (
"syscall"
"time"
"unsafe"
cadvisorapi "github.com/google/cadvisor/info/v1"
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
)
var (
procGetDiskFreeSpaceEx = modkernel32.NewProc("GetDiskFreeSpaceExW")
)
// Client is an interface that is used to get stats information.
type Client interface {
WinContainerInfos() (map[string]cadvisorapiv2.ContainerInfo, error)
WinMachineInfo() (*cadvisorapi.MachineInfo, error)
WinVersionInfo() (*cadvisorapi.VersionInfo, error)
GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error)
}
// StatsClient is a client that implements the Client interface
type statsClient struct {
type StatsClient struct {
client winNodeStatsClient
}
@ -61,7 +70,7 @@ type nodeInfo struct {
// newClient constructs a Client.
func newClient(statsNodeClient winNodeStatsClient) (Client, error) {
statsClient := new(statsClient)
statsClient := new(StatsClient)
statsClient.client = statsNodeClient
err := statsClient.client.startMonitoring()
@ -74,7 +83,7 @@ func newClient(statsNodeClient winNodeStatsClient) (Client, error) {
// WinContainerInfos returns a map of container infos. The map contains node and
// pod level stats. Analogous to cadvisor GetContainerInfoV2 method.
func (c *statsClient) WinContainerInfos() (map[string]cadvisorapiv2.ContainerInfo, error) {
func (c *StatsClient) WinContainerInfos() (map[string]cadvisorapiv2.ContainerInfo, error) {
infos := make(map[string]cadvisorapiv2.ContainerInfo)
rootContainerInfo, err := c.createRootContainerInfo()
if err != nil {
@ -88,17 +97,17 @@ func (c *statsClient) WinContainerInfos() (map[string]cadvisorapiv2.ContainerInf
// WinMachineInfo returns a cadvisorapi.MachineInfo with details about the
// node machine. Analogous to cadvisor MachineInfo method.
func (c *statsClient) WinMachineInfo() (*cadvisorapi.MachineInfo, error) {
func (c *StatsClient) WinMachineInfo() (*cadvisorapi.MachineInfo, error) {
return c.client.getMachineInfo()
}
// WinVersionInfo returns a cadvisorapi.VersionInfo with version info of
// the kernel and docker runtime. Analogous to cadvisor VersionInfo method.
func (c *statsClient) WinVersionInfo() (*cadvisorapi.VersionInfo, error) {
func (c *StatsClient) WinVersionInfo() (*cadvisorapi.VersionInfo, error) {
return c.client.getVersionInfo()
}
func (c *statsClient) createRootContainerInfo() (*cadvisorapiv2.ContainerInfo, error) {
func (c *StatsClient) createRootContainerInfo() (*cadvisorapiv2.ContainerInfo, error) {
nodeMetrics, err := c.client.getNodeMetrics()
if err != nil {
@ -134,3 +143,30 @@ func (c *statsClient) createRootContainerInfo() (*cadvisorapiv2.ContainerInfo, e
return &rootInfo, nil
}
// GetDirFsInfo returns filesystem capacity and usage information.
func (c *StatsClient) GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error) {
var freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes int64
var err error
ret, _, err := syscall.Syscall6(
procGetDiskFreeSpaceEx.Addr(),
4,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(path))),
uintptr(unsafe.Pointer(&freeBytesAvailable)),
uintptr(unsafe.Pointer(&totalNumberOfBytes)),
uintptr(unsafe.Pointer(&totalNumberOfFreeBytes)),
0,
0,
)
if ret == 0 {
return cadvisorapiv2.FsInfo{}, err
}
return cadvisorapiv2.FsInfo{
Timestamp: time.Now(),
Capacity: uint64(totalNumberOfBytes),
Available: uint64(freeBytesAvailable),
Usage: uint64(totalNumberOfBytes - freeBytesAvailable),
}, nil
}

View File

@ -1,3 +1,5 @@
// +build windows
/*
Copyright 2017 The Kubernetes Authors.