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
7b6aa090
Commit
7b6aa090
authored
Oct 24, 2017
by
Seth Jennings
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
validate container state transitions
parent
2aeace40
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
1 deletion
+32
-1
validation.go
pkg/apis/core/validation/validation.go
+32
-1
No files found.
pkg/apis/core/validation/validation.go
View file @
7b6aa090
...
@@ -3322,6 +3322,31 @@ func ValidatePodUpdate(newPod, oldPod *core.Pod) field.ErrorList {
...
@@ -3322,6 +3322,31 @@ func ValidatePodUpdate(newPod, oldPod *core.Pod) field.ErrorList {
return
allErrs
return
allErrs
}
}
// ValidateContainerStateTransition test to if any illegal container state transitions are being attempted
func
ValidateContainerStateTransition
(
newStatuses
,
oldStatuses
[]
core
.
ContainerStatus
,
fldpath
*
field
.
Path
,
restartPolicy
core
.
RestartPolicy
)
field
.
ErrorList
{
allErrs
:=
field
.
ErrorList
{}
// If we should always restart, containers are allowed to leave the terminated state
if
restartPolicy
==
core
.
RestartPolicyAlways
{
return
allErrs
}
for
i
,
oldStatus
:=
range
oldStatuses
{
// Skip any container that is not terminated
if
oldStatus
.
State
.
Terminated
==
nil
{
continue
}
// Skip any container that failed but is allowed to restart
if
oldStatus
.
State
.
Terminated
.
ExitCode
!=
0
&&
restartPolicy
==
core
.
RestartPolicyOnFailure
{
continue
}
for
_
,
newStatus
:=
range
newStatuses
{
if
oldStatus
.
Name
==
newStatus
.
Name
&&
newStatus
.
State
.
Terminated
==
nil
{
allErrs
=
append
(
allErrs
,
field
.
Forbidden
(
fldpath
.
Index
(
i
)
.
Child
(
"state"
),
"may not be transitioned to non-terminated state"
))
}
}
}
return
allErrs
}
// ValidatePodStatusUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields
// ValidatePodStatusUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields
// that cannot be changed.
// that cannot be changed.
func
ValidatePodStatusUpdate
(
newPod
,
oldPod
*
core
.
Pod
)
field
.
ErrorList
{
func
ValidatePodStatusUpdate
(
newPod
,
oldPod
*
core
.
Pod
)
field
.
ErrorList
{
...
@@ -3329,10 +3354,16 @@ func ValidatePodStatusUpdate(newPod, oldPod *core.Pod) field.ErrorList {
...
@@ -3329,10 +3354,16 @@ func ValidatePodStatusUpdate(newPod, oldPod *core.Pod) field.ErrorList {
allErrs
:=
ValidateObjectMetaUpdate
(
&
newPod
.
ObjectMeta
,
&
oldPod
.
ObjectMeta
,
fldPath
)
allErrs
:=
ValidateObjectMetaUpdate
(
&
newPod
.
ObjectMeta
,
&
oldPod
.
ObjectMeta
,
fldPath
)
allErrs
=
append
(
allErrs
,
ValidatePodSpecificAnnotationUpdates
(
newPod
,
oldPod
,
fldPath
.
Child
(
"annotations"
))
...
)
allErrs
=
append
(
allErrs
,
ValidatePodSpecificAnnotationUpdates
(
newPod
,
oldPod
,
fldPath
.
Child
(
"annotations"
))
...
)
fldPath
=
field
.
NewPath
(
"status"
)
if
newPod
.
Spec
.
NodeName
!=
oldPod
.
Spec
.
NodeName
{
if
newPod
.
Spec
.
NodeName
!=
oldPod
.
Spec
.
NodeName
{
allErrs
=
append
(
allErrs
,
field
.
Forbidden
(
f
ield
.
NewPath
(
"status"
,
"nodeName"
),
"may not be changed directly"
))
allErrs
=
append
(
allErrs
,
field
.
Forbidden
(
f
ldPath
.
Child
(
"nodeName"
),
"may not be changed directly"
))
}
}
// If pod should not restart, make sure the status update does not transition
// any terminated containers to a non-terminated state.
allErrs
=
append
(
allErrs
,
ValidateContainerStateTransition
(
newPod
.
Status
.
ContainerStatuses
,
oldPod
.
Status
.
ContainerStatuses
,
fldPath
.
Child
(
"containerStatuses"
),
oldPod
.
Spec
.
RestartPolicy
)
...
)
allErrs
=
append
(
allErrs
,
ValidateContainerStateTransition
(
newPod
.
Status
.
InitContainerStatuses
,
oldPod
.
Status
.
InitContainerStatuses
,
fldPath
.
Child
(
"initContainerStatuses"
),
oldPod
.
Spec
.
RestartPolicy
)
...
)
// For status update we ignore changes to pod spec.
// For status update we ignore changes to pod spec.
newPod
.
Spec
=
oldPod
.
Spec
newPod
.
Spec
=
oldPod
.
Spec
...
...
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