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
1fcad1b4
Commit
1fcad1b4
authored
May 31, 2019
by
Ben Moss
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix memory leak from not closing hcs container handles
parent
8b7e777f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
9 deletions
+24
-9
cri_stats_provider_windows.go
pkg/kubelet/stats/cri_stats_provider_windows.go
+24
-9
No files found.
pkg/kubelet/stats/cri_stats_provider_windows.go
View file @
1fcad1b4
...
@@ -19,6 +19,7 @@ limitations under the License.
...
@@ -19,6 +19,7 @@ limitations under the License.
package
stats
package
stats
import
(
import
(
"fmt"
"time"
"time"
"github.com/Microsoft/hcsshim"
"github.com/Microsoft/hcsshim"
...
@@ -40,18 +41,11 @@ func (p *criStatsProvider) listContainerNetworkStats() (map[string]*statsapi.Net
...
@@ -40,18 +41,11 @@ func (p *criStatsProvider) listContainerNetworkStats() (map[string]*statsapi.Net
stats
:=
make
(
map
[
string
]
*
statsapi
.
NetworkStats
)
stats
:=
make
(
map
[
string
]
*
statsapi
.
NetworkStats
)
for
_
,
c
:=
range
containers
{
for
_
,
c
:=
range
containers
{
c
ontainer
,
err
:=
hcsshim
.
OpenContainer
(
c
.
ID
)
c
stats
,
err
:=
fetchContainerStats
(
c
)
if
err
!=
nil
{
if
err
!=
nil
{
klog
.
V
(
4
)
.
Infof
(
"Failed to
open
container %q with error '%v', continue to get stats for other containers"
,
c
.
ID
,
err
)
klog
.
V
(
4
)
.
Infof
(
"Failed to
fetch statistics for
container %q with error '%v', continue to get stats for other containers"
,
c
.
ID
,
err
)
continue
continue
}
}
cstats
,
err
:=
container
.
Statistics
()
if
err
!=
nil
{
klog
.
V
(
4
)
.
Infof
(
"Failed to get statistics for container %q with error '%v', continue to get stats for other containers"
,
c
.
ID
,
err
)
continue
}
if
len
(
cstats
.
Network
)
>
0
{
if
len
(
cstats
.
Network
)
>
0
{
stats
[
c
.
ID
]
=
hcsStatsToNetworkStats
(
cstats
.
Timestamp
,
cstats
.
Network
)
stats
[
c
.
ID
]
=
hcsStatsToNetworkStats
(
cstats
.
Timestamp
,
cstats
.
Network
)
}
}
...
@@ -60,6 +54,27 @@ func (p *criStatsProvider) listContainerNetworkStats() (map[string]*statsapi.Net
...
@@ -60,6 +54,27 @@ func (p *criStatsProvider) listContainerNetworkStats() (map[string]*statsapi.Net
return
stats
,
nil
return
stats
,
nil
}
}
func
fetchContainerStats
(
c
hcsshim
.
ContainerProperties
)
(
stats
hcsshim
.
Statistics
,
err
error
)
{
var
(
container
hcsshim
.
Container
)
container
,
err
=
hcsshim
.
OpenContainer
(
c
.
ID
)
if
err
!=
nil
{
return
}
defer
func
()
{
if
closeErr
:=
container
.
Close
();
closeErr
!=
nil
{
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"failed to close container after error %v; close error: %v"
,
err
,
closeErr
)
}
else
{
err
=
closeErr
}
}
}()
return
container
.
Statistics
()
}
// hcsStatsToNetworkStats converts hcsshim.Statistics.Network to statsapi.NetworkStats
// hcsStatsToNetworkStats converts hcsshim.Statistics.Network to statsapi.NetworkStats
func
hcsStatsToNetworkStats
(
timestamp
time
.
Time
,
hcsStats
[]
hcsshim
.
NetworkStats
)
*
statsapi
.
NetworkStats
{
func
hcsStatsToNetworkStats
(
timestamp
time
.
Time
,
hcsStats
[]
hcsshim
.
NetworkStats
)
*
statsapi
.
NetworkStats
{
result
:=
&
statsapi
.
NetworkStats
{
result
:=
&
statsapi
.
NetworkStats
{
...
...
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