mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
vendor update for CSI 0.3.0
This commit is contained in:
2
vendor/k8s.io/kubernetes/pkg/kubelet/stats/BUILD
generated
vendored
2
vendor/k8s.io/kubernetes/pkg/kubelet/stats/BUILD
generated
vendored
@ -55,13 +55,11 @@ go_library(
|
||||
"//pkg/kubelet/container:go_default_library",
|
||||
"//pkg/kubelet/kuberuntime:go_default_library",
|
||||
"//pkg/kubelet/leaky:go_default_library",
|
||||
"//pkg/kubelet/network:go_default_library",
|
||||
"//pkg/kubelet/pod:go_default_library",
|
||||
"//pkg/kubelet/server/stats:go_default_library",
|
||||
"//pkg/kubelet/types:go_default_library",
|
||||
"//pkg/volume:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
"//vendor/github.com/golang/protobuf/proto:go_default_library",
|
||||
"//vendor/github.com/google/cadvisor/fs:go_default_library",
|
||||
"//vendor/github.com/google/cadvisor/info/v1:go_default_library",
|
||||
"//vendor/github.com/google/cadvisor/info/v2:go_default_library",
|
||||
|
9
vendor/k8s.io/kubernetes/pkg/kubelet/stats/cadvisor_stats_provider.go
generated
vendored
9
vendor/k8s.io/kubernetes/pkg/kubelet/stats/cadvisor_stats_provider.go
generated
vendored
@ -255,9 +255,14 @@ func isPodManagedContainer(cinfo *cadvisorapiv2.ContainerInfo) bool {
|
||||
func getCadvisorPodInfoFromPodUID(podUID types.UID, infos map[string]cadvisorapiv2.ContainerInfo) *cadvisorapiv2.ContainerInfo {
|
||||
for key, info := range infos {
|
||||
if cm.IsSystemdStyleName(key) {
|
||||
key = cm.RevertFromSystemdToCgroupStyleName(key)
|
||||
// Convert to internal cgroup name and take the last component only.
|
||||
internalCgroupName := cm.ParseSystemdToCgroupName(key)
|
||||
key = internalCgroupName[len(internalCgroupName)-1]
|
||||
} else {
|
||||
// Take last component only.
|
||||
key = path.Base(key)
|
||||
}
|
||||
if cm.GetPodCgroupNameSuffix(podUID) == path.Base(key) {
|
||||
if cm.GetPodCgroupNameSuffix(podUID) == key {
|
||||
return &info
|
||||
}
|
||||
}
|
||||
|
69
vendor/k8s.io/kubernetes/pkg/kubelet/stats/cri_stats_provider.go
generated
vendored
69
vendor/k8s.io/kubernetes/pkg/kubelet/stats/cri_stats_provider.go
generated
vendored
@ -25,7 +25,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/golang/protobuf/proto"
|
||||
cadvisorfs "github.com/google/cadvisor/fs"
|
||||
|
||||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||
@ -143,12 +142,14 @@ func (p *criStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
|
||||
ps, found := sandboxIDToPodStats[podSandboxID]
|
||||
if !found {
|
||||
ps = buildPodStats(podSandbox)
|
||||
// Fill stats from cadvisor is available for full set of required pod stats
|
||||
p.addCadvisorPodNetworkStats(ps, podSandboxID, caInfos)
|
||||
p.addCadvisorPodCPUMemoryStats(ps, types.UID(podSandbox.Metadata.Uid), allInfos)
|
||||
sandboxIDToPodStats[podSandboxID] = ps
|
||||
}
|
||||
|
||||
// Fill available stats for full set of required pod stats
|
||||
cs := p.makeContainerStats(stats, container, &rootFsInfo, fsIDtoInfo, podSandbox.GetMetadata().GetUid())
|
||||
p.addPodNetworkStats(ps, podSandboxID, caInfos, cs)
|
||||
p.addPodCPUMemoryStats(ps, types.UID(podSandbox.Metadata.Uid), allInfos, cs)
|
||||
|
||||
// If cadvisor stats is available for the container, use it to populate
|
||||
// container stats
|
||||
caStats, caFound := caInfos[containerID]
|
||||
@ -264,29 +265,69 @@ func (p *criStatsProvider) makePodStorageStats(s *statsapi.PodStats, rootFsInfo
|
||||
return s
|
||||
}
|
||||
|
||||
func (p *criStatsProvider) addCadvisorPodNetworkStats(
|
||||
func (p *criStatsProvider) addPodNetworkStats(
|
||||
ps *statsapi.PodStats,
|
||||
podSandboxID string,
|
||||
caInfos map[string]cadvisorapiv2.ContainerInfo,
|
||||
cs *statsapi.ContainerStats,
|
||||
) {
|
||||
caPodSandbox, found := caInfos[podSandboxID]
|
||||
// try get network stats from cadvisor first.
|
||||
if found {
|
||||
ps.Network = cadvisorInfoToNetworkStats(ps.PodRef.Name, &caPodSandbox)
|
||||
} else {
|
||||
glog.V(4).Infof("Unable to find cadvisor stats for sandbox %q", podSandboxID)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: sum Pod network stats from container stats.
|
||||
glog.V(4).Infof("Unable to find cadvisor stats for sandbox %q", podSandboxID)
|
||||
}
|
||||
|
||||
func (p *criStatsProvider) addCadvisorPodCPUMemoryStats(
|
||||
func (p *criStatsProvider) addPodCPUMemoryStats(
|
||||
ps *statsapi.PodStats,
|
||||
podUID types.UID,
|
||||
allInfos map[string]cadvisorapiv2.ContainerInfo,
|
||||
cs *statsapi.ContainerStats,
|
||||
) {
|
||||
// try get cpu and memory stats from cadvisor first.
|
||||
podCgroupInfo := getCadvisorPodInfoFromPodUID(podUID, allInfos)
|
||||
if podCgroupInfo != nil {
|
||||
cpu, memory := cadvisorInfoToCPUandMemoryStats(podCgroupInfo)
|
||||
ps.CPU = cpu
|
||||
ps.Memory = memory
|
||||
return
|
||||
}
|
||||
|
||||
// Sum Pod cpu and memory stats from containers stats.
|
||||
if cs.CPU != nil {
|
||||
if ps.CPU == nil {
|
||||
ps.CPU = &statsapi.CPUStats{}
|
||||
}
|
||||
|
||||
ps.CPU.Time = cs.StartTime
|
||||
usageCoreNanoSeconds := getUint64Value(cs.CPU.UsageCoreNanoSeconds) + getUint64Value(ps.CPU.UsageCoreNanoSeconds)
|
||||
usageNanoCores := getUint64Value(cs.CPU.UsageNanoCores) + getUint64Value(ps.CPU.UsageNanoCores)
|
||||
ps.CPU.UsageCoreNanoSeconds = &usageCoreNanoSeconds
|
||||
ps.CPU.UsageNanoCores = &usageNanoCores
|
||||
}
|
||||
|
||||
if cs.Memory != nil {
|
||||
if ps.Memory == nil {
|
||||
ps.Memory = &statsapi.MemoryStats{}
|
||||
}
|
||||
|
||||
ps.Memory.Time = cs.Memory.Time
|
||||
availableBytes := getUint64Value(cs.Memory.AvailableBytes) + getUint64Value(ps.Memory.AvailableBytes)
|
||||
usageBytes := getUint64Value(cs.Memory.UsageBytes) + getUint64Value(ps.Memory.UsageBytes)
|
||||
workingSetBytes := getUint64Value(cs.Memory.WorkingSetBytes) + getUint64Value(ps.Memory.WorkingSetBytes)
|
||||
rSSBytes := getUint64Value(cs.Memory.RSSBytes) + getUint64Value(ps.Memory.RSSBytes)
|
||||
pageFaults := getUint64Value(cs.Memory.PageFaults) + getUint64Value(ps.Memory.PageFaults)
|
||||
majorPageFaults := getUint64Value(cs.Memory.MajorPageFaults) + getUint64Value(ps.Memory.MajorPageFaults)
|
||||
ps.Memory.AvailableBytes = &availableBytes
|
||||
ps.Memory.UsageBytes = &usageBytes
|
||||
ps.Memory.WorkingSetBytes = &workingSetBytes
|
||||
ps.Memory.RSSBytes = &rSSBytes
|
||||
ps.Memory.PageFaults = &pageFaults
|
||||
ps.Memory.MajorPageFaults = &majorPageFaults
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,15 +342,9 @@ func (p *criStatsProvider) makeContainerStats(
|
||||
Name: stats.Attributes.Metadata.Name,
|
||||
// The StartTime in the summary API is the container creation time.
|
||||
StartTime: metav1.NewTime(time.Unix(0, container.CreatedAt)),
|
||||
// Work around heapster bug. https://github.com/kubernetes/kubernetes/issues/54962
|
||||
// TODO(random-liu): Remove this after heapster is updated to newer than 1.5.0-beta.0.
|
||||
CPU: &statsapi.CPUStats{
|
||||
UsageNanoCores: proto.Uint64(0),
|
||||
},
|
||||
Memory: &statsapi.MemoryStats{
|
||||
RSSBytes: proto.Uint64(0),
|
||||
},
|
||||
Rootfs: &statsapi.FsStats{},
|
||||
CPU: &statsapi.CPUStats{},
|
||||
Memory: &statsapi.MemoryStats{},
|
||||
Rootfs: &statsapi.FsStats{},
|
||||
// UserDefinedMetrics is not supported by CRI.
|
||||
}
|
||||
if stats.Cpu != nil {
|
||||
|
4
vendor/k8s.io/kubernetes/pkg/kubelet/stats/cri_stats_provider_test.go
generated
vendored
4
vendor/k8s.io/kubernetes/pkg/kubelet/stats/cri_stats_provider_test.go
generated
vendored
@ -18,6 +18,7 @@ package stats
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@ -464,6 +465,9 @@ func checkCRINetworkStats(assert *assert.Assertions, actual *statsapi.NetworkSta
|
||||
}
|
||||
|
||||
func checkCRIPodCPUAndMemoryStats(assert *assert.Assertions, actual statsapi.PodStats, cs *cadvisorapiv2.ContainerStats) {
|
||||
if runtime.GOOS != "linux" {
|
||||
return
|
||||
}
|
||||
assert.Equal(cs.Timestamp.UnixNano(), actual.CPU.Time.UnixNano())
|
||||
assert.Equal(cs.Cpu.Usage.Total, *actual.CPU.UsageCoreNanoSeconds)
|
||||
assert.Equal(cs.CpuInst.Usage.Total, *actual.CPU.UsageNanoCores)
|
||||
|
16
vendor/k8s.io/kubernetes/pkg/kubelet/stats/helper.go
generated
vendored
16
vendor/k8s.io/kubernetes/pkg/kubelet/stats/helper.go
generated
vendored
@ -27,9 +27,13 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
statsapi "k8s.io/kubernetes/pkg/kubelet/apis/stats/v1alpha1"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cadvisor"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
)
|
||||
|
||||
// defaultNetworkInterfaceName is used for collectng network stats.
|
||||
// This logic relies on knowledge of the container runtime implementation and
|
||||
// is not reliable.
|
||||
const defaultNetworkInterfaceName = "eth0"
|
||||
|
||||
func cadvisorInfoToCPUandMemoryStats(info *cadvisorapiv2.ContainerInfo) (*statsapi.CPUStats, *statsapi.MemoryStats) {
|
||||
cstat, found := latestContainerStats(info)
|
||||
if !found {
|
||||
@ -153,7 +157,7 @@ func cadvisorInfoToNetworkStats(name string, info *cadvisorapiv2.ContainerInfo)
|
||||
TxErrors: &inter.TxErrors,
|
||||
}
|
||||
|
||||
if inter.Name == network.DefaultInterfaceName {
|
||||
if inter.Name == defaultNetworkInterfaceName {
|
||||
iStats.InterfaceStats = iStat
|
||||
}
|
||||
|
||||
@ -299,3 +303,11 @@ func buildRootfsStats(cstat *cadvisorapiv2.ContainerStats, imageFs *cadvisorapiv
|
||||
Inodes: imageFs.Inodes,
|
||||
}
|
||||
}
|
||||
|
||||
func getUint64Value(value *uint64) uint64 {
|
||||
if value == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return *value
|
||||
}
|
||||
|
Reference in New Issue
Block a user