mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
cleanup: fix golint errors in /pkg/kubelet/stats
This commit is contained in:
parent
0a14265b7e
commit
8c724d7933
@ -108,7 +108,6 @@ pkg/kubelet/dockershim/network/testing
|
|||||||
pkg/kubelet/pluginmanager/pluginwatcher
|
pkg/kubelet/pluginmanager/pluginwatcher
|
||||||
pkg/kubelet/pod/testing
|
pkg/kubelet/pod/testing
|
||||||
pkg/kubelet/preemption
|
pkg/kubelet/preemption
|
||||||
pkg/kubelet/stats
|
|
||||||
pkg/kubelet/sysctl
|
pkg/kubelet/sysctl
|
||||||
pkg/kubelet/types
|
pkg/kubelet/types
|
||||||
pkg/kubemark
|
pkg/kubemark
|
||||||
|
@ -145,6 +145,7 @@ go_library(
|
|||||||
"//staging/src/k8s.io/cri-api/pkg/apis:go_default_library",
|
"//staging/src/k8s.io/cri-api/pkg/apis:go_default_library",
|
||||||
"//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library",
|
"//staging/src/k8s.io/cri-api/pkg/apis/runtime/v1alpha2:go_default_library",
|
||||||
"//staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1:go_default_library",
|
"//staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/kubelet/pkg/apis/stats/v1alpha1:go_default_library",
|
||||||
"//staging/src/k8s.io/mount-utils:go_default_library",
|
"//staging/src/k8s.io/mount-utils:go_default_library",
|
||||||
"//third_party/forked/golang/expansion:go_default_library",
|
"//third_party/forked/golang/expansion:go_default_library",
|
||||||
"//vendor/github.com/golang/groupcache/lru:go_default_library",
|
"//vendor/github.com/golang/groupcache/lru:go_default_library",
|
||||||
|
@ -58,6 +58,7 @@ import (
|
|||||||
internalapi "k8s.io/cri-api/pkg/apis"
|
internalapi "k8s.io/cri-api/pkg/apis"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
pluginwatcherapi "k8s.io/kubelet/pkg/apis/pluginregistration/v1"
|
pluginwatcherapi "k8s.io/kubelet/pkg/apis/pluginregistration/v1"
|
||||||
|
statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
|
||||||
api "k8s.io/kubernetes/pkg/apis/core"
|
api "k8s.io/kubernetes/pkg/apis/core"
|
||||||
"k8s.io/kubernetes/pkg/features"
|
"k8s.io/kubernetes/pkg/features"
|
||||||
kubeletconfiginternal "k8s.io/kubernetes/pkg/kubelet/apis/config"
|
kubeletconfiginternal "k8s.io/kubernetes/pkg/kubelet/apis/config"
|
||||||
@ -1119,7 +1120,7 @@ type Kubelet struct {
|
|||||||
dockerLegacyService legacy.DockerLegacyService
|
dockerLegacyService legacy.DockerLegacyService
|
||||||
|
|
||||||
// StatsProvider provides the node and the container stats.
|
// StatsProvider provides the node and the container stats.
|
||||||
*stats.StatsProvider
|
StatsProvider *stats.Provider
|
||||||
|
|
||||||
// This flag, if set, instructs the kubelet to keep volumes from terminated pods mounted to the node.
|
// This flag, if set, instructs the kubelet to keep volumes from terminated pods mounted to the node.
|
||||||
// This can be useful for debugging volume related issues.
|
// This can be useful for debugging volume related issues.
|
||||||
@ -1136,6 +1137,56 @@ type Kubelet struct {
|
|||||||
runtimeClassManager *runtimeclass.Manager
|
runtimeClassManager *runtimeclass.Manager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListPodStats is delegated to StatsProvider, which implements stats.Provider interface
|
||||||
|
func (kl *Kubelet) ListPodStats() ([]statsapi.PodStats, error) {
|
||||||
|
return kl.StatsProvider.ListPodStats()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListPodCPUAndMemoryStats is delegated to StatsProvider, which implements stats.Provider interface
|
||||||
|
func (kl *Kubelet) ListPodCPUAndMemoryStats() ([]statsapi.PodStats, error) {
|
||||||
|
return kl.StatsProvider.ListPodCPUAndMemoryStats()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListPodStatsAndUpdateCPUNanoCoreUsage is delegated to StatsProvider, which implements stats.Provider interface
|
||||||
|
func (kl *Kubelet) ListPodStatsAndUpdateCPUNanoCoreUsage() ([]statsapi.PodStats, error) {
|
||||||
|
return kl.StatsProvider.ListPodStatsAndUpdateCPUNanoCoreUsage()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageFsStats is delegated to StatsProvider, which implements stats.Provider interface
|
||||||
|
func (kl *Kubelet) ImageFsStats() (*statsapi.FsStats, error) {
|
||||||
|
return kl.StatsProvider.ImageFsStats()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCgroupStats is delegated to StatsProvider, which implements stats.Provider interface
|
||||||
|
func (kl *Kubelet) GetCgroupStats(cgroupName string, updateStats bool) (*statsapi.ContainerStats, *statsapi.NetworkStats, error) {
|
||||||
|
return kl.StatsProvider.GetCgroupStats(cgroupName, updateStats)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCgroupCPUAndMemoryStats is delegated to StatsProvider, which implements stats.Provider interface
|
||||||
|
func (kl *Kubelet) GetCgroupCPUAndMemoryStats(cgroupName string, updateStats bool) (*statsapi.ContainerStats, error) {
|
||||||
|
return kl.StatsProvider.GetCgroupCPUAndMemoryStats(cgroupName, updateStats)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RootFsStats is delegated to StatsProvider, which implements stats.Provider interface
|
||||||
|
func (kl *Kubelet) RootFsStats() (*statsapi.FsStats, error) {
|
||||||
|
return kl.StatsProvider.RootFsStats()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetContainerInfo is delegated to StatsProvider, which implements stats.Provider interface
|
||||||
|
func (kl *Kubelet) GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error) {
|
||||||
|
return kl.StatsProvider.GetContainerInfo(podFullName, uid, containerName, req)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRawContainerInfo is delegated to StatsProvider, which implements stats.Provider interface
|
||||||
|
func (kl *Kubelet) GetRawContainerInfo(containerName string, req *cadvisorapi.ContainerInfoRequest, subcontainers bool) (map[string]*cadvisorapi.ContainerInfo, error) {
|
||||||
|
return kl.StatsProvider.GetRawContainerInfo(containerName, req, subcontainers)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RlimitStats is delegated to StatsProvider, which implements stats.Provider interface
|
||||||
|
func (kl *Kubelet) RlimitStats() (*statsapi.RlimitStats, error) {
|
||||||
|
return kl.StatsProvider.RlimitStats()
|
||||||
|
}
|
||||||
|
|
||||||
// setupDataDirs creates:
|
// setupDataDirs creates:
|
||||||
// 1. the root directory
|
// 1. the root directory
|
||||||
// 2. the pods directory
|
// 2. the pods directory
|
||||||
|
@ -113,7 +113,7 @@ func TestRunOnce(t *testing.T) {
|
|||||||
false, /* keepTerminatedPodVolumes */
|
false, /* keepTerminatedPodVolumes */
|
||||||
volumetest.NewBlockVolumePathHandler())
|
volumetest.NewBlockVolumePathHandler())
|
||||||
|
|
||||||
// TODO: Factor out "StatsProvider" from Kubelet so we don't have a cyclic dependency
|
// TODO: Factor out "stats.Provider" from Kubelet so we don't have a cyclic dependency
|
||||||
volumeStatsAggPeriod := time.Second * 10
|
volumeStatsAggPeriod := time.Second * 10
|
||||||
kb.resourceAnalyzer = stats.NewResourceAnalyzer(kb, volumeStatsAggPeriod)
|
kb.resourceAnalyzer = stats.NewResourceAnalyzer(kb, volumeStatsAggPeriod)
|
||||||
nodeRef := &v1.ObjectReference{
|
nodeRef := &v1.ObjectReference{
|
||||||
|
@ -9,7 +9,7 @@ go_library(
|
|||||||
"cri_stats_provider_windows.go",
|
"cri_stats_provider_windows.go",
|
||||||
"helper.go",
|
"helper.go",
|
||||||
"log_metrics_provider.go",
|
"log_metrics_provider.go",
|
||||||
"stats_provider.go",
|
"provider.go",
|
||||||
],
|
],
|
||||||
importpath = "k8s.io/kubernetes/pkg/kubelet/stats",
|
importpath = "k8s.io/kubernetes/pkg/kubelet/stats",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
@ -67,7 +67,7 @@ go_test(
|
|||||||
"cri_stats_provider_test.go",
|
"cri_stats_provider_test.go",
|
||||||
"helper_test.go",
|
"helper_test.go",
|
||||||
"log_metrics_provider_test.go",
|
"log_metrics_provider_test.go",
|
||||||
"stats_provider_test.go",
|
"provider_test.go",
|
||||||
],
|
],
|
||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
|
@ -32,7 +32,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/kubelet/status"
|
"k8s.io/kubernetes/pkg/kubelet/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCRIStatsProvider returns a StatsProvider that provides the node stats
|
// NewCRIStatsProvider returns a Provider that provides the node stats
|
||||||
// from cAdvisor and the container stats from CRI.
|
// from cAdvisor and the container stats from CRI.
|
||||||
func NewCRIStatsProvider(
|
func NewCRIStatsProvider(
|
||||||
cadvisor cadvisor.Interface,
|
cadvisor cadvisor.Interface,
|
||||||
@ -43,7 +43,7 @@ func NewCRIStatsProvider(
|
|||||||
imageService internalapi.ImageManagerService,
|
imageService internalapi.ImageManagerService,
|
||||||
logMetricsService LogMetricsService,
|
logMetricsService LogMetricsService,
|
||||||
osInterface kubecontainer.OSInterface,
|
osInterface kubecontainer.OSInterface,
|
||||||
) *StatsProvider {
|
) *Provider {
|
||||||
return newStatsProvider(cadvisor, podManager, runtimeCache, newCRIStatsProvider(cadvisor, resourceAnalyzer,
|
return newStatsProvider(cadvisor, podManager, runtimeCache, newCRIStatsProvider(cadvisor, resourceAnalyzer,
|
||||||
runtimeService, imageService, logMetricsService, osInterface))
|
runtimeService, imageService, logMetricsService, osInterface))
|
||||||
}
|
}
|
||||||
@ -57,19 +57,19 @@ func NewCadvisorStatsProvider(
|
|||||||
runtimeCache kubecontainer.RuntimeCache,
|
runtimeCache kubecontainer.RuntimeCache,
|
||||||
imageService kubecontainer.ImageService,
|
imageService kubecontainer.ImageService,
|
||||||
statusProvider status.PodStatusProvider,
|
statusProvider status.PodStatusProvider,
|
||||||
) *StatsProvider {
|
) *Provider {
|
||||||
return newStatsProvider(cadvisor, podManager, runtimeCache, newCadvisorStatsProvider(cadvisor, resourceAnalyzer, imageService, statusProvider))
|
return newStatsProvider(cadvisor, podManager, runtimeCache, newCadvisorStatsProvider(cadvisor, resourceAnalyzer, imageService, statusProvider))
|
||||||
}
|
}
|
||||||
|
|
||||||
// newStatsProvider returns a new StatsProvider that provides node stats from
|
// newStatsProvider returns a new Provider that provides node stats from
|
||||||
// cAdvisor and the container stats using the containerStatsProvider.
|
// cAdvisor and the container stats using the containerStatsProvider.
|
||||||
func newStatsProvider(
|
func newStatsProvider(
|
||||||
cadvisor cadvisor.Interface,
|
cadvisor cadvisor.Interface,
|
||||||
podManager kubepod.Manager,
|
podManager kubepod.Manager,
|
||||||
runtimeCache kubecontainer.RuntimeCache,
|
runtimeCache kubecontainer.RuntimeCache,
|
||||||
containerStatsProvider containerStatsProvider,
|
containerStatsProvider containerStatsProvider,
|
||||||
) *StatsProvider {
|
) *Provider {
|
||||||
return &StatsProvider{
|
return &Provider{
|
||||||
cadvisor: cadvisor,
|
cadvisor: cadvisor,
|
||||||
podManager: podManager,
|
podManager: podManager,
|
||||||
runtimeCache: runtimeCache,
|
runtimeCache: runtimeCache,
|
||||||
@ -77,8 +77,8 @@ func newStatsProvider(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatsProvider provides the stats of the node and the pod-managed containers.
|
// Provider provides the stats of the node and the pod-managed containers.
|
||||||
type StatsProvider struct {
|
type Provider struct {
|
||||||
cadvisor cadvisor.Interface
|
cadvisor cadvisor.Interface
|
||||||
podManager kubepod.Manager
|
podManager kubepod.Manager
|
||||||
runtimeCache kubecontainer.RuntimeCache
|
runtimeCache kubecontainer.RuntimeCache
|
||||||
@ -101,13 +101,13 @@ type rlimitStatsProvider interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RlimitStats returns base information about process count
|
// RlimitStats returns base information about process count
|
||||||
func (p *StatsProvider) RlimitStats() (*statsapi.RlimitStats, error) {
|
func (p *Provider) RlimitStats() (*statsapi.RlimitStats, error) {
|
||||||
return pidlimit.Stats()
|
return pidlimit.Stats()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCgroupStats returns the stats of the cgroup with the cgroupName. Note that
|
// GetCgroupStats returns the stats of the cgroup with the cgroupName. Note that
|
||||||
// this function doesn't generate filesystem stats.
|
// this function doesn't generate filesystem stats.
|
||||||
func (p *StatsProvider) GetCgroupStats(cgroupName string, updateStats bool) (*statsapi.ContainerStats, *statsapi.NetworkStats, error) {
|
func (p *Provider) GetCgroupStats(cgroupName string, updateStats bool) (*statsapi.ContainerStats, *statsapi.NetworkStats, error) {
|
||||||
info, err := getCgroupInfo(p.cadvisor, cgroupName, updateStats)
|
info, err := getCgroupInfo(p.cadvisor, cgroupName, updateStats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("failed to get cgroup stats for %q: %v", cgroupName, err)
|
return nil, nil, fmt.Errorf("failed to get cgroup stats for %q: %v", cgroupName, err)
|
||||||
@ -120,7 +120,7 @@ func (p *StatsProvider) GetCgroupStats(cgroupName string, updateStats bool) (*st
|
|||||||
|
|
||||||
// GetCgroupCPUAndMemoryStats returns the CPU and memory stats of the cgroup with the cgroupName. Note that
|
// GetCgroupCPUAndMemoryStats returns the CPU and memory stats of the cgroup with the cgroupName. Note that
|
||||||
// this function doesn't generate filesystem stats.
|
// this function doesn't generate filesystem stats.
|
||||||
func (p *StatsProvider) GetCgroupCPUAndMemoryStats(cgroupName string, updateStats bool) (*statsapi.ContainerStats, error) {
|
func (p *Provider) GetCgroupCPUAndMemoryStats(cgroupName string, updateStats bool) (*statsapi.ContainerStats, error) {
|
||||||
info, err := getCgroupInfo(p.cadvisor, cgroupName, updateStats)
|
info, err := getCgroupInfo(p.cadvisor, cgroupName, updateStats)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get cgroup stats for %q: %v", cgroupName, err)
|
return nil, fmt.Errorf("failed to get cgroup stats for %q: %v", cgroupName, err)
|
||||||
@ -131,7 +131,7 @@ func (p *StatsProvider) GetCgroupCPUAndMemoryStats(cgroupName string, updateStat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RootFsStats returns the stats of the node root filesystem.
|
// RootFsStats returns the stats of the node root filesystem.
|
||||||
func (p *StatsProvider) RootFsStats() (*statsapi.FsStats, error) {
|
func (p *Provider) RootFsStats() (*statsapi.FsStats, error) {
|
||||||
rootFsInfo, err := p.cadvisor.RootFsInfo()
|
rootFsInfo, err := p.cadvisor.RootFsInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get rootFs info: %v", err)
|
return nil, fmt.Errorf("failed to get rootFs info: %v", err)
|
||||||
@ -162,7 +162,7 @@ func (p *StatsProvider) RootFsStats() (*statsapi.FsStats, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetContainerInfo returns stats (from cAdvisor) for a container.
|
// GetContainerInfo returns stats (from cAdvisor) for a container.
|
||||||
func (p *StatsProvider) GetContainerInfo(podFullName string, podUID types.UID, containerName string, req *cadvisorapiv1.ContainerInfoRequest) (*cadvisorapiv1.ContainerInfo, error) {
|
func (p *Provider) GetContainerInfo(podFullName string, podUID types.UID, containerName string, req *cadvisorapiv1.ContainerInfoRequest) (*cadvisorapiv1.ContainerInfo, error) {
|
||||||
// Resolve and type convert back again.
|
// Resolve and type convert back again.
|
||||||
// We need the static pod UID but the kubecontainer API works with types.UID.
|
// We need the static pod UID but the kubecontainer API works with types.UID.
|
||||||
podUID = types.UID(p.podManager.TranslatePodUID(podUID))
|
podUID = types.UID(p.podManager.TranslatePodUID(podUID))
|
||||||
@ -186,7 +186,7 @@ func (p *StatsProvider) GetContainerInfo(podFullName string, podUID types.UID, c
|
|||||||
|
|
||||||
// GetRawContainerInfo returns the stats (from cadvisor) for a non-Kubernetes
|
// GetRawContainerInfo returns the stats (from cadvisor) for a non-Kubernetes
|
||||||
// container.
|
// container.
|
||||||
func (p *StatsProvider) GetRawContainerInfo(containerName string, req *cadvisorapiv1.ContainerInfoRequest, subcontainers bool) (map[string]*cadvisorapiv1.ContainerInfo, error) {
|
func (p *Provider) GetRawContainerInfo(containerName string, req *cadvisorapiv1.ContainerInfoRequest, subcontainers bool) (map[string]*cadvisorapiv1.ContainerInfo, error) {
|
||||||
if subcontainers {
|
if subcontainers {
|
||||||
return p.cadvisor.SubcontainerInfo(containerName, req)
|
return p.cadvisor.SubcontainerInfo(containerName, req)
|
||||||
}
|
}
|
||||||
@ -200,7 +200,7 @@ func (p *StatsProvider) GetRawContainerInfo(containerName string, req *cadvisora
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HasDedicatedImageFs returns true if a dedicated image filesystem exists for storing images.
|
// HasDedicatedImageFs returns true if a dedicated image filesystem exists for storing images.
|
||||||
func (p *StatsProvider) HasDedicatedImageFs() (bool, error) {
|
func (p *Provider) HasDedicatedImageFs() (bool, error) {
|
||||||
device, err := p.containerStatsProvider.ImageFsDevice()
|
device, err := p.containerStatsProvider.ImageFsDevice()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
Loading…
Reference in New Issue
Block a user