mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Rename cAdvisor info API to cadvisorApi
This commit is contained in:
parent
a35f4374c5
commit
43b469bd9f
@ -25,16 +25,16 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
info "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ContainerInfoGetter interface {
|
type ContainerInfoGetter interface {
|
||||||
// GetContainerInfo returns information about a container.
|
// GetContainerInfo returns information about a container.
|
||||||
GetContainerInfo(host, podID, containerID string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
GetContainerInfo(host, podID, containerID string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
|
||||||
// GetRootInfo returns information about the root container on a machine.
|
// GetRootInfo returns information about the root container on a machine.
|
||||||
GetRootInfo(host string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
GetRootInfo(host string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
|
||||||
// GetMachineInfo returns the machine's information like number of cores, memory capacity.
|
// GetMachineInfo returns the machine's information like number of cores, memory capacity.
|
||||||
GetMachineInfo(host string) (*info.MachineInfo, error)
|
GetMachineInfo(host string) (*cadvisorApi.MachineInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPContainerInfoGetter struct {
|
type HTTPContainerInfoGetter struct {
|
||||||
@ -42,7 +42,7 @@ type HTTPContainerInfoGetter struct {
|
|||||||
Port int
|
Port int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*info.MachineInfo, error) {
|
func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*cadvisorApi.MachineInfo, error) {
|
||||||
request, err := http.NewRequest(
|
request, err := http.NewRequest(
|
||||||
"GET",
|
"GET",
|
||||||
fmt.Sprintf("http://%v/spec",
|
fmt.Sprintf("http://%v/spec",
|
||||||
@ -63,7 +63,7 @@ func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*info.MachineI
|
|||||||
return nil, fmt.Errorf("trying to get machine spec from %v; received status %v",
|
return nil, fmt.Errorf("trying to get machine spec from %v; received status %v",
|
||||||
host, response.Status)
|
host, response.Status)
|
||||||
}
|
}
|
||||||
var minfo info.MachineInfo
|
var minfo cadvisorApi.MachineInfo
|
||||||
err = json.NewDecoder(response.Body).Decode(&minfo)
|
err = json.NewDecoder(response.Body).Decode(&minfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -71,7 +71,7 @@ func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*info.MachineI
|
|||||||
return &minfo, nil
|
return &minfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *HTTPContainerInfoGetter) getContainerInfo(host, path string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
func (self *HTTPContainerInfoGetter) getContainerInfo(host, path string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
var body io.Reader
|
var body io.Reader
|
||||||
if req != nil {
|
if req != nil {
|
||||||
content, err := json.Marshal(req)
|
content, err := json.Marshal(req)
|
||||||
@ -102,7 +102,7 @@ func (self *HTTPContainerInfoGetter) getContainerInfo(host, path string, req *in
|
|||||||
return nil, fmt.Errorf("trying to get info for %v from %v; received status %v",
|
return nil, fmt.Errorf("trying to get info for %v from %v; received status %v",
|
||||||
path, host, response.Status)
|
path, host, response.Status)
|
||||||
}
|
}
|
||||||
var cinfo info.ContainerInfo
|
var cinfo cadvisorApi.ContainerInfo
|
||||||
err = json.NewDecoder(response.Body).Decode(&cinfo)
|
err = json.NewDecoder(response.Body).Decode(&cinfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -110,7 +110,7 @@ func (self *HTTPContainerInfoGetter) getContainerInfo(host, path string, req *in
|
|||||||
return &cinfo, nil
|
return &cinfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *HTTPContainerInfoGetter) GetContainerInfo(host, podID, containerID string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
func (self *HTTPContainerInfoGetter) GetContainerInfo(host, podID, containerID string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
return self.getContainerInfo(
|
return self.getContainerInfo(
|
||||||
host,
|
host,
|
||||||
fmt.Sprintf("%v/%v", podID, containerID),
|
fmt.Sprintf("%v/%v", podID, containerID),
|
||||||
@ -118,6 +118,6 @@ func (self *HTTPContainerInfoGetter) GetContainerInfo(host, podID, containerID s
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *HTTPContainerInfoGetter) GetRootInfo(host string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
func (self *HTTPContainerInfoGetter) GetRootInfo(host string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
return self.getContainerInfo(host, "", req)
|
return self.getContainerInfo(host, "", req)
|
||||||
}
|
}
|
||||||
|
@ -28,13 +28,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
info "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
itest "github.com/google/cadvisor/info/v1/test"
|
cadvisorApiTest "github.com/google/cadvisor/info/v1/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testHTTPContainerInfoGetter(
|
func testHTTPContainerInfoGetter(
|
||||||
req *info.ContainerInfoRequest,
|
req *cadvisorApi.ContainerInfoRequest,
|
||||||
cinfo *info.ContainerInfo,
|
cinfo *cadvisorApi.ContainerInfo,
|
||||||
podID string,
|
podID string,
|
||||||
containerID string,
|
containerID string,
|
||||||
status int,
|
status int,
|
||||||
@ -53,7 +53,7 @@ func testHTTPContainerInfoGetter(
|
|||||||
expectedPath, r.URL.Path)
|
expectedPath, r.URL.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
var receivedReq info.ContainerInfoRequest
|
var receivedReq cadvisorApi.ContainerInfoRequest
|
||||||
err := json.NewDecoder(r.Body).Decode(&receivedReq)
|
err := json.NewDecoder(r.Body).Decode(&receivedReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -87,7 +87,7 @@ func testHTTPContainerInfoGetter(
|
|||||||
Port: port,
|
Port: port,
|
||||||
}
|
}
|
||||||
|
|
||||||
var receivedContainerInfo *info.ContainerInfo
|
var receivedContainerInfo *cadvisorApi.ContainerInfo
|
||||||
if len(podID) > 0 && len(containerID) > 0 {
|
if len(podID) > 0 && len(containerID) > 0 {
|
||||||
receivedContainerInfo, err = containerInfoGetter.GetContainerInfo(parts[0], podID, containerID, req)
|
receivedContainerInfo, err = containerInfoGetter.GetContainerInfo(parts[0], podID, containerID, req)
|
||||||
} else {
|
} else {
|
||||||
@ -109,10 +109,10 @@ func testHTTPContainerInfoGetter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPContainerInfoGetterGetContainerInfoSuccessfully(t *testing.T) {
|
func TestHTTPContainerInfoGetterGetContainerInfoSuccessfully(t *testing.T) {
|
||||||
req := &info.ContainerInfoRequest{
|
req := &cadvisorApi.ContainerInfoRequest{
|
||||||
NumStats: 10,
|
NumStats: 10,
|
||||||
}
|
}
|
||||||
cinfo := itest.GenerateRandomContainerInfo(
|
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
|
||||||
"dockerIDWhichWillNotBeChecked", // docker ID
|
"dockerIDWhichWillNotBeChecked", // docker ID
|
||||||
2, // Number of cores
|
2, // Number of cores
|
||||||
req,
|
req,
|
||||||
@ -122,10 +122,10 @@ func TestHTTPContainerInfoGetterGetContainerInfoSuccessfully(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPContainerInfoGetterGetRootInfoSuccessfully(t *testing.T) {
|
func TestHTTPContainerInfoGetterGetRootInfoSuccessfully(t *testing.T) {
|
||||||
req := &info.ContainerInfoRequest{
|
req := &cadvisorApi.ContainerInfoRequest{
|
||||||
NumStats: 10,
|
NumStats: 10,
|
||||||
}
|
}
|
||||||
cinfo := itest.GenerateRandomContainerInfo(
|
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
|
||||||
"dockerIDWhichWillNotBeChecked", // docker ID
|
"dockerIDWhichWillNotBeChecked", // docker ID
|
||||||
2, // Number of cores
|
2, // Number of cores
|
||||||
req,
|
req,
|
||||||
@ -135,10 +135,10 @@ func TestHTTPContainerInfoGetterGetRootInfoSuccessfully(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPContainerInfoGetterGetContainerInfoWithError(t *testing.T) {
|
func TestHTTPContainerInfoGetterGetContainerInfoWithError(t *testing.T) {
|
||||||
req := &info.ContainerInfoRequest{
|
req := &cadvisorApi.ContainerInfoRequest{
|
||||||
NumStats: 10,
|
NumStats: 10,
|
||||||
}
|
}
|
||||||
cinfo := itest.GenerateRandomContainerInfo(
|
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
|
||||||
"dockerIDWhichWillNotBeChecked", // docker ID
|
"dockerIDWhichWillNotBeChecked", // docker ID
|
||||||
2, // Number of cores
|
2, // Number of cores
|
||||||
req,
|
req,
|
||||||
@ -148,10 +148,10 @@ func TestHTTPContainerInfoGetterGetContainerInfoWithError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPContainerInfoGetterGetRootInfoWithError(t *testing.T) {
|
func TestHTTPContainerInfoGetterGetRootInfoWithError(t *testing.T) {
|
||||||
req := &info.ContainerInfoRequest{
|
req := &cadvisorApi.ContainerInfoRequest{
|
||||||
NumStats: 10,
|
NumStats: 10,
|
||||||
}
|
}
|
||||||
cinfo := itest.GenerateRandomContainerInfo(
|
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
|
||||||
"dockerIDWhichWillNotBeChecked", // docker ID
|
"dockerIDWhichWillNotBeChecked", // docker ID
|
||||||
2, // Number of cores
|
2, // Number of cores
|
||||||
req,
|
req,
|
||||||
@ -161,7 +161,7 @@ func TestHTTPContainerInfoGetterGetRootInfoWithError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHTTPGetMachineInfo(t *testing.T) {
|
func TestHTTPGetMachineInfo(t *testing.T) {
|
||||||
mspec := &info.MachineInfo{
|
mspec := &cadvisorApi.MachineInfo{
|
||||||
NumCores: 4,
|
NumCores: 4,
|
||||||
MemoryCapacity: 2048,
|
MemoryCapacity: 2048,
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
cadvisor "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -38,16 +38,16 @@ var (
|
|||||||
|
|
||||||
// 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.
|
||||||
type cadvisorInterface interface {
|
type cadvisorInterface interface {
|
||||||
DockerContainer(name string, req *cadvisor.ContainerInfoRequest) (cadvisor.ContainerInfo, error)
|
DockerContainer(name string, req *cadvisorApi.ContainerInfoRequest) (cadvisorApi.ContainerInfo, error)
|
||||||
ContainerInfo(name string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error)
|
ContainerInfo(name string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
|
||||||
MachineInfo() (*cadvisor.MachineInfo, error)
|
MachineInfo() (*cadvisorApi.MachineInfo, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// statsFromContainerPath 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 statsFromContainerPath(cc cadvisorInterface, containerPath string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
|
func statsFromContainerPath(cc cadvisorInterface, containerPath string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.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
|
||||||
@ -57,7 +57,7 @@ func statsFromContainerPath(cc cadvisorInterface, containerPath string, req *cad
|
|||||||
|
|
||||||
// statsFromDockerContainer 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 statsFromDockerContainer(cc cadvisorInterface, containerId string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
|
func statsFromDockerContainer(cc cadvisorInterface, containerId string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.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
|
||||||
@ -66,7 +66,7 @@ func statsFromDockerContainer(cc cadvisorInterface, containerId string, req *cad
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetContainerInfo returns stats (from Cadvisor) for a container.
|
// GetContainerInfo returns stats (from Cadvisor) for a container.
|
||||||
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 *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
cc := kl.GetCadvisorClient()
|
cc := kl.GetCadvisorClient()
|
||||||
if cc == nil {
|
if cc == nil {
|
||||||
return nil, fmt.Errorf("no cadvisor connection")
|
return nil, fmt.Errorf("no cadvisor connection")
|
||||||
@ -91,7 +91,7 @@ func (kl *Kubelet) GetContainerInfo(podFullName string, uid types.UID, container
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetRootInfo returns stats (from Cadvisor) of current machine (root container).
|
// GetRootInfo returns stats (from Cadvisor) of current machine (root container).
|
||||||
func (kl *Kubelet) GetRootInfo(req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
|
func (kl *Kubelet) GetRootInfo(req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
cc := kl.GetCadvisorClient()
|
cc := kl.GetCadvisorClient()
|
||||||
if cc == nil {
|
if cc == nil {
|
||||||
return nil, fmt.Errorf("no cadvisor connection")
|
return nil, fmt.Errorf("no cadvisor connection")
|
||||||
@ -99,7 +99,7 @@ func (kl *Kubelet) GetRootInfo(req *cadvisor.ContainerInfoRequest) (*cadvisor.Co
|
|||||||
return statsFromContainerPath(cc, "/", req)
|
return statsFromContainerPath(cc, "/", req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (kl *Kubelet) GetMachineInfo() (*cadvisor.MachineInfo, error) {
|
func (kl *Kubelet) GetMachineInfo() (*cadvisorApi.MachineInfo, error) {
|
||||||
cc := kl.GetCadvisorClient()
|
cc := kl.GetCadvisorClient()
|
||||||
if cc == nil {
|
if cc == nil {
|
||||||
return nil, fmt.Errorf("no cadvisor connection")
|
return nil, fmt.Errorf("no cadvisor connection")
|
||||||
|
@ -41,7 +41,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/fsouza/go-dockerclient"
|
"github.com/fsouza/go-dockerclient"
|
||||||
info "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1258,34 +1258,34 @@ func (f *errorTestingDockerClient) ListContainers(options docker.ListContainersO
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ContainerInfo is a mock implementation of CadvisorInterface.ContainerInfo.
|
// ContainerInfo is a mock implementation of CadvisorInterface.ContainerInfo.
|
||||||
func (c *mockCadvisorClient) ContainerInfo(name string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
func (c *mockCadvisorClient) ContainerInfo(name string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
args := c.Called(name, req)
|
args := c.Called(name, req)
|
||||||
return args.Get(0).(*info.ContainerInfo), args.Error(1)
|
return args.Get(0).(*cadvisorApi.ContainerInfo), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DockerContainer is a mock implementation of CadvisorInterface.DockerContainer.
|
// DockerContainer is a mock implementation of CadvisorInterface.DockerContainer.
|
||||||
func (c *mockCadvisorClient) DockerContainer(name string, req *info.ContainerInfoRequest) (info.ContainerInfo, error) {
|
func (c *mockCadvisorClient) DockerContainer(name string, req *cadvisorApi.ContainerInfoRequest) (cadvisorApi.ContainerInfo, error) {
|
||||||
args := c.Called(name, req)
|
args := c.Called(name, req)
|
||||||
return args.Get(0).(info.ContainerInfo), args.Error(1)
|
return args.Get(0).(cadvisorApi.ContainerInfo), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MachineInfo is a mock implementation of CadvisorInterface.MachineInfo.
|
// MachineInfo is a mock implementation of CadvisorInterface.MachineInfo.
|
||||||
func (c *mockCadvisorClient) MachineInfo() (*info.MachineInfo, error) {
|
func (c *mockCadvisorClient) MachineInfo() (*cadvisorApi.MachineInfo, error) {
|
||||||
args := c.Called()
|
args := c.Called()
|
||||||
return args.Get(0).(*info.MachineInfo), args.Error(1)
|
return args.Get(0).(*cadvisorApi.MachineInfo), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContainerInfo(t *testing.T) {
|
func TestGetContainerInfo(t *testing.T) {
|
||||||
containerID := "ab2cdf"
|
containerID := "ab2cdf"
|
||||||
containerPath := fmt.Sprintf("/docker/%v", containerID)
|
containerPath := fmt.Sprintf("/docker/%v", containerID)
|
||||||
containerInfo := info.ContainerInfo{
|
containerInfo := cadvisorApi.ContainerInfo{
|
||||||
ContainerReference: info.ContainerReference{
|
ContainerReference: cadvisorApi.ContainerReference{
|
||||||
Name: containerPath,
|
Name: containerPath,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
mockCadvisor := &mockCadvisorClient{}
|
mockCadvisor := &mockCadvisorClient{}
|
||||||
cadvisorReq := &info.ContainerInfoRequest{}
|
cadvisorReq := &cadvisorApi.ContainerInfoRequest{}
|
||||||
mockCadvisor.On("DockerContainer", containerID, cadvisorReq).Return(containerInfo, nil)
|
mockCadvisor.On("DockerContainer", containerID, cadvisorReq).Return(containerInfo, nil)
|
||||||
|
|
||||||
kubelet, fakeDocker, _ := newTestKubelet(t)
|
kubelet, fakeDocker, _ := newTestKubelet(t)
|
||||||
@ -1311,15 +1311,15 @@ func TestGetContainerInfo(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetRootInfo(t *testing.T) {
|
func TestGetRootInfo(t *testing.T) {
|
||||||
containerPath := "/"
|
containerPath := "/"
|
||||||
containerInfo := &info.ContainerInfo{
|
containerInfo := &cadvisorApi.ContainerInfo{
|
||||||
ContainerReference: info.ContainerReference{
|
ContainerReference: cadvisorApi.ContainerReference{
|
||||||
Name: containerPath,
|
Name: containerPath,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
fakeDocker := dockertools.FakeDockerClient{}
|
fakeDocker := dockertools.FakeDockerClient{}
|
||||||
|
|
||||||
mockCadvisor := &mockCadvisorClient{}
|
mockCadvisor := &mockCadvisorClient{}
|
||||||
cadvisorReq := &info.ContainerInfoRequest{}
|
cadvisorReq := &cadvisorApi.ContainerInfoRequest{}
|
||||||
mockCadvisor.On("ContainerInfo", containerPath, cadvisorReq).Return(containerInfo, nil)
|
mockCadvisor.On("ContainerInfo", containerPath, cadvisorReq).Return(containerInfo, nil)
|
||||||
|
|
||||||
kubelet := Kubelet{
|
kubelet := Kubelet{
|
||||||
@ -1357,9 +1357,9 @@ func TestGetContainerInfoWithoutCadvisor(t *testing.T) {
|
|||||||
func TestGetContainerInfoWhenCadvisorFailed(t *testing.T) {
|
func TestGetContainerInfoWhenCadvisorFailed(t *testing.T) {
|
||||||
containerID := "ab2cdf"
|
containerID := "ab2cdf"
|
||||||
|
|
||||||
containerInfo := info.ContainerInfo{}
|
containerInfo := cadvisorApi.ContainerInfo{}
|
||||||
mockCadvisor := &mockCadvisorClient{}
|
mockCadvisor := &mockCadvisorClient{}
|
||||||
cadvisorReq := &info.ContainerInfoRequest{}
|
cadvisorReq := &cadvisorApi.ContainerInfoRequest{}
|
||||||
mockCadvisor.On("DockerContainer", containerID, cadvisorReq).Return(containerInfo, ErrCadvisorApiFailure)
|
mockCadvisor.On("DockerContainer", containerID, cadvisorReq).Return(containerInfo, ErrCadvisorApiFailure)
|
||||||
|
|
||||||
kubelet, fakeDocker, _ := newTestKubelet(t)
|
kubelet, fakeDocker, _ := newTestKubelet(t)
|
||||||
|
@ -39,7 +39,7 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream/spdy"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream/spdy"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
info "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -77,10 +77,10 @@ func ListenAndServeKubeletServer(host HostInterface, address net.IP, port uint,
|
|||||||
// HostInterface contains all the kubelet methods required by the server.
|
// HostInterface contains all the kubelet methods required by the server.
|
||||||
// For testablitiy.
|
// For testablitiy.
|
||||||
type HostInterface interface {
|
type HostInterface interface {
|
||||||
GetContainerInfo(podFullName string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
|
||||||
GetRootInfo(req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
GetRootInfo(req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
|
||||||
GetDockerVersion() ([]uint, error)
|
GetDockerVersion() ([]uint, error)
|
||||||
GetMachineInfo() (*info.MachineInfo, error)
|
GetMachineInfo() (*cadvisorApi.MachineInfo, error)
|
||||||
GetBoundPods() ([]api.BoundPod, error)
|
GetBoundPods() ([]api.BoundPod, error)
|
||||||
GetPodByName(namespace, name string) (*api.BoundPod, bool)
|
GetPodByName(namespace, name string) (*api.BoundPod, bool)
|
||||||
GetPodStatus(name string, uid types.UID) (api.PodStatus, error)
|
GetPodStatus(name string, uid types.UID) (api.PodStatus, error)
|
||||||
@ -633,9 +633,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
|
func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
|
||||||
// /stats/<podfullname>/<containerName> or /stats/<namespace>/<podfullname>/<uid>/<containerName>
|
// /stats/<podfullname>/<containerName> or /stats/<namespace>/<podfullname>/<uid>/<containerName>
|
||||||
components := strings.Split(strings.TrimPrefix(path.Clean(req.URL.Path), "/"), "/")
|
components := strings.Split(strings.TrimPrefix(path.Clean(req.URL.Path), "/"), "/")
|
||||||
var stats *info.ContainerInfo
|
var stats *cadvisorApi.ContainerInfo
|
||||||
var err error
|
var err error
|
||||||
var query info.ContainerInfoRequest
|
var query cadvisorApi.ContainerInfoRequest
|
||||||
err = json.NewDecoder(req.Body).Decode(&query)
|
err = json.NewDecoder(req.Body).Decode(&query)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
s.error(w, err)
|
s.error(w, err)
|
||||||
|
@ -34,15 +34,15 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream/spdy"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream/spdy"
|
||||||
info "github.com/google/cadvisor/info/v1"
|
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeKubelet struct {
|
type fakeKubelet struct {
|
||||||
podByNameFunc func(namespace, name string) (*api.BoundPod, bool)
|
podByNameFunc func(namespace, name string) (*api.BoundPod, bool)
|
||||||
statusFunc func(name string) (api.PodStatus, error)
|
statusFunc func(name string) (api.PodStatus, error)
|
||||||
containerInfoFunc func(podFullName string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
containerInfoFunc func(podFullName string, uid types.UID, containerName string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
|
||||||
rootInfoFunc func(query *info.ContainerInfoRequest) (*info.ContainerInfo, error)
|
rootInfoFunc func(query *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
|
||||||
machineInfoFunc func() (*info.MachineInfo, error)
|
machineInfoFunc func() (*cadvisorApi.MachineInfo, error)
|
||||||
boundPodsFunc func() ([]api.BoundPod, error)
|
boundPodsFunc func() ([]api.BoundPod, error)
|
||||||
logFunc func(w http.ResponseWriter, req *http.Request)
|
logFunc func(w http.ResponseWriter, req *http.Request)
|
||||||
runFunc func(podFullName string, uid types.UID, containerName string, cmd []string) ([]byte, error)
|
runFunc func(podFullName string, uid types.UID, containerName string, cmd []string) ([]byte, error)
|
||||||
@ -62,11 +62,11 @@ func (fk *fakeKubelet) GetPodStatus(name string, uid types.UID) (api.PodStatus,
|
|||||||
return fk.statusFunc(name)
|
return fk.statusFunc(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fk *fakeKubelet) GetContainerInfo(podFullName string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
func (fk *fakeKubelet) GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
return fk.containerInfoFunc(podFullName, uid, containerName, req)
|
return fk.containerInfoFunc(podFullName, uid, containerName, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fk *fakeKubelet) GetRootInfo(req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
func (fk *fakeKubelet) GetRootInfo(req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
return fk.rootInfoFunc(req)
|
return fk.rootInfoFunc(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ func (fk *fakeKubelet) GetDockerVersion() ([]uint, error) {
|
|||||||
return fk.dockerVersionFunc()
|
return fk.dockerVersionFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fk *fakeKubelet) GetMachineInfo() (*info.MachineInfo, error) {
|
func (fk *fakeKubelet) GetMachineInfo() (*cadvisorApi.MachineInfo, error) {
|
||||||
return fk.machineInfoFunc()
|
return fk.machineInfoFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,11 +189,11 @@ func TestPodStatus(t *testing.T) {
|
|||||||
|
|
||||||
func TestContainerInfo(t *testing.T) {
|
func TestContainerInfo(t *testing.T) {
|
||||||
fw := newServerTest()
|
fw := newServerTest()
|
||||||
expectedInfo := &info.ContainerInfo{}
|
expectedInfo := &cadvisorApi.ContainerInfo{}
|
||||||
podID := "somepod"
|
podID := "somepod"
|
||||||
expectedPodID := "somepod" + ".default.etcd"
|
expectedPodID := "somepod" + ".default.etcd"
|
||||||
expectedContainerName := "goodcontainer"
|
expectedContainerName := "goodcontainer"
|
||||||
fw.fakeKubelet.containerInfoFunc = func(podID string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
fw.fakeKubelet.containerInfoFunc = func(podID string, uid types.UID, containerName string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
if podID != expectedPodID || containerName != expectedContainerName {
|
if podID != expectedPodID || containerName != expectedContainerName {
|
||||||
return nil, fmt.Errorf("bad podID or containerName: podID=%v; containerName=%v", podID, containerName)
|
return nil, fmt.Errorf("bad podID or containerName: podID=%v; containerName=%v", podID, containerName)
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ func TestContainerInfo(t *testing.T) {
|
|||||||
t.Fatalf("Got error GETing: %v", err)
|
t.Fatalf("Got error GETing: %v", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
var receivedInfo info.ContainerInfo
|
var receivedInfo cadvisorApi.ContainerInfo
|
||||||
err = json.NewDecoder(resp.Body).Decode(&receivedInfo)
|
err = json.NewDecoder(resp.Body).Decode(&receivedInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("received invalid json data: %v", err)
|
t.Fatalf("received invalid json data: %v", err)
|
||||||
@ -217,13 +217,13 @@ func TestContainerInfo(t *testing.T) {
|
|||||||
|
|
||||||
func TestContainerInfoWithUidNamespace(t *testing.T) {
|
func TestContainerInfoWithUidNamespace(t *testing.T) {
|
||||||
fw := newServerTest()
|
fw := newServerTest()
|
||||||
expectedInfo := &info.ContainerInfo{}
|
expectedInfo := &cadvisorApi.ContainerInfo{}
|
||||||
podID := "somepod"
|
podID := "somepod"
|
||||||
expectedNamespace := "custom"
|
expectedNamespace := "custom"
|
||||||
expectedPodID := "somepod" + "." + expectedNamespace + ".etcd"
|
expectedPodID := "somepod" + "." + expectedNamespace + ".etcd"
|
||||||
expectedContainerName := "goodcontainer"
|
expectedContainerName := "goodcontainer"
|
||||||
expectedUid := "9b01b80f-8fb4-11e4-95ab-4200af06647"
|
expectedUid := "9b01b80f-8fb4-11e4-95ab-4200af06647"
|
||||||
fw.fakeKubelet.containerInfoFunc = func(podID string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
fw.fakeKubelet.containerInfoFunc = func(podID string, uid types.UID, containerName string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
if podID != expectedPodID || string(uid) != expectedUid || containerName != expectedContainerName {
|
if podID != expectedPodID || string(uid) != expectedUid || containerName != expectedContainerName {
|
||||||
return nil, fmt.Errorf("bad podID or uid or containerName: podID=%v; uid=%v; containerName=%v", podID, uid, containerName)
|
return nil, fmt.Errorf("bad podID or uid or containerName: podID=%v; uid=%v; containerName=%v", podID, uid, containerName)
|
||||||
}
|
}
|
||||||
@ -235,7 +235,7 @@ func TestContainerInfoWithUidNamespace(t *testing.T) {
|
|||||||
t.Fatalf("Got error GETing: %v", err)
|
t.Fatalf("Got error GETing: %v", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
var receivedInfo info.ContainerInfo
|
var receivedInfo cadvisorApi.ContainerInfo
|
||||||
err = json.NewDecoder(resp.Body).Decode(&receivedInfo)
|
err = json.NewDecoder(resp.Body).Decode(&receivedInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("received invalid json data: %v", err)
|
t.Fatalf("received invalid json data: %v", err)
|
||||||
@ -251,7 +251,7 @@ func TestContainerNotFound(t *testing.T) {
|
|||||||
expectedNamespace := "custom"
|
expectedNamespace := "custom"
|
||||||
expectedContainerName := "slowstartcontainer"
|
expectedContainerName := "slowstartcontainer"
|
||||||
expectedUid := "9b01b80f-8fb4-11e4-95ab-4200af06647"
|
expectedUid := "9b01b80f-8fb4-11e4-95ab-4200af06647"
|
||||||
fw.fakeKubelet.containerInfoFunc = func(podID string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
fw.fakeKubelet.containerInfoFunc = func(podID string, uid types.UID, containerName string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
return nil, ErrContainerNotFound
|
return nil, ErrContainerNotFound
|
||||||
}
|
}
|
||||||
resp, err := http.Get(fw.testHTTPServer.URL + fmt.Sprintf("/stats/%v/%v/%v/%v", expectedNamespace, podID, expectedUid, expectedContainerName))
|
resp, err := http.Get(fw.testHTTPServer.URL + fmt.Sprintf("/stats/%v/%v/%v/%v", expectedNamespace, podID, expectedUid, expectedContainerName))
|
||||||
@ -266,8 +266,8 @@ func TestContainerNotFound(t *testing.T) {
|
|||||||
|
|
||||||
func TestRootInfo(t *testing.T) {
|
func TestRootInfo(t *testing.T) {
|
||||||
fw := newServerTest()
|
fw := newServerTest()
|
||||||
expectedInfo := &info.ContainerInfo{}
|
expectedInfo := &cadvisorApi.ContainerInfo{}
|
||||||
fw.fakeKubelet.rootInfoFunc = func(req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
|
fw.fakeKubelet.rootInfoFunc = func(req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||||
return expectedInfo, nil
|
return expectedInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ func TestRootInfo(t *testing.T) {
|
|||||||
t.Fatalf("Got error GETing: %v", err)
|
t.Fatalf("Got error GETing: %v", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
var receivedInfo info.ContainerInfo
|
var receivedInfo cadvisorApi.ContainerInfo
|
||||||
err = json.NewDecoder(resp.Body).Decode(&receivedInfo)
|
err = json.NewDecoder(resp.Body).Decode(&receivedInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("received invalid json data: %v", err)
|
t.Fatalf("received invalid json data: %v", err)
|
||||||
@ -288,11 +288,11 @@ func TestRootInfo(t *testing.T) {
|
|||||||
|
|
||||||
func TestMachineInfo(t *testing.T) {
|
func TestMachineInfo(t *testing.T) {
|
||||||
fw := newServerTest()
|
fw := newServerTest()
|
||||||
expectedInfo := &info.MachineInfo{
|
expectedInfo := &cadvisorApi.MachineInfo{
|
||||||
NumCores: 4,
|
NumCores: 4,
|
||||||
MemoryCapacity: 1024,
|
MemoryCapacity: 1024,
|
||||||
}
|
}
|
||||||
fw.fakeKubelet.machineInfoFunc = func() (*info.MachineInfo, error) {
|
fw.fakeKubelet.machineInfoFunc = func() (*cadvisorApi.MachineInfo, error) {
|
||||||
return expectedInfo, nil
|
return expectedInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +301,7 @@ func TestMachineInfo(t *testing.T) {
|
|||||||
t.Fatalf("Got error GETing: %v", err)
|
t.Fatalf("Got error GETing: %v", err)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
var receivedInfo info.MachineInfo
|
var receivedInfo cadvisorApi.MachineInfo
|
||||||
err = json.NewDecoder(resp.Body).Decode(&receivedInfo)
|
err = json.NewDecoder(resp.Body).Decode(&receivedInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("received invalid json data: %v", err)
|
t.Fatalf("received invalid json data: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user