mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-02 16:29:21 +00:00
Merge pull request #4650 from xiang90/cadvisor
pkg/kubelet: minor fixes for cadvisor.go
This commit is contained in:
commit
d22fefd72d
@ -27,13 +27,13 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
// ErrNoKubeletContainers returned when there are not containers managed by the kubelet (ie: either no containers on the node, or none that the kubelet cares about).
|
// ErrNoKubeletContainers returned when there are not containers managed by the kubelet (ie: either no containers on the node, or none that the kubelet cares about).
|
||||||
ErrNoKubeletContainers = errors.New("No containers managed by kubelet")
|
ErrNoKubeletContainers = errors.New("no containers managed by kubelet")
|
||||||
|
|
||||||
// ErrContainerNotFound returned when a container in the given pod with the given container name was not found, amongst those managed by the kubelet.
|
// ErrContainerNotFound returned when a container in the given pod with the given container name was not found, amongst those managed by the kubelet.
|
||||||
ErrContainerNotFound = errors.New("No matching container")
|
ErrContainerNotFound = errors.New("no matching container")
|
||||||
|
|
||||||
// ErrCadvisorApiFailure returned when cadvisor couldn't retrieve stats for the given container, either because it isn't running or it was confused by the request
|
// ErrCadvisorApiFailure returned when cadvisor couldn't retrieve stats for the given container, either because it isn't running or it was confused by the request
|
||||||
ErrCadvisorApiFailure = errors.New("Failed to retrieve cadvisor stats")
|
ErrCadvisorApiFailure = errors.New("failed to retrieve cadvisor stats")
|
||||||
)
|
)
|
||||||
|
|
||||||
// cadvisorInterface is an abstract interface for testability. It abstracts the interface of "github.com/google/cadvisor/client".Client.
|
// cadvisorInterface is an abstract interface for testability. It abstracts the interface of "github.com/google/cadvisor/client".Client.
|
||||||
@ -43,11 +43,11 @@ type cadvisorInterface interface {
|
|||||||
MachineInfo() (*cadvisor.MachineInfo, error)
|
MachineInfo() (*cadvisor.MachineInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method takes a container's absolute path and returns the stats for the
|
// statsFromContainerPath takes a container's absolute path and returns the stats for the
|
||||||
// container. The container's absolute path refers to its hierarchy in the
|
// container. The container's absolute path refers to its hierarchy in the
|
||||||
// cgroup file system. e.g. The root container, which represents the whole
|
// cgroup file system. e.g. The root container, which represents the whole
|
||||||
// machine, has path "/"; all docker containers have path "/docker/<docker id>"
|
// machine, has path "/"; all docker containers have path "/docker/<docker id>"
|
||||||
func (kl *Kubelet) statsFromContainerPath(cc cadvisorInterface, containerPath string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
|
func statsFromContainerPath(cc cadvisorInterface, containerPath string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
|
||||||
cinfo, err := cc.ContainerInfo(containerPath, req)
|
cinfo, err := cc.ContainerInfo(containerPath, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -55,9 +55,9 @@ func (kl *Kubelet) statsFromContainerPath(cc cadvisorInterface, containerPath st
|
|||||||
return cinfo, nil
|
return cinfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method takes a Docker container's ID and returns the stats for the
|
// statsFromDockerContainer takes a Docker container's ID and returns the stats for the
|
||||||
// container.
|
// container.
|
||||||
func (kl *Kubelet) statsFromDockerContainer(cc cadvisorInterface, containerId string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
|
func statsFromDockerContainer(cc cadvisorInterface, containerId string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
|
||||||
cinfo, err := cc.DockerContainer(containerId, req)
|
cinfo, err := cc.DockerContainer(containerId, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -69,7 +69,7 @@ func (kl *Kubelet) statsFromDockerContainer(cc cadvisorInterface, containerId st
|
|||||||
func (kl *Kubelet) GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
|
func (kl *Kubelet) GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
|
||||||
cc := kl.GetCadvisorClient()
|
cc := kl.GetCadvisorClient()
|
||||||
if cc == nil {
|
if cc == nil {
|
||||||
return nil, nil
|
return nil, fmt.Errorf("no cadvisor connection")
|
||||||
}
|
}
|
||||||
dockerContainers, err := dockertools.GetKubeletDockerContainers(kl.dockerClient, false)
|
dockerContainers, err := dockertools.GetKubeletDockerContainers(kl.dockerClient, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -83,7 +83,7 @@ func (kl *Kubelet) GetContainerInfo(podFullName string, uid types.UID, container
|
|||||||
return nil, ErrContainerNotFound
|
return nil, ErrContainerNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
ci, err := kl.statsFromDockerContainer(cc, dockerContainer.ID, req)
|
ci, err := statsFromDockerContainer(cc, dockerContainer.ID, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrCadvisorApiFailure
|
return nil, ErrCadvisorApiFailure
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ func (kl *Kubelet) GetRootInfo(req *cadvisor.ContainerInfoRequest) (*cadvisor.Co
|
|||||||
if cc == nil {
|
if cc == nil {
|
||||||
return nil, fmt.Errorf("no cadvisor connection")
|
return nil, fmt.Errorf("no cadvisor connection")
|
||||||
}
|
}
|
||||||
return kl.statsFromContainerPath(cc, "/", req)
|
return statsFromContainerPath(cc, "/", req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kl *Kubelet) GetMachineInfo() (*cadvisor.MachineInfo, error) {
|
func (kl *Kubelet) GetMachineInfo() (*cadvisor.MachineInfo, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user