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
cb57dc4c
Commit
cb57dc4c
authored
Sep 23, 2016
by
Yu-Ju Hong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kuberuntime: include container hash in backoff keys
We should reset the backoff if the content of the container has been updated.
parent
18340399
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
5 deletions
+61
-5
helpers.go
pkg/kubelet/kuberuntime/helpers.go
+9
-0
helpers_test.go
pkg/kubelet/kuberuntime/helpers_test.go
+47
-0
kuberuntime_manager.go
pkg/kubelet/kuberuntime/kuberuntime_manager.go
+5
-5
No files found.
pkg/kubelet/kuberuntime/helpers.go
View file @
cb57dc4c
...
@@ -18,6 +18,7 @@ package kuberuntime
...
@@ -18,6 +18,7 @@ package kuberuntime
import
(
import
(
"fmt"
"fmt"
"strconv"
"github.com/golang/glog"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
@@ -160,3 +161,11 @@ func milliCPUToQuota(milliCPU int64) (quota int64, period int64) {
...
@@ -160,3 +161,11 @@ func milliCPUToQuota(milliCPU int64) (quota int64, period int64) {
return
return
}
}
// getStableKey generates a key (string) to uniquely identify a
// (pod, container) tuple. The key should include the content of the
// container, so that any change to the container generates a new key.
func
getStableKey
(
pod
*
api
.
Pod
,
container
*
api
.
Container
)
string
{
hash
:=
strconv
.
FormatUint
(
kubecontainer
.
HashContainer
(
container
),
16
)
return
fmt
.
Sprintf
(
"%s_%s_%s_%s_%s"
,
pod
.
Name
,
pod
.
Namespace
,
string
(
pod
.
UID
),
container
.
Name
,
hash
)
}
pkg/kubelet/kuberuntime/helpers_test.go
0 → 100644
View file @
cb57dc4c
/*
Copyright 2016 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
kuberuntime
import
(
"testing"
"github.com/stretchr/testify/assert"
"k8s.io/kubernetes/pkg/api"
)
func
TestStableKey
(
t
*
testing
.
T
)
{
container
:=
&
api
.
Container
{
Name
:
"test_container"
,
Image
:
"foo/image:v1"
,
}
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"test_pod"
,
Namespace
:
"test_pod_namespace"
,
UID
:
"test_pod_uid"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
*
container
},
},
}
oldKey
:=
getStableKey
(
pod
,
container
)
// Updating the container image should change the key.
container
.
Image
=
"foo/image:v2"
newKey
:=
getStableKey
(
pod
,
container
)
assert
.
NotEqual
(
t
,
oldKey
,
newKey
)
}
pkg/kubelet/kuberuntime/kuberuntime_manager.go
View file @
cb57dc4c
...
@@ -627,18 +627,18 @@ func (m *kubeGenericRuntimeManager) doBackOff(pod *api.Pod, container *api.Conta
...
@@ -627,18 +627,18 @@ func (m *kubeGenericRuntimeManager) doBackOff(pod *api.Pod, container *api.Conta
glog
.
Infof
(
"checking backoff for container %q in pod %q"
,
container
.
Name
,
format
.
Pod
(
pod
))
glog
.
Infof
(
"checking backoff for container %q in pod %q"
,
container
.
Name
,
format
.
Pod
(
pod
))
// Use the finished time of the latest exited container as the start point to calculate whether to do back-off.
// Use the finished time of the latest exited container as the start point to calculate whether to do back-off.
ts
:=
cStatus
.
FinishedAt
ts
:=
cStatus
.
FinishedAt
// backOff requires a unique
id to identify the container
// backOff requires a unique
key to identify the container.
stableName
:=
fmt
.
Sprintf
(
"%s_%s_%s_%s"
,
pod
.
Name
,
pod
.
Namespace
,
string
(
pod
.
UID
),
container
.
Name
)
key
:=
getStableKey
(
pod
,
container
)
if
backOff
.
IsInBackOffSince
(
stableName
,
ts
)
{
if
backOff
.
IsInBackOffSince
(
key
,
ts
)
{
if
ref
,
err
:=
kubecontainer
.
GenerateContainerRef
(
pod
,
container
);
err
==
nil
{
if
ref
,
err
:=
kubecontainer
.
GenerateContainerRef
(
pod
,
container
);
err
==
nil
{
m
.
recorder
.
Eventf
(
ref
,
api
.
EventTypeWarning
,
events
.
BackOffStartContainer
,
"Back-off restarting failed container"
)
m
.
recorder
.
Eventf
(
ref
,
api
.
EventTypeWarning
,
events
.
BackOffStartContainer
,
"Back-off restarting failed container"
)
}
}
err
:=
fmt
.
Errorf
(
"Back-off %s restarting failed container=%s pod=%s"
,
backOff
.
Get
(
stableName
),
container
.
Name
,
format
.
Pod
(
pod
))
err
:=
fmt
.
Errorf
(
"Back-off %s restarting failed container=%s pod=%s"
,
backOff
.
Get
(
key
),
container
.
Name
,
format
.
Pod
(
pod
))
glog
.
Infof
(
"%s"
,
err
.
Error
())
glog
.
Infof
(
"%s"
,
err
.
Error
())
return
true
,
err
.
Error
(),
kubecontainer
.
ErrCrashLoopBackOff
return
true
,
err
.
Error
(),
kubecontainer
.
ErrCrashLoopBackOff
}
}
backOff
.
Next
(
stableName
,
ts
)
backOff
.
Next
(
key
,
ts
)
return
false
,
""
,
nil
return
false
,
""
,
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