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
68dadcfd
Commit
68dadcfd
authored
Jan 30, 2018
by
Lantao Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make eviction manager work with CRI container runtime.
Signed-off-by:
Lantao Liu
<
lantaol@google.com
>
parent
03b3d599
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
82 additions
and
34 deletions
+82
-34
cadvisor_linux.go
pkg/kubelet/cadvisor/cadvisor_linux.go
+0
-13
cadvisor_unsupported.go
pkg/kubelet/cadvisor/cadvisor_unsupported.go
+0
-4
cadvisor_windows.go
pkg/kubelet/cadvisor/cadvisor_windows.go
+0
-4
cadvisor_fake.go
pkg/kubelet/cadvisor/testing/cadvisor_fake.go
+0
-4
cadvisor_mock.go
pkg/kubelet/cadvisor/testing/cadvisor_mock.go
+0
-5
types.go
pkg/kubelet/cadvisor/types.go
+0
-3
kubelet.go
pkg/kubelet/kubelet.go
+1
-1
cadvisor_stats_provider.go
pkg/kubelet/stats/cadvisor_stats_provider.go
+10
-0
cri_stats_provider.go
pkg/kubelet/stats/cri_stats_provider.go
+17
-0
stats_provider.go
pkg/kubelet/stats/stats_provider.go
+14
-0
stats_provider_test.go
pkg/kubelet/stats/stats_provider_test.go
+40
-0
No files found.
pkg/kubelet/cadvisor/cadvisor_linux.go
View file @
68dadcfd
...
@@ -242,16 +242,3 @@ func (cc *cadvisorClient) getFsInfo(label string) (cadvisorapiv2.FsInfo, error)
...
@@ -242,16 +242,3 @@ func (cc *cadvisorClient) getFsInfo(label string) (cadvisorapiv2.FsInfo, error)
func
(
cc
*
cadvisorClient
)
WatchEvents
(
request
*
events
.
Request
)
(
*
events
.
EventChannel
,
error
)
{
func
(
cc
*
cadvisorClient
)
WatchEvents
(
request
*
events
.
Request
)
(
*
events
.
EventChannel
,
error
)
{
return
cc
.
WatchForEvents
(
request
)
return
cc
.
WatchForEvents
(
request
)
}
}
// HasDedicatedImageFs returns true if the imagefs has a dedicated device.
func
(
cc
*
cadvisorClient
)
HasDedicatedImageFs
()
(
bool
,
error
)
{
imageFsInfo
,
err
:=
cc
.
ImagesFsInfo
()
if
err
!=
nil
{
return
false
,
err
}
rootFsInfo
,
err
:=
cc
.
RootFsInfo
()
if
err
!=
nil
{
return
false
,
err
}
return
imageFsInfo
.
Device
!=
rootFsInfo
.
Device
,
nil
}
pkg/kubelet/cadvisor/cadvisor_unsupported.go
View file @
68dadcfd
...
@@ -77,10 +77,6 @@ func (cu *cadvisorUnsupported) WatchEvents(request *events.Request) (*events.Eve
...
@@ -77,10 +77,6 @@ func (cu *cadvisorUnsupported) WatchEvents(request *events.Request) (*events.Eve
return
nil
,
unsupportedErr
return
nil
,
unsupportedErr
}
}
func
(
cu
*
cadvisorUnsupported
)
HasDedicatedImageFs
()
(
bool
,
error
)
{
return
false
,
unsupportedErr
}
func
(
c
*
cadvisorUnsupported
)
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
func
(
c
*
cadvisorUnsupported
)
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
return
cadvisorapiv2
.
FsInfo
{},
nil
return
cadvisorapiv2
.
FsInfo
{},
nil
}
}
pkg/kubelet/cadvisor/cadvisor_windows.go
View file @
68dadcfd
...
@@ -77,10 +77,6 @@ func (cu *cadvisorClient) WatchEvents(request *events.Request) (*events.EventCha
...
@@ -77,10 +77,6 @@ func (cu *cadvisorClient) WatchEvents(request *events.Request) (*events.EventCha
return
&
events
.
EventChannel
{},
nil
return
&
events
.
EventChannel
{},
nil
}
}
func
(
cu
*
cadvisorClient
)
HasDedicatedImageFs
()
(
bool
,
error
)
{
return
false
,
nil
}
func
(
c
*
cadvisorClient
)
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
func
(
c
*
cadvisorClient
)
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
return
cadvisorapiv2
.
FsInfo
{},
nil
return
cadvisorapiv2
.
FsInfo
{},
nil
}
}
pkg/kubelet/cadvisor/testing/cadvisor_fake.go
View file @
68dadcfd
...
@@ -76,10 +76,6 @@ func (c *Fake) WatchEvents(request *events.Request) (*events.EventChannel, error
...
@@ -76,10 +76,6 @@ func (c *Fake) WatchEvents(request *events.Request) (*events.EventChannel, error
return
new
(
events
.
EventChannel
),
nil
return
new
(
events
.
EventChannel
),
nil
}
}
func
(
c
*
Fake
)
HasDedicatedImageFs
()
(
bool
,
error
)
{
return
false
,
nil
}
func
(
c
*
Fake
)
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
func
(
c
*
Fake
)
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
return
cadvisorapiv2
.
FsInfo
{},
nil
return
cadvisorapiv2
.
FsInfo
{},
nil
}
}
pkg/kubelet/cadvisor/testing/cadvisor_mock.go
View file @
68dadcfd
...
@@ -84,11 +84,6 @@ func (c *Mock) WatchEvents(request *events.Request) (*events.EventChannel, error
...
@@ -84,11 +84,6 @@ func (c *Mock) WatchEvents(request *events.Request) (*events.EventChannel, error
return
args
.
Get
(
0
)
.
(
*
events
.
EventChannel
),
args
.
Error
(
1
)
return
args
.
Get
(
0
)
.
(
*
events
.
EventChannel
),
args
.
Error
(
1
)
}
}
func
(
c
*
Mock
)
HasDedicatedImageFs
()
(
bool
,
error
)
{
args
:=
c
.
Called
()
return
args
.
Get
(
0
)
.
(
bool
),
args
.
Error
(
1
)
}
func
(
c
*
Mock
)
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
func
(
c
*
Mock
)
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
args
:=
c
.
Called
(
uuid
)
args
:=
c
.
Called
(
uuid
)
return
args
.
Get
(
0
)
.
(
cadvisorapiv2
.
FsInfo
),
args
.
Error
(
1
)
return
args
.
Get
(
0
)
.
(
cadvisorapiv2
.
FsInfo
),
args
.
Error
(
1
)
...
...
pkg/kubelet/cadvisor/types.go
View file @
68dadcfd
...
@@ -42,9 +42,6 @@ type Interface interface {
...
@@ -42,9 +42,6 @@ type Interface interface {
// Get events streamed through passedChannel that fit the request.
// Get events streamed through passedChannel that fit the request.
WatchEvents
(
request
*
events
.
Request
)
(
*
events
.
EventChannel
,
error
)
WatchEvents
(
request
*
events
.
Request
)
(
*
events
.
EventChannel
,
error
)
// HasDedicatedImageFs returns true iff a dedicated image filesystem exists for storing images.
HasDedicatedImageFs
()
(
bool
,
error
)
// GetFsInfoByFsUUID returns the stats of the filesystem with the specified
// GetFsInfoByFsUUID returns the stats of the filesystem with the specified
// uuid.
// uuid.
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
...
...
pkg/kubelet/kubelet.go
View file @
68dadcfd
...
@@ -1321,7 +1321,7 @@ func (kl *Kubelet) initializeRuntimeDependentModules() {
...
@@ -1321,7 +1321,7 @@ func (kl *Kubelet) initializeRuntimeDependentModules() {
glog
.
Fatalf
(
"Failed to start cAdvisor %v"
,
err
)
glog
.
Fatalf
(
"Failed to start cAdvisor %v"
,
err
)
}
}
// eviction manager must start after cadvisor because it needs to know if the container runtime has a dedicated imagefs
// eviction manager must start after cadvisor because it needs to know if the container runtime has a dedicated imagefs
kl
.
evictionManager
.
Start
(
kl
.
cadviso
r
,
kl
.
GetActivePods
,
kl
.
podResourcesAreReclaimed
,
kl
.
containerManager
,
evictionMonitoringPeriod
)
kl
.
evictionManager
.
Start
(
kl
.
StatsProvide
r
,
kl
.
GetActivePods
,
kl
.
podResourcesAreReclaimed
,
kl
.
containerManager
,
evictionMonitoringPeriod
)
}
}
// Run starts the kubelet reacting to config updates
// Run starts the kubelet reacting to config updates
...
...
pkg/kubelet/stats/cadvisor_stats_provider.go
View file @
68dadcfd
...
@@ -220,6 +220,16 @@ func (p *cadvisorStatsProvider) ImageFsStats() (*statsapi.FsStats, error) {
...
@@ -220,6 +220,16 @@ func (p *cadvisorStatsProvider) ImageFsStats() (*statsapi.FsStats, error) {
},
nil
},
nil
}
}
// ImageFsDevice returns name of the device where the image filesystem locates,
// e.g. /dev/sda1.
func
(
p
*
cadvisorStatsProvider
)
ImageFsDevice
()
(
string
,
error
)
{
imageFsInfo
,
err
:=
p
.
cadvisor
.
ImagesFsInfo
()
if
err
!=
nil
{
return
""
,
err
}
return
imageFsInfo
.
Device
,
nil
}
// buildPodRef returns a PodReference that identifies the Pod managing cinfo
// buildPodRef returns a PodReference that identifies the Pod managing cinfo
func
buildPodRef
(
containerLabels
map
[
string
]
string
)
statsapi
.
PodReference
{
func
buildPodRef
(
containerLabels
map
[
string
]
string
)
statsapi
.
PodReference
{
podName
:=
kubetypes
.
GetPodName
(
containerLabels
)
podName
:=
kubetypes
.
GetPodName
(
containerLabels
)
...
...
pkg/kubelet/stats/cri_stats_provider.go
View file @
68dadcfd
...
@@ -17,6 +17,7 @@ limitations under the License.
...
@@ -17,6 +17,7 @@ limitations under the License.
package
stats
package
stats
import
(
import
(
"errors"
"fmt"
"fmt"
"path"
"path"
"sort"
"sort"
...
@@ -202,6 +203,22 @@ func (p *criStatsProvider) ImageFsStats() (*statsapi.FsStats, error) {
...
@@ -202,6 +203,22 @@ func (p *criStatsProvider) ImageFsStats() (*statsapi.FsStats, error) {
return
nil
,
fmt
.
Errorf
(
"imageFs information is unavailable"
)
return
nil
,
fmt
.
Errorf
(
"imageFs information is unavailable"
)
}
}
// ImageFsDevice returns name of the device where the image filesystem locates,
// e.g. /dev/sda1.
func
(
p
*
criStatsProvider
)
ImageFsDevice
()
(
string
,
error
)
{
resp
,
err
:=
p
.
imageService
.
ImageFsInfo
()
if
err
!=
nil
{
return
""
,
err
}
for
_
,
fs
:=
range
resp
{
fsInfo
:=
p
.
getFsInfo
(
fs
.
GetStorageId
())
if
fsInfo
!=
nil
{
return
fsInfo
.
Device
,
nil
}
}
return
""
,
errors
.
New
(
"imagefs device is not found"
)
}
// getFsInfo returns the information of the filesystem with the specified
// getFsInfo returns the information of the filesystem with the specified
// storageID. If any error occurs, this function logs the error and returns
// storageID. If any error occurs, this function logs the error and returns
// nil.
// nil.
...
...
pkg/kubelet/stats/stats_provider.go
View file @
68dadcfd
...
@@ -84,6 +84,7 @@ type StatsProvider struct {
...
@@ -84,6 +84,7 @@ type StatsProvider struct {
type
containerStatsProvider
interface
{
type
containerStatsProvider
interface
{
ListPodStats
()
([]
statsapi
.
PodStats
,
error
)
ListPodStats
()
([]
statsapi
.
PodStats
,
error
)
ImageFsStats
()
(
*
statsapi
.
FsStats
,
error
)
ImageFsStats
()
(
*
statsapi
.
FsStats
,
error
)
ImageFsDevice
()
(
string
,
error
)
}
}
// GetCgroupStats returns the stats of the cgroup with the cgroupName. Note that
// GetCgroupStats returns the stats of the cgroup with the cgroupName. Note that
...
@@ -167,3 +168,16 @@ func (p *StatsProvider) GetRawContainerInfo(containerName string, req *cadvisora
...
@@ -167,3 +168,16 @@ func (p *StatsProvider) GetRawContainerInfo(containerName string, req *cadvisora
containerInfo
.
Name
:
containerInfo
,
containerInfo
.
Name
:
containerInfo
,
},
nil
},
nil
}
}
// HasDedicatedImageFs returns true if a dedicated image filesystem exists for storing images.
func
(
p
*
StatsProvider
)
HasDedicatedImageFs
()
(
bool
,
error
)
{
device
,
err
:=
p
.
containerStatsProvider
.
ImageFsDevice
()
if
err
!=
nil
{
return
false
,
err
}
rootFsInfo
,
err
:=
p
.
cadvisor
.
RootFsInfo
()
if
err
!=
nil
{
return
false
,
err
}
return
device
!=
rootFsInfo
.
Device
,
nil
}
pkg/kubelet/stats/stats_provider_test.go
View file @
68dadcfd
...
@@ -362,6 +362,41 @@ func TestGetRawContainerInfoSubcontainers(t *testing.T) {
...
@@ -362,6 +362,41 @@ func TestGetRawContainerInfoSubcontainers(t *testing.T) {
mockCadvisor
.
AssertExpectations
(
t
)
mockCadvisor
.
AssertExpectations
(
t
)
}
}
func
TestHasDedicatedImageFs
(
t
*
testing
.
T
)
{
for
desc
,
test
:=
range
map
[
string
]
struct
{
rootfsDevice
string
imagefsDevice
string
dedicated
bool
}{
"dedicated device for image filesystem"
:
{
rootfsDevice
:
"root/device"
,
imagefsDevice
:
"image/device"
,
dedicated
:
true
,
},
"shared device for image filesystem"
:
{
rootfsDevice
:
"share/device"
,
imagefsDevice
:
"share/device"
,
dedicated
:
false
,
},
}
{
t
.
Logf
(
"TestCase %q"
,
desc
)
var
(
mockCadvisor
=
new
(
cadvisortest
.
Mock
)
mockPodManager
=
new
(
kubepodtest
.
MockManager
)
mockRuntimeCache
=
new
(
kubecontainertest
.
MockRuntimeCache
)
)
mockCadvisor
.
On
(
"RootFsInfo"
)
.
Return
(
cadvisorapiv2
.
FsInfo
{
Device
:
test
.
rootfsDevice
},
nil
)
provider
:=
newStatsProvider
(
mockCadvisor
,
mockPodManager
,
mockRuntimeCache
,
fakeContainerStatsProvider
{
device
:
test
.
imagefsDevice
,
})
dedicated
,
err
:=
provider
.
HasDedicatedImageFs
()
assert
.
NoError
(
t
,
err
)
assert
.
Equal
(
t
,
test
.
dedicated
,
dedicated
)
mockCadvisor
.
AssertExpectations
(
t
)
}
}
func
getTerminatedContainerInfo
(
seed
int
,
podName
string
,
podNamespace
string
,
containerName
string
)
cadvisorapiv2
.
ContainerInfo
{
func
getTerminatedContainerInfo
(
seed
int
,
podName
string
,
podNamespace
string
,
containerName
string
)
cadvisorapiv2
.
ContainerInfo
{
cinfo
:=
getTestContainerInfo
(
seed
,
podName
,
podNamespace
,
containerName
)
cinfo
:=
getTestContainerInfo
(
seed
,
podName
,
podNamespace
,
containerName
)
cinfo
.
Stats
[
0
]
.
Memory
.
RSS
=
0
cinfo
.
Stats
[
0
]
.
Memory
.
RSS
=
0
...
@@ -606,6 +641,7 @@ func (o *fakeResourceAnalyzer) GetPodVolumeStats(uid types.UID) (serverstats.Pod
...
@@ -606,6 +641,7 @@ func (o *fakeResourceAnalyzer) GetPodVolumeStats(uid types.UID) (serverstats.Pod
}
}
type
fakeContainerStatsProvider
struct
{
type
fakeContainerStatsProvider
struct
{
device
string
}
}
func
(
p
fakeContainerStatsProvider
)
ListPodStats
()
([]
statsapi
.
PodStats
,
error
)
{
func
(
p
fakeContainerStatsProvider
)
ListPodStats
()
([]
statsapi
.
PodStats
,
error
)
{
...
@@ -614,3 +650,7 @@ func (p fakeContainerStatsProvider) ListPodStats() ([]statsapi.PodStats, error)
...
@@ -614,3 +650,7 @@ func (p fakeContainerStatsProvider) ListPodStats() ([]statsapi.PodStats, error)
func
(
p
fakeContainerStatsProvider
)
ImageFsStats
()
(
*
statsapi
.
FsStats
,
error
)
{
func
(
p
fakeContainerStatsProvider
)
ImageFsStats
()
(
*
statsapi
.
FsStats
,
error
)
{
return
nil
,
fmt
.
Errorf
(
"not implemented"
)
return
nil
,
fmt
.
Errorf
(
"not implemented"
)
}
}
func
(
p
fakeContainerStatsProvider
)
ImageFsDevice
()
(
string
,
error
)
{
return
p
.
device
,
nil
}
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