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
a77450ec
Commit
a77450ec
authored
Feb 07, 2018
by
Lantao Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mountpoint as CRI image filesystem storage identifier.
parent
c37b5d75
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
57 additions
and
57 deletions
+57
-57
api.pb.go
pkg/kubelet/apis/cri/runtime/v1alpha2/api.pb.go
+0
-0
api.proto
pkg/kubelet/apis/cri/runtime/v1alpha2/api.proto
+6
-6
cadvisor_unsupported.go
pkg/kubelet/cadvisor/cadvisor_unsupported.go
+1
-1
cadvisor_windows.go
pkg/kubelet/cadvisor/cadvisor_windows.go
+1
-1
cadvisor_fake.go
pkg/kubelet/cadvisor/testing/cadvisor_fake.go
+1
-1
cadvisor_mock.go
pkg/kubelet/cadvisor/testing/cadvisor_mock.go
+2
-2
types.go
pkg/kubelet/cadvisor/types.go
+2
-3
cri_stats_provider.go
pkg/kubelet/stats/cri_stats_provider.go
+25
-24
cri_stats_provider_test.go
pkg/kubelet/stats/cri_stats_provider_test.go
+19
-19
No files found.
pkg/kubelet/apis/cri/runtime/v1alpha2/api.pb.go
View file @
a77450ec
This diff is collapsed.
Click to expand it.
pkg/kubelet/apis/cri/runtime/v1alpha2/api.proto
View file @
a77450ec
...
...
@@ -1103,18 +1103,18 @@ message UInt64Value {
uint64
value
=
1
;
}
//
StorageIdentifier uniquely identify the storage.
.
message
Storage
Identifier
{
//
UUID of the device
.
string
uuid
=
1
;
//
FilesystemIdentifier uniquely identify the filesystem
.
message
Filesystem
Identifier
{
//
Mountpoint of a filesystem
.
string
mountpoint
=
1
;
}
// FilesystemUsage provides the filesystem usage information.
message
FilesystemUsage
{
// Timestamp in nanoseconds at which the information were collected. Must be > 0.
int64
timestamp
=
1
;
// The un
derlying storage
of the filesystem.
StorageIdentifier
storage
_id
=
2
;
// The un
ique identifier
of the filesystem.
FilesystemIdentifier
fs
_id
=
2
;
// UsedBytes represents the bytes used for images on the filesystem.
// This may differ from the total bytes used on the filesystem and may not
// equal CapacityBytes - AvailableBytes.
...
...
pkg/kubelet/cadvisor/cadvisor_unsupported.go
View file @
a77450ec
...
...
@@ -77,6 +77,6 @@ func (cu *cadvisorUnsupported) WatchEvents(request *events.Request) (*events.Eve
return
nil
,
unsupportedErr
}
func
(
c
*
cadvisorUnsupported
)
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
func
(
c
u
*
cadvisorUnsupported
)
GetDirFsInfo
(
path
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
return
cadvisorapiv2
.
FsInfo
{},
nil
}
pkg/kubelet/cadvisor/cadvisor_windows.go
View file @
a77450ec
...
...
@@ -77,6 +77,6 @@ func (cu *cadvisorClient) WatchEvents(request *events.Request) (*events.EventCha
return
&
events
.
EventChannel
{},
nil
}
func
(
c
*
cadvisorClient
)
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
func
(
c
u
*
cadvisorClient
)
GetDirFsInfo
(
path
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
return
cadvisorapiv2
.
FsInfo
{},
nil
}
pkg/kubelet/cadvisor/testing/cadvisor_fake.go
View file @
a77450ec
...
...
@@ -76,6 +76,6 @@ func (c *Fake) WatchEvents(request *events.Request) (*events.EventChannel, error
return
new
(
events
.
EventChannel
),
nil
}
func
(
c
*
Fake
)
Get
FsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
func
(
c
*
Fake
)
Get
DirFsInfo
(
path
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
return
cadvisorapiv2
.
FsInfo
{},
nil
}
pkg/kubelet/cadvisor/testing/cadvisor_mock.go
View file @
a77450ec
...
...
@@ -84,7 +84,7 @@ func (c *Mock) WatchEvents(request *events.Request) (*events.EventChannel, error
return
args
.
Get
(
0
)
.
(
*
events
.
EventChannel
),
args
.
Error
(
1
)
}
func
(
c
*
Mock
)
Get
FsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
args
:=
c
.
Called
(
uuid
)
func
(
c
*
Mock
)
Get
DirFsInfo
(
path
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
{
args
:=
c
.
Called
(
path
)
return
args
.
Get
(
0
)
.
(
cadvisorapiv2
.
FsInfo
),
args
.
Error
(
1
)
}
pkg/kubelet/cadvisor/types.go
View file @
a77450ec
...
...
@@ -42,9 +42,8 @@ type Interface interface {
// Get events streamed through passedChannel that fit the request.
WatchEvents
(
request
*
events
.
Request
)
(
*
events
.
EventChannel
,
error
)
// GetFsInfoByFsUUID returns the stats of the filesystem with the specified
// uuid.
GetFsInfoByFsUUID
(
uuid
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
// Get filesystem information for the filesystem that contains the given file.
GetDirFsInfo
(
path
string
)
(
cadvisorapiv2
.
FsInfo
,
error
)
}
// ImageFsInfoProvider informs cAdvisor how to find imagefs for container images.
...
...
pkg/kubelet/stats/cri_stats_provider.go
View file @
a77450ec
...
...
@@ -95,10 +95,10 @@ func (p *criStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
podSandboxMap
[
s
.
Id
]
=
s
}
//
uuidToFsInfo is a map from filesystem UUID to its stats. This will be
//
used as a cache to avoid querying cAdvisor for the filesystem stats with
//
the same UUID
many times.
uuidToFsInfo
:=
make
(
map
[
runtimeapi
.
Storage
Identifier
]
*
cadvisorapiv2
.
FsInfo
)
//
fsIDtoInfo is a map from filesystem id to its stats. This will be used
//
as a cache to avoid querying cAdvisor for the filesystem stats with the
//
same filesystem id
many times.
fsIDtoInfo
:=
make
(
map
[
runtimeapi
.
Filesystem
Identifier
]
*
cadvisorapiv2
.
FsInfo
)
// sandboxIDToPodStats is a temporary map from sandbox ID to its pod stats.
sandboxIDToPodStats
:=
make
(
map
[
string
]
*
statsapi
.
PodStats
)
...
...
@@ -149,7 +149,7 @@ func (p *criStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
}
sandboxIDToPodStats
[
podSandboxID
]
=
ps
}
cs
:=
p
.
makeContainerStats
(
stats
,
container
,
&
rootFsInfo
,
uuidToFs
Info
)
cs
:=
p
.
makeContainerStats
(
stats
,
container
,
&
rootFsInfo
,
fsIDto
Info
)
// If cadvisor stats is available for the container, use it to populate
// container stats
caStats
,
caFound
:=
caInfos
[
containerID
]
...
...
@@ -186,11 +186,11 @@ func (p *criStatsProvider) ImageFsStats() (*statsapi.FsStats, error) {
UsedBytes
:
&
fs
.
UsedBytes
.
Value
,
InodesUsed
:
&
fs
.
InodesUsed
.
Value
,
}
imageFsInfo
:=
p
.
getFsInfo
(
fs
.
StorageId
)
imageFsInfo
:=
p
.
getFsInfo
(
fs
.
GetFsId
()
)
if
imageFsInfo
!=
nil
{
// The image filesystem
UUID is unknown to the local node or
//
there's an error on retrieving the stats. In these cases, w
e
//
omit those
stats and return the best-effort partial result. See
// The image filesystem
id is unknown to the local node or there's
//
an error on retrieving the stats. In these cases, we omit thos
e
// stats and return the best-effort partial result. See
// https://github.com/kubernetes/heapster/issues/1793.
s
.
AvailableBytes
=
&
imageFsInfo
.
Available
s
.
CapacityBytes
=
&
imageFsInfo
.
Capacity
...
...
@@ -211,7 +211,7 @@ func (p *criStatsProvider) ImageFsDevice() (string, error) {
return
""
,
err
}
for
_
,
fs
:=
range
resp
{
fsInfo
:=
p
.
getFsInfo
(
fs
.
Get
Storage
Id
())
fsInfo
:=
p
.
getFsInfo
(
fs
.
Get
Fs
Id
())
if
fsInfo
!=
nil
{
return
fsInfo
.
Device
,
nil
}
...
...
@@ -220,16 +220,17 @@ func (p *criStatsProvider) ImageFsDevice() (string, error) {
}
// getFsInfo returns the information of the filesystem with the specified
//
storage
ID. If any error occurs, this function logs the error and returns
//
fs
ID. If any error occurs, this function logs the error and returns
// nil.
func
(
p
*
criStatsProvider
)
getFsInfo
(
storageID
*
runtimeapi
.
Storage
Identifier
)
*
cadvisorapiv2
.
FsInfo
{
if
storage
ID
==
nil
{
glog
.
V
(
2
)
.
Infof
(
"Failed to get filesystem info:
storage
ID is nil."
)
func
(
p
*
criStatsProvider
)
getFsInfo
(
fsID
*
runtimeapi
.
Filesystem
Identifier
)
*
cadvisorapiv2
.
FsInfo
{
if
fs
ID
==
nil
{
glog
.
V
(
2
)
.
Infof
(
"Failed to get filesystem info:
fs
ID is nil."
)
return
nil
}
fsInfo
,
err
:=
p
.
cadvisor
.
GetFsInfoByFsUUID
(
storageID
.
Uuid
)
mountpoint
:=
fsID
.
GetMountpoint
()
fsInfo
,
err
:=
p
.
cadvisor
.
GetDirFsInfo
(
mountpoint
)
if
err
!=
nil
{
msg
:=
fmt
.
Sprintf
(
"Failed to get the info of the filesystem with
id %q: %v."
,
storageID
.
Uuid
,
err
)
msg
:=
fmt
.
Sprintf
(
"Failed to get the info of the filesystem with
mountpoint %q: %v."
,
mountpoint
,
err
)
if
err
==
cadvisorfs
.
ErrNoSuchDevice
{
glog
.
V
(
2
)
.
Info
(
msg
)
}
else
{
...
...
@@ -275,7 +276,7 @@ func (p *criStatsProvider) makeContainerStats(
stats
*
runtimeapi
.
ContainerStats
,
container
*
runtimeapi
.
Container
,
rootFsInfo
*
cadvisorapiv2
.
FsInfo
,
uuidToFsInfo
map
[
runtimeapi
.
Storage
Identifier
]
*
cadvisorapiv2
.
FsInfo
,
fsIDtoInfo
map
[
runtimeapi
.
Filesystem
Identifier
]
*
cadvisorapiv2
.
FsInfo
,
)
*
statsapi
.
ContainerStats
{
result
:=
&
statsapi
.
ContainerStats
{
Name
:
stats
.
Attributes
.
Metadata
.
Name
,
...
...
@@ -324,16 +325,16 @@ func (p *criStatsProvider) makeContainerStats(
result
.
Rootfs
.
InodesUsed
=
&
stats
.
WritableLayer
.
InodesUsed
.
Value
}
}
storageID
:=
stats
.
GetWritableLayer
()
.
GetStorage
Id
()
if
storage
ID
!=
nil
{
imageFsInfo
,
found
:=
uuidToFsInfo
[
*
storage
ID
]
fsID
:=
stats
.
GetWritableLayer
()
.
GetFs
Id
()
if
fs
ID
!=
nil
{
imageFsInfo
,
found
:=
fsIDtoInfo
[
*
fs
ID
]
if
!
found
{
imageFsInfo
=
p
.
getFsInfo
(
storage
ID
)
uuidToFsInfo
[
*
storage
ID
]
=
imageFsInfo
imageFsInfo
=
p
.
getFsInfo
(
fs
ID
)
fsIDtoInfo
[
*
fs
ID
]
=
imageFsInfo
}
if
imageFsInfo
!=
nil
{
// The image filesystem
UUID is unknown to the local node or there's an
// error on retrieving the stats. In these cases, we omit those stats
// The image filesystem
id is unknown to the local node or there's
//
an
error on retrieving the stats. In these cases, we omit those stats
// and return the best-effort partial result. See
// https://github.com/kubernetes/heapster/issues/1793.
result
.
Rootfs
.
AvailableBytes
=
&
imageFsInfo
.
Available
...
...
pkg/kubelet/stats/cri_stats_provider_test.go
View file @
a77450ec
...
...
@@ -63,26 +63,26 @@ func TestCRIListPodStats(t *testing.T) {
)
var
(
imageFs
StorageUUID
=
"imagefs-storage-uuid
"
unknown
StorageUUID
=
"unknown-storage-uuid
"
imageFsInfo
=
getTestFsInfo
(
2000
)
rootFsInfo
=
getTestFsInfo
(
1000
)
imageFs
Mountpoint
=
"/test/mount/point
"
unknown
Mountpoint
=
"/unknown/mount/point
"
imageFsInfo
=
getTestFsInfo
(
2000
)
rootFsInfo
=
getTestFsInfo
(
1000
)
sandbox0
=
makeFakePodSandbox
(
"sandbox0-name"
,
"sandbox0-uid"
,
"sandbox0-ns"
)
container0
=
makeFakeContainer
(
sandbox0
,
cName0
,
0
,
false
)
containerStats0
=
makeFakeContainerStats
(
container0
,
imageFs
StorageUUID
)
containerStats0
=
makeFakeContainerStats
(
container0
,
imageFs
Mountpoint
)
container1
=
makeFakeContainer
(
sandbox0
,
cName1
,
0
,
false
)
containerStats1
=
makeFakeContainerStats
(
container1
,
unknown
StorageUUID
)
containerStats1
=
makeFakeContainerStats
(
container1
,
unknown
Mountpoint
)
sandbox1
=
makeFakePodSandbox
(
"sandbox1-name"
,
"sandbox1-uid"
,
"sandbox1-ns"
)
container2
=
makeFakeContainer
(
sandbox1
,
cName2
,
0
,
false
)
containerStats2
=
makeFakeContainerStats
(
container2
,
imageFs
StorageUUID
)
containerStats2
=
makeFakeContainerStats
(
container2
,
imageFs
Mountpoint
)
sandbox2
=
makeFakePodSandbox
(
"sandbox2-name"
,
"sandbox2-uid"
,
"sandbox2-ns"
)
container3
=
makeFakeContainer
(
sandbox2
,
cName3
,
0
,
true
)
containerStats3
=
makeFakeContainerStats
(
container3
,
imageFs
StorageUUID
)
containerStats3
=
makeFakeContainerStats
(
container3
,
imageFs
Mountpoint
)
container4
=
makeFakeContainer
(
sandbox2
,
cName3
,
1
,
false
)
containerStats4
=
makeFakeContainerStats
(
container4
,
imageFs
StorageUUID
)
containerStats4
=
makeFakeContainerStats
(
container4
,
imageFs
Mountpoint
)
)
var
(
...
...
@@ -116,8 +116,8 @@ func TestCRIListPodStats(t *testing.T) {
mockCadvisor
.
On
(
"ContainerInfoV2"
,
"/"
,
options
)
.
Return
(
infos
,
nil
)
.
On
(
"RootFsInfo"
)
.
Return
(
rootFsInfo
,
nil
)
.
On
(
"Get
FsInfoByFsUUID"
,
imageFsStorageUUID
)
.
Return
(
imageFsInfo
,
nil
)
.
On
(
"Get
FsInfoByFsUUID"
,
unknownStorageUUID
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
cadvisorfs
.
ErrNoSuchDevice
)
On
(
"Get
DirFsInfo"
,
imageFsMountpoint
)
.
Return
(
imageFsInfo
,
nil
)
.
On
(
"Get
DirFsInfo"
,
unknownMountpoint
)
.
Return
(
cadvisorapiv2
.
FsInfo
{},
cadvisorfs
.
ErrNoSuchDevice
)
fakeRuntimeService
.
SetFakeSandboxes
([]
*
critest
.
FakePodSandbox
{
sandbox0
,
sandbox1
,
sandbox2
,
})
...
...
@@ -209,9 +209,9 @@ func TestCRIListPodStats(t *testing.T) {
func
TestCRIImagesFsStats
(
t
*
testing
.
T
)
{
var
(
imageFs
StorageUUID
=
"imagefs-storage-uuid
"
imageFsInfo
=
getTestFsInfo
(
2000
)
imageFsUsage
=
makeFakeImageFsUsage
(
imageFsStorageUUID
)
imageFs
Mountpoint
=
"/test/mount/point
"
imageFsInfo
=
getTestFsInfo
(
2000
)
imageFsUsage
=
makeFakeImageFsUsage
(
imageFsMountpoint
)
)
var
(
mockCadvisor
=
new
(
cadvisortest
.
Mock
)
...
...
@@ -222,7 +222,7 @@ func TestCRIImagesFsStats(t *testing.T) {
fakeImageService
=
critest
.
NewFakeImageService
()
)
mockCadvisor
.
On
(
"Get
FsInfoByFsUUID"
,
imageFsStorageUUID
)
.
Return
(
imageFsInfo
,
nil
)
mockCadvisor
.
On
(
"Get
DirFsInfo"
,
imageFsMountpoint
)
.
Return
(
imageFsInfo
,
nil
)
fakeImageService
.
SetFakeFilesystemUsage
([]
*
runtimeapi
.
FilesystemUsage
{
imageFsUsage
,
})
...
...
@@ -292,7 +292,7 @@ func makeFakeContainer(sandbox *critest.FakePodSandbox, name string, attempt uin
return
c
}
func
makeFakeContainerStats
(
container
*
critest
.
FakeContainer
,
imageFs
UUID
string
)
*
runtimeapi
.
ContainerStats
{
func
makeFakeContainerStats
(
container
*
critest
.
FakeContainer
,
imageFs
Mountpoint
string
)
*
runtimeapi
.
ContainerStats
{
containerStats
:=
&
runtimeapi
.
ContainerStats
{
Attributes
:
&
runtimeapi
.
ContainerAttributes
{
Id
:
container
.
ContainerStatus
.
Id
,
...
...
@@ -300,7 +300,7 @@ func makeFakeContainerStats(container *critest.FakeContainer, imageFsUUID string
},
WritableLayer
:
&
runtimeapi
.
FilesystemUsage
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
StorageId
:
&
runtimeapi
.
StorageIdentifier
{
Uuid
:
imageFsUUID
},
FsId
:
&
runtimeapi
.
FilesystemIdentifier
{
Mountpoint
:
imageFsMountpoint
},
UsedBytes
:
&
runtimeapi
.
UInt64Value
{
Value
:
rand
.
Uint64
()
/
100
},
InodesUsed
:
&
runtimeapi
.
UInt64Value
{
Value
:
rand
.
Uint64
()
/
100
},
},
...
...
@@ -321,10 +321,10 @@ func makeFakeContainerStats(container *critest.FakeContainer, imageFsUUID string
return
containerStats
}
func
makeFakeImageFsUsage
(
fs
UUID
string
)
*
runtimeapi
.
FilesystemUsage
{
func
makeFakeImageFsUsage
(
fs
Mountpoint
string
)
*
runtimeapi
.
FilesystemUsage
{
return
&
runtimeapi
.
FilesystemUsage
{
Timestamp
:
time
.
Now
()
.
UnixNano
(),
StorageId
:
&
runtimeapi
.
StorageIdentifier
{
Uuid
:
fsUUID
},
FsId
:
&
runtimeapi
.
FilesystemIdentifier
{
Mountpoint
:
fsMountpoint
},
UsedBytes
:
&
runtimeapi
.
UInt64Value
{
Value
:
rand
.
Uint64
()},
InodesUsed
:
&
runtimeapi
.
UInt64Value
{
Value
:
rand
.
Uint64
()},
}
...
...
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