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
5f6c0227
Commit
5f6c0227
authored
Oct 27, 2017
by
Joel Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent successful containers from restarting with OnFailure restart policy
parent
b00c15f1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
16 deletions
+23
-16
status_manager.go
pkg/kubelet/status/status_manager.go
+23
-16
No files found.
pkg/kubelet/status/status_manager.go
View file @
5f6c0227
...
@@ -268,13 +268,22 @@ func (m *manager) TerminatePod(pod *v1.Pod) {
...
@@ -268,13 +268,22 @@ func (m *manager) TerminatePod(pod *v1.Pod) {
// checkContainerStateTransition ensures that no container is trying to transition
// checkContainerStateTransition ensures that no container is trying to transition
// from a terminated to non-terminated state, which is illegal and indicates a
// from a terminated to non-terminated state, which is illegal and indicates a
// logical error in the kubelet.
// logical error in the kubelet.
func
checkContainerStateTransition
(
oldStatuses
,
newStatuses
[]
v1
.
ContainerStatus
)
error
{
func
checkContainerStateTransition
(
oldStatuses
,
newStatuses
[]
v1
.
ContainerStatus
,
restartPolicy
v1
.
RestartPolicy
)
error
{
for
_
,
newStatus
:=
range
newStatuses
{
// If we should always restart, containers are allowed to leave the terminated state
for
_
,
oldStatus
:=
range
oldStatuses
{
if
restartPolicy
==
v1
.
RestartPolicyAlways
{
if
newStatus
.
Name
!=
oldStatus
.
Name
{
return
nil
continue
}
}
for
_
,
oldStatus
:=
range
oldStatuses
{
if
oldStatus
.
State
.
Terminated
!=
nil
&&
newStatus
.
State
.
Terminated
==
nil
{
// Skip any container that wasn't terminated
if
oldStatus
.
State
.
Terminated
==
nil
{
continue
}
// Skip any container that failed but is allowed to restart
if
oldStatus
.
State
.
Terminated
.
ExitCode
!=
0
&&
restartPolicy
==
v1
.
RestartPolicyOnFailure
{
continue
}
for
_
,
newStatus
:=
range
newStatuses
{
if
oldStatus
.
Name
==
newStatus
.
Name
&&
newStatus
.
State
.
Terminated
==
nil
{
return
fmt
.
Errorf
(
"terminated container %v attempted illegal transition to non-terminated state"
,
newStatus
.
Name
)
return
fmt
.
Errorf
(
"terminated container %v attempted illegal transition to non-terminated state"
,
newStatus
.
Name
)
}
}
}
}
...
@@ -297,15 +306,13 @@ func (m *manager) updateStatusInternal(pod *v1.Pod, status v1.PodStatus, forceUp
...
@@ -297,15 +306,13 @@ func (m *manager) updateStatusInternal(pod *v1.Pod, status v1.PodStatus, forceUp
}
}
// Check for illegal state transition in containers
// Check for illegal state transition in containers
if
pod
.
Spec
.
RestartPolicy
==
v1
.
RestartPolicyNever
{
if
err
:=
checkContainerStateTransition
(
oldStatus
.
ContainerStatuses
,
status
.
ContainerStatuses
,
pod
.
Spec
.
RestartPolicy
);
err
!=
nil
{
if
err
:=
checkContainerStateTransition
(
oldStatus
.
ContainerStatuses
,
status
.
ContainerStatuses
);
err
!=
nil
{
glog
.
Errorf
(
"Status update on pod %v/%v aborted: %v"
,
pod
.
Namespace
,
pod
.
Name
,
err
)
glog
.
Errorf
(
"Status update on pod %v/%v aborted: %v"
,
pod
.
Namespace
,
pod
.
Name
,
err
)
return
false
return
false
}
}
if
err
:=
checkContainerStateTransition
(
oldStatus
.
InitContainerStatuses
,
status
.
InitContainerStatuses
,
pod
.
Spec
.
RestartPolicy
);
err
!=
nil
{
if
err
:=
checkContainerStateTransition
(
oldStatus
.
InitContainerStatuses
,
status
.
InitContainerStatuses
);
err
!=
nil
{
glog
.
Errorf
(
"Status update on pod %v/%v aborted: %v"
,
pod
.
Namespace
,
pod
.
Name
,
err
)
glog
.
Errorf
(
"Status update on pod %v/%v aborted: %v"
,
pod
.
Namespace
,
pod
.
Name
,
err
)
return
false
return
false
}
}
}
// Set ReadyCondition.LastTransitionTime.
// Set ReadyCondition.LastTransitionTime.
...
...
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