Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f6721480
Commit
f6721480
authored
Jan 08, 2018
by
David Ashpole
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enable on-demand metrics for eviction
parent
6244ff36
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
48 additions
and
35 deletions
+48
-35
eviction_manager.go
pkg/kubelet/eviction/eviction_manager.go
+3
-1
helpers.go
pkg/kubelet/eviction/helpers.go
+2
-1
helpers_test.go
pkg/kubelet/eviction/helpers_test.go
+1
-1
server_test.go
pkg/kubelet/server/server_test.go
+1
-1
handler.go
pkg/kubelet/server/stats/handler.go
+4
-2
summary.go
pkg/kubelet/server/stats/summary.go
+6
-5
summary_test.go
pkg/kubelet/server/stats/summary_test.go
+5
-5
mock_stats_provider.go
pkg/kubelet/server/stats/testing/mock_stats_provider.go
+9
-9
helper.go
pkg/kubelet/stats/helper.go
+9
-3
stats_provider.go
pkg/kubelet/stats/stats_provider.go
+4
-4
stats_provider_test.go
pkg/kubelet/stats/stats_provider_test.go
+4
-3
No files found.
pkg/kubelet/eviction/eviction_manager.go
View file @
f6721480
...
@@ -455,7 +455,9 @@ func (m *managerImpl) reclaimNodeLevelResources(resourceToReclaim v1.ResourceNam
...
@@ -455,7 +455,9 @@ func (m *managerImpl) reclaimNodeLevelResources(resourceToReclaim v1.ResourceNam
// localStorageEviction checks the EmptyDir volume usage for each pod and determine whether it exceeds the specified limit and needs
// localStorageEviction checks the EmptyDir volume usage for each pod and determine whether it exceeds the specified limit and needs
// to be evicted. It also checks every container in the pod, if the container overlay usage exceeds the limit, the pod will be evicted too.
// to be evicted. It also checks every container in the pod, if the container overlay usage exceeds the limit, the pod will be evicted too.
func
(
m
*
managerImpl
)
localStorageEviction
(
pods
[]
*
v1
.
Pod
)
[]
*
v1
.
Pod
{
func
(
m
*
managerImpl
)
localStorageEviction
(
pods
[]
*
v1
.
Pod
)
[]
*
v1
.
Pod
{
summary
,
err
:=
m
.
summaryProvider
.
Get
()
// do not update node-level stats as local storage evictions do not utilize them.
forceStatsUpdate
:=
false
summary
,
err
:=
m
.
summaryProvider
.
Get
(
forceStatsUpdate
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Could not get summary provider"
)
glog
.
Errorf
(
"Could not get summary provider"
)
return
nil
return
nil
...
...
pkg/kubelet/eviction/helpers.go
View file @
f6721480
...
@@ -712,7 +712,8 @@ func (a byEvictionPriority) Less(i, j int) bool {
...
@@ -712,7 +712,8 @@ func (a byEvictionPriority) Less(i, j int) bool {
// makeSignalObservations derives observations using the specified summary provider.
// makeSignalObservations derives observations using the specified summary provider.
func
makeSignalObservations
(
summaryProvider
stats
.
SummaryProvider
,
capacityProvider
CapacityProvider
,
pods
[]
*
v1
.
Pod
)
(
signalObservations
,
statsFunc
,
error
)
{
func
makeSignalObservations
(
summaryProvider
stats
.
SummaryProvider
,
capacityProvider
CapacityProvider
,
pods
[]
*
v1
.
Pod
)
(
signalObservations
,
statsFunc
,
error
)
{
summary
,
err
:=
summaryProvider
.
Get
()
updateStats
:=
true
summary
,
err
:=
summaryProvider
.
Get
(
updateStats
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
...
...
pkg/kubelet/eviction/helpers_test.go
View file @
f6721480
...
@@ -920,7 +920,7 @@ type fakeSummaryProvider struct {
...
@@ -920,7 +920,7 @@ type fakeSummaryProvider struct {
result
*
statsapi
.
Summary
result
*
statsapi
.
Summary
}
}
func
(
f
*
fakeSummaryProvider
)
Get
()
(
*
statsapi
.
Summary
,
error
)
{
func
(
f
*
fakeSummaryProvider
)
Get
(
updateStats
bool
)
(
*
statsapi
.
Summary
,
error
)
{
return
f
.
result
,
nil
return
f
.
result
,
nil
}
}
...
...
pkg/kubelet/server/server_test.go
View file @
f6721480
...
@@ -176,7 +176,7 @@ func (fk *fakeKubelet) ListVolumesForPod(podUID types.UID) (map[string]volume.Vo
...
@@ -176,7 +176,7 @@ func (fk *fakeKubelet) ListVolumesForPod(podUID types.UID) (map[string]volume.Vo
func
(
_
*
fakeKubelet
)
RootFsStats
()
(
*
statsapi
.
FsStats
,
error
)
{
return
nil
,
nil
}
func
(
_
*
fakeKubelet
)
RootFsStats
()
(
*
statsapi
.
FsStats
,
error
)
{
return
nil
,
nil
}
func
(
_
*
fakeKubelet
)
ListPodStats
()
([]
statsapi
.
PodStats
,
error
)
{
return
nil
,
nil
}
func
(
_
*
fakeKubelet
)
ListPodStats
()
([]
statsapi
.
PodStats
,
error
)
{
return
nil
,
nil
}
func
(
_
*
fakeKubelet
)
ImageFsStats
()
(
*
statsapi
.
FsStats
,
error
)
{
return
nil
,
nil
}
func
(
_
*
fakeKubelet
)
ImageFsStats
()
(
*
statsapi
.
FsStats
,
error
)
{
return
nil
,
nil
}
func
(
_
*
fakeKubelet
)
GetCgroupStats
(
cgroupName
string
)
(
*
statsapi
.
ContainerStats
,
*
statsapi
.
NetworkStats
,
error
)
{
func
(
_
*
fakeKubelet
)
GetCgroupStats
(
cgroupName
string
,
updateStats
bool
)
(
*
statsapi
.
ContainerStats
,
*
statsapi
.
NetworkStats
,
error
)
{
return
nil
,
nil
,
nil
return
nil
,
nil
,
nil
}
}
...
...
pkg/kubelet/server/stats/handler.go
View file @
f6721480
...
@@ -50,7 +50,7 @@ type StatsProvider interface {
...
@@ -50,7 +50,7 @@ type StatsProvider interface {
//
//
// GetCgroupStats returns the stats and the networking usage of the cgroup
// GetCgroupStats returns the stats and the networking usage of the cgroup
// with the specified cgroupName.
// with the specified cgroupName.
GetCgroupStats
(
cgroupName
string
)
(
*
statsapi
.
ContainerStats
,
*
statsapi
.
NetworkStats
,
error
)
GetCgroupStats
(
cgroupName
string
,
updateStats
bool
)
(
*
statsapi
.
ContainerStats
,
*
statsapi
.
NetworkStats
,
error
)
// RootFsStats returns the stats of the node root filesystem.
// RootFsStats returns the stats of the node root filesystem.
RootFsStats
()
(
*
statsapi
.
FsStats
,
error
)
RootFsStats
()
(
*
statsapi
.
FsStats
,
error
)
...
@@ -183,7 +183,9 @@ func (h *handler) handleStats(request *restful.Request, response *restful.Respon
...
@@ -183,7 +183,9 @@ func (h *handler) handleStats(request *restful.Request, response *restful.Respon
// Handles stats summary requests to /stats/summary
// Handles stats summary requests to /stats/summary
func
(
h
*
handler
)
handleSummary
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
func
(
h
*
handler
)
handleSummary
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
summary
,
err
:=
h
.
summaryProvider
.
Get
()
// external calls to the summary API use cached stats
forceStatsUpdate
:=
false
summary
,
err
:=
h
.
summaryProvider
.
Get
(
forceStatsUpdate
)
if
err
!=
nil
{
if
err
!=
nil
{
handleError
(
response
,
"/stats/summary"
,
err
)
handleError
(
response
,
"/stats/summary"
,
err
)
}
else
{
}
else
{
...
...
pkg/kubelet/server/stats/summary.go
View file @
f6721480
...
@@ -25,7 +25,9 @@ import (
...
@@ -25,7 +25,9 @@ import (
)
)
type
SummaryProvider
interface
{
type
SummaryProvider
interface
{
Get
()
(
*
statsapi
.
Summary
,
error
)
// Get provides a new Summary with the stats from Kubelet,
// and will update some stats if updateStats is true
Get
(
updateStats
bool
)
(
*
statsapi
.
Summary
,
error
)
}
}
// summaryProviderImpl implements the SummaryProvider interface.
// summaryProviderImpl implements the SummaryProvider interface.
...
@@ -41,8 +43,7 @@ func NewSummaryProvider(statsProvider StatsProvider) SummaryProvider {
...
@@ -41,8 +43,7 @@ func NewSummaryProvider(statsProvider StatsProvider) SummaryProvider {
return
&
summaryProviderImpl
{
statsProvider
}
return
&
summaryProviderImpl
{
statsProvider
}
}
}
// Get provides a new Summary with the stats from Kubelet.
func
(
sp
*
summaryProviderImpl
)
Get
(
updateStats
bool
)
(
*
statsapi
.
Summary
,
error
)
{
func
(
sp
*
summaryProviderImpl
)
Get
()
(
*
statsapi
.
Summary
,
error
)
{
// TODO(timstclair): Consider returning a best-effort response if any of
// TODO(timstclair): Consider returning a best-effort response if any of
// the following errors occur.
// the following errors occur.
node
,
err
:=
sp
.
provider
.
GetNode
()
node
,
err
:=
sp
.
provider
.
GetNode
()
...
@@ -50,7 +51,7 @@ func (sp *summaryProviderImpl) Get() (*statsapi.Summary, error) {
...
@@ -50,7 +51,7 @@ func (sp *summaryProviderImpl) Get() (*statsapi.Summary, error) {
return
nil
,
fmt
.
Errorf
(
"failed to get node info: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to get node info: %v"
,
err
)
}
}
nodeConfig
:=
sp
.
provider
.
GetNodeConfig
()
nodeConfig
:=
sp
.
provider
.
GetNodeConfig
()
rootStats
,
networkStats
,
err
:=
sp
.
provider
.
GetCgroupStats
(
"/"
)
rootStats
,
networkStats
,
err
:=
sp
.
provider
.
GetCgroupStats
(
"/"
,
updateStats
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to get root cgroup stats: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to get root cgroup stats: %v"
,
err
)
}
}
...
@@ -87,7 +88,7 @@ func (sp *summaryProviderImpl) Get() (*statsapi.Summary, error) {
...
@@ -87,7 +88,7 @@ func (sp *summaryProviderImpl) Get() (*statsapi.Summary, error) {
if
name
==
""
{
if
name
==
""
{
continue
continue
}
}
s
,
_
,
err
:=
sp
.
provider
.
GetCgroupStats
(
name
)
s
,
_
,
err
:=
sp
.
provider
.
GetCgroupStats
(
name
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Errorf
(
"Failed to get system container stats for %q: %v"
,
name
,
err
)
glog
.
Errorf
(
"Failed to get system container stats for %q: %v"
,
name
,
err
)
continue
continue
...
...
pkg/kubelet/server/stats/summary_test.go
View file @
f6721480
...
@@ -69,13 +69,13 @@ func TestSummaryProvider(t *testing.T) {
...
@@ -69,13 +69,13 @@ func TestSummaryProvider(t *testing.T) {
On
(
"ListPodStats"
)
.
Return
(
podStats
,
nil
)
.
On
(
"ListPodStats"
)
.
Return
(
podStats
,
nil
)
.
On
(
"ImageFsStats"
)
.
Return
(
imageFsStats
,
nil
)
.
On
(
"ImageFsStats"
)
.
Return
(
imageFsStats
,
nil
)
.
On
(
"RootFsStats"
)
.
Return
(
rootFsStats
,
nil
)
.
On
(
"RootFsStats"
)
.
Return
(
rootFsStats
,
nil
)
.
On
(
"GetCgroupStats"
,
"/"
)
.
Return
(
cgroupStatsMap
[
"/"
]
.
cs
,
cgroupStatsMap
[
"/"
]
.
ns
,
nil
)
.
On
(
"GetCgroupStats"
,
"/"
,
true
)
.
Return
(
cgroupStatsMap
[
"/"
]
.
cs
,
cgroupStatsMap
[
"/"
]
.
ns
,
nil
)
.
On
(
"GetCgroupStats"
,
"/runtime"
)
.
Return
(
cgroupStatsMap
[
"/runtime"
]
.
cs
,
cgroupStatsMap
[
"/runtime"
]
.
ns
,
nil
)
.
On
(
"GetCgroupStats"
,
"/runtime"
,
false
)
.
Return
(
cgroupStatsMap
[
"/runtime"
]
.
cs
,
cgroupStatsMap
[
"/runtime"
]
.
ns
,
nil
)
.
On
(
"GetCgroupStats"
,
"/misc"
)
.
Return
(
cgroupStatsMap
[
"/misc"
]
.
cs
,
cgroupStatsMap
[
"/misc"
]
.
ns
,
nil
)
.
On
(
"GetCgroupStats"
,
"/misc"
,
false
)
.
Return
(
cgroupStatsMap
[
"/misc"
]
.
cs
,
cgroupStatsMap
[
"/misc"
]
.
ns
,
nil
)
.
On
(
"GetCgroupStats"
,
"/kubelet"
)
.
Return
(
cgroupStatsMap
[
"/kubelet"
]
.
cs
,
cgroupStatsMap
[
"/kubelet"
]
.
ns
,
nil
)
On
(
"GetCgroupStats"
,
"/kubelet"
,
false
)
.
Return
(
cgroupStatsMap
[
"/kubelet"
]
.
cs
,
cgroupStatsMap
[
"/kubelet"
]
.
ns
,
nil
)
provider
:=
NewSummaryProvider
(
mockStatsProvider
)
provider
:=
NewSummaryProvider
(
mockStatsProvider
)
summary
,
err
:=
provider
.
Get
()
summary
,
err
:=
provider
.
Get
(
true
)
assert
.
NoError
(
err
)
assert
.
NoError
(
err
)
assert
.
Equal
(
summary
.
Node
.
NodeName
,
"test-node"
)
assert
.
Equal
(
summary
.
Node
.
NodeName
,
"test-node"
)
...
...
pkg/kubelet/server/stats/testing/mock_stats_provider.go
View file @
f6721480
...
@@ -33,13 +33,13 @@ type StatsProvider struct {
...
@@ -33,13 +33,13 @@ type StatsProvider struct {
mock
.
Mock
mock
.
Mock
}
}
// GetCgroupStats provides a mock function with given fields: cgroupName
// GetCgroupStats provides a mock function with given fields: cgroupName
, updateStats
func
(
_m
*
StatsProvider
)
GetCgroupStats
(
cgroupName
string
)
(
*
v1alpha1
.
ContainerStats
,
*
v1alpha1
.
NetworkStats
,
error
)
{
func
(
_m
*
StatsProvider
)
GetCgroupStats
(
cgroupName
string
,
updateStats
bool
)
(
*
v1alpha1
.
ContainerStats
,
*
v1alpha1
.
NetworkStats
,
error
)
{
ret
:=
_m
.
Called
(
cgroupName
)
ret
:=
_m
.
Called
(
cgroupName
,
updateStats
)
var
r0
*
v1alpha1
.
ContainerStats
var
r0
*
v1alpha1
.
ContainerStats
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
string
)
*
v1alpha1
.
ContainerStats
);
ok
{
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
string
,
bool
)
*
v1alpha1
.
ContainerStats
);
ok
{
r0
=
rf
(
cgroupName
)
r0
=
rf
(
cgroupName
,
updateStats
)
}
else
{
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
v1alpha1
.
ContainerStats
)
r0
=
ret
.
Get
(
0
)
.
(
*
v1alpha1
.
ContainerStats
)
...
@@ -47,8 +47,8 @@ func (_m *StatsProvider) GetCgroupStats(cgroupName string) (*v1alpha1.ContainerS
...
@@ -47,8 +47,8 @@ func (_m *StatsProvider) GetCgroupStats(cgroupName string) (*v1alpha1.ContainerS
}
}
var
r1
*
v1alpha1
.
NetworkStats
var
r1
*
v1alpha1
.
NetworkStats
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
string
)
*
v1alpha1
.
NetworkStats
);
ok
{
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
string
,
bool
)
*
v1alpha1
.
NetworkStats
);
ok
{
r1
=
rf
(
cgroupName
)
r1
=
rf
(
cgroupName
,
updateStats
)
}
else
{
}
else
{
if
ret
.
Get
(
1
)
!=
nil
{
if
ret
.
Get
(
1
)
!=
nil
{
r1
=
ret
.
Get
(
1
)
.
(
*
v1alpha1
.
NetworkStats
)
r1
=
ret
.
Get
(
1
)
.
(
*
v1alpha1
.
NetworkStats
)
...
@@ -56,8 +56,8 @@ func (_m *StatsProvider) GetCgroupStats(cgroupName string) (*v1alpha1.ContainerS
...
@@ -56,8 +56,8 @@ func (_m *StatsProvider) GetCgroupStats(cgroupName string) (*v1alpha1.ContainerS
}
}
var
r2
error
var
r2
error
if
rf
,
ok
:=
ret
.
Get
(
2
)
.
(
func
(
string
)
error
);
ok
{
if
rf
,
ok
:=
ret
.
Get
(
2
)
.
(
func
(
string
,
bool
)
error
);
ok
{
r2
=
rf
(
cgroupName
)
r2
=
rf
(
cgroupName
,
updateStats
)
}
else
{
}
else
{
r2
=
ret
.
Error
(
2
)
r2
=
ret
.
Error
(
2
)
}
}
...
...
pkg/kubelet/stats/helper.go
View file @
f6721480
...
@@ -238,11 +238,17 @@ func isMemoryUnlimited(v uint64) bool {
...
@@ -238,11 +238,17 @@ func isMemoryUnlimited(v uint64) bool {
// getCgroupInfo returns the information of the container with the specified
// getCgroupInfo returns the information of the container with the specified
// containerName from cadvisor.
// containerName from cadvisor.
func
getCgroupInfo
(
cadvisor
cadvisor
.
Interface
,
containerName
string
)
(
*
cadvisorapiv2
.
ContainerInfo
,
error
)
{
func
getCgroupInfo
(
cadvisor
cadvisor
.
Interface
,
containerName
string
,
updateStats
bool
)
(
*
cadvisorapiv2
.
ContainerInfo
,
error
)
{
var
maxAge
*
time
.
Duration
if
updateStats
{
age
:=
0
*
time
.
Second
maxAge
=
&
age
}
infoMap
,
err
:=
cadvisor
.
ContainerInfoV2
(
containerName
,
cadvisorapiv2
.
RequestOptions
{
infoMap
,
err
:=
cadvisor
.
ContainerInfoV2
(
containerName
,
cadvisorapiv2
.
RequestOptions
{
IdType
:
cadvisorapiv2
.
TypeName
,
IdType
:
cadvisorapiv2
.
TypeName
,
Count
:
2
,
// 2 samples are needed to compute "instantaneous" CPU
Count
:
2
,
// 2 samples are needed to compute "instantaneous" CPU
Recursive
:
false
,
Recursive
:
false
,
MaxAge
:
maxAge
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to get container info for %q: %v"
,
containerName
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to get container info for %q: %v"
,
containerName
,
err
)
...
@@ -256,8 +262,8 @@ func getCgroupInfo(cadvisor cadvisor.Interface, containerName string) (*cadvisor
...
@@ -256,8 +262,8 @@ func getCgroupInfo(cadvisor cadvisor.Interface, containerName string) (*cadvisor
// getCgroupStats returns the latest stats of the container having the
// getCgroupStats returns the latest stats of the container having the
// specified containerName from cadvisor.
// specified containerName from cadvisor.
func
getCgroupStats
(
cadvisor
cadvisor
.
Interface
,
containerName
string
)
(
*
cadvisorapiv2
.
ContainerStats
,
error
)
{
func
getCgroupStats
(
cadvisor
cadvisor
.
Interface
,
containerName
string
,
updateStats
bool
)
(
*
cadvisorapiv2
.
ContainerStats
,
error
)
{
info
,
err
:=
getCgroupInfo
(
cadvisor
,
containerName
)
info
,
err
:=
getCgroupInfo
(
cadvisor
,
containerName
,
updateStats
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/kubelet/stats/stats_provider.go
View file @
f6721480
...
@@ -88,8 +88,8 @@ type containerStatsProvider interface {
...
@@ -88,8 +88,8 @@ type containerStatsProvider interface {
// 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
)
(
*
statsapi
.
ContainerStats
,
*
statsapi
.
NetworkStats
,
error
)
{
func
(
p
*
StatsProvider
)
GetCgroupStats
(
cgroupName
string
,
updateStats
bool
)
(
*
statsapi
.
ContainerStats
,
*
statsapi
.
NetworkStats
,
error
)
{
info
,
err
:=
getCgroupInfo
(
p
.
cadvisor
,
cgroupName
)
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
)
}
}
...
@@ -113,8 +113,8 @@ func (p *StatsProvider) RootFsStats() (*statsapi.FsStats, error) {
...
@@ -113,8 +113,8 @@ func (p *StatsProvider) RootFsStats() (*statsapi.FsStats, error) {
}
}
// Get the root container stats's timestamp, which will be used as the
// Get the root container stats's timestamp, which will be used as the
// imageFs stats timestamp.
// imageFs stats timestamp.
Dont force a stats update, as we only want the timestamp.
rootStats
,
err
:=
getCgroupStats
(
p
.
cadvisor
,
"/"
)
rootStats
,
err
:=
getCgroupStats
(
p
.
cadvisor
,
"/"
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"failed to get root container stats: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"failed to get root container stats: %v"
,
err
)
}
}
...
...
pkg/kubelet/stats/stats_provider_test.go
View file @
f6721480
...
@@ -71,6 +71,7 @@ func TestGetCgroupStats(t *testing.T) {
...
@@ -71,6 +71,7 @@ func TestGetCgroupStats(t *testing.T) {
const
(
const
(
cgroupName
=
"test-cgroup-name"
cgroupName
=
"test-cgroup-name"
containerInfoSeed
=
1000
containerInfoSeed
=
1000
updateStats
=
false
)
)
var
(
var
(
mockCadvisor
=
new
(
cadvisortest
.
Mock
)
mockCadvisor
=
new
(
cadvisortest
.
Mock
)
...
@@ -87,7 +88,7 @@ func TestGetCgroupStats(t *testing.T) {
...
@@ -87,7 +88,7 @@ func TestGetCgroupStats(t *testing.T) {
mockCadvisor
.
On
(
"ContainerInfoV2"
,
cgroupName
,
options
)
.
Return
(
containerInfoMap
,
nil
)
mockCadvisor
.
On
(
"ContainerInfoV2"
,
cgroupName
,
options
)
.
Return
(
containerInfoMap
,
nil
)
provider
:=
newStatsProvider
(
mockCadvisor
,
mockPodManager
,
mockRuntimeCache
,
fakeContainerStatsProvider
{})
provider
:=
newStatsProvider
(
mockCadvisor
,
mockPodManager
,
mockRuntimeCache
,
fakeContainerStatsProvider
{})
cs
,
ns
,
err
:=
provider
.
GetCgroupStats
(
cgroupName
)
cs
,
ns
,
err
:=
provider
.
GetCgroupStats
(
cgroupName
,
updateStats
)
assert
.
NoError
(
err
)
assert
.
NoError
(
err
)
checkCPUStats
(
t
,
""
,
containerInfoSeed
,
cs
.
CPU
)
checkCPUStats
(
t
,
""
,
containerInfoSeed
,
cs
.
CPU
)
...
@@ -599,8 +600,8 @@ type fakeResourceAnalyzer struct {
...
@@ -599,8 +600,8 @@ type fakeResourceAnalyzer struct {
podVolumeStats
serverstats
.
PodVolumeStats
podVolumeStats
serverstats
.
PodVolumeStats
}
}
func
(
o
*
fakeResourceAnalyzer
)
Start
()
{}
func
(
o
*
fakeResourceAnalyzer
)
Start
()
{}
func
(
o
*
fakeResourceAnalyzer
)
Get
()
(
*
statsapi
.
Summary
,
error
)
{
return
nil
,
nil
}
func
(
o
*
fakeResourceAnalyzer
)
Get
(
bool
)
(
*
statsapi
.
Summary
,
error
)
{
return
nil
,
nil
}
func
(
o
*
fakeResourceAnalyzer
)
GetPodVolumeStats
(
uid
types
.
UID
)
(
serverstats
.
PodVolumeStats
,
bool
)
{
func
(
o
*
fakeResourceAnalyzer
)
GetPodVolumeStats
(
uid
types
.
UID
)
(
serverstats
.
PodVolumeStats
,
bool
)
{
return
o
.
podVolumeStats
,
true
return
o
.
podVolumeStats
,
true
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment