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
bc091be6
Commit
bc091be6
authored
Nov 30, 2018
by
Robert Krawitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 71614: Protect log message maps
parent
3156df3e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
kuberuntime_manager.go
pkg/kubelet/kuberuntime/kuberuntime_manager.go
+6
-0
remote_runtime.go
pkg/kubelet/remote/remote_runtime.go
+12
-0
No files found.
pkg/kubelet/kuberuntime/kuberuntime_manager.go
View file @
bc091be6
...
...
@@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"os"
"sync"
"time"
cadvisorapi
"github.com/google/cadvisor/info/v1"
...
...
@@ -131,6 +132,7 @@ type kubeGenericRuntimeManager struct {
// Time last per-container error message was printed
errorPrinted
map
[
string
]
time
.
Time
errorMapLock
sync
.
Mutex
}
// KubeGenericRuntime is a interface contains interfaces for container runtime and command.
...
...
@@ -830,6 +832,8 @@ func (m *kubeGenericRuntimeManager) killPodWithSyncResult(pod *v1.Pod, runningPo
}
func
(
m
*
kubeGenericRuntimeManager
)
cleanupErrorTimeouts
()
{
m
.
errorMapLock
.
Lock
()
defer
m
.
errorMapLock
.
Unlock
()
for
name
,
timeout
:=
range
m
.
errorPrinted
{
if
time
.
Now
()
.
Sub
(
timeout
)
>=
identicalErrorDelay
{
delete
(
m
.
errorPrinted
,
name
)
...
...
@@ -886,6 +890,8 @@ func (m *kubeGenericRuntimeManager) GetPodStatus(uid kubetypes.UID, name, namesp
// Get statuses of all containers visible in the pod.
containerStatuses
,
err
:=
m
.
getPodContainerStatuses
(
uid
,
name
,
namespace
)
m
.
errorMapLock
.
Lock
()
defer
m
.
errorMapLock
.
Unlock
()
if
err
!=
nil
{
lastMsg
,
ok
:=
m
.
lastError
[
podFullName
]
if
!
ok
||
err
.
Error
()
!=
lastMsg
||
time
.
Now
()
.
Sub
(
m
.
errorPrinted
[
podFullName
])
>=
identicalErrorDelay
{
...
...
pkg/kubelet/remote/remote_runtime.go
View file @
bc091be6
...
...
@@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"strings"
"sync"
"time"
"google.golang.org/grpc"
...
...
@@ -40,6 +41,7 @@ type RemoteRuntimeService struct {
lastError
map
[
string
]
string
// Time last per-container error message was printed
errorPrinted
map
[
string
]
time
.
Time
errorMapLock
sync
.
Mutex
}
const
(
...
...
@@ -236,8 +238,10 @@ func (r *RemoteRuntimeService) StopContainer(containerID string, timeout int64)
ctx
,
cancel
:=
getContextWithTimeout
(
t
)
defer
cancel
()
r
.
errorMapLock
.
Lock
()
delete
(
r
.
lastError
,
containerID
)
delete
(
r
.
errorPrinted
,
containerID
)
r
.
errorMapLock
.
Unlock
()
_
,
err
:=
r
.
runtimeClient
.
StopContainer
(
ctx
,
&
runtimeapi
.
StopContainerRequest
{
ContainerId
:
containerID
,
Timeout
:
timeout
,
...
...
@@ -256,8 +260,10 @@ func (r *RemoteRuntimeService) RemoveContainer(containerID string) error {
ctx
,
cancel
:=
getContextWithTimeout
(
r
.
timeout
)
defer
cancel
()
r
.
errorMapLock
.
Lock
()
delete
(
r
.
lastError
,
containerID
)
delete
(
r
.
errorPrinted
,
containerID
)
r
.
errorMapLock
.
Unlock
()
_
,
err
:=
r
.
runtimeClient
.
RemoveContainer
(
ctx
,
&
runtimeapi
.
RemoveContainerRequest
{
ContainerId
:
containerID
,
})
...
...
@@ -287,6 +293,8 @@ func (r *RemoteRuntimeService) ListContainers(filter *runtimeapi.ContainerFilter
// Clean up any expired last-error timers
func
(
r
*
RemoteRuntimeService
)
cleanupErrorTimeouts
()
{
r
.
errorMapLock
.
Lock
()
defer
r
.
errorMapLock
.
Unlock
()
for
ID
,
timeout
:=
range
r
.
errorPrinted
{
if
time
.
Now
()
.
Sub
(
timeout
)
>=
identicalErrorDelay
{
delete
(
r
.
lastError
,
ID
)
...
...
@@ -304,6 +312,8 @@ func (r *RemoteRuntimeService) ContainerStatus(containerID string) (*runtimeapi.
ContainerId
:
containerID
,
})
r
.
cleanupErrorTimeouts
()
r
.
errorMapLock
.
Lock
()
defer
r
.
errorMapLock
.
Unlock
()
if
err
!=
nil
{
// Don't spam the log with endless messages about the same failure.
lastMsg
,
ok
:=
r
.
lastError
[
containerID
]
...
...
@@ -491,6 +501,8 @@ func (r *RemoteRuntimeService) ContainerStats(containerID string) (*runtimeapi.C
ContainerId
:
containerID
,
})
r
.
cleanupErrorTimeouts
()
r
.
errorMapLock
.
Lock
()
defer
r
.
errorMapLock
.
Unlock
()
if
err
!=
nil
{
lastMsg
,
ok
:=
r
.
lastError
[
containerID
]
if
!
ok
||
err
.
Error
()
!=
lastMsg
||
time
.
Now
()
.
Sub
(
r
.
errorPrinted
[
containerID
])
>=
identicalErrorDelay
{
...
...
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