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
14730841
Commit
14730841
authored
Dec 01, 2016
by
Derek Carr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix logic in graceful deletion if existing grace period was 0
parent
e5b559ac
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletion
+46
-1
delete.go
pkg/api/rest/delete.go
+9
-1
store_test.go
pkg/registry/generic/registry/store_test.go
+37
-0
No files found.
pkg/api/rest/delete.go
View file @
14730841
...
@@ -81,7 +81,15 @@ func BeforeDelete(strategy RESTDeleteStrategy, ctx api.Context, obj runtime.Obje
...
@@ -81,7 +81,15 @@ func BeforeDelete(strategy RESTDeleteStrategy, ctx api.Context, obj runtime.Obje
// if we are already being deleted, we may only shorten the deletion grace period
// if we are already being deleted, we may only shorten the deletion grace period
// this means the object was gracefully deleted previously but deletionGracePeriodSeconds was not set,
// this means the object was gracefully deleted previously but deletionGracePeriodSeconds was not set,
// so we force deletion immediately
// so we force deletion immediately
if
objectMeta
.
DeletionGracePeriodSeconds
==
nil
{
// IMPORTANT:
// The deletion operation happens in two phases.
// 1. Update to set DeletionGracePeriodSeconds and DeletionTimestamp
// 2. Delete the object from storage.
// If the update succeeds, but the delete fails (network error, internal storage error, etc.),
// a resource was previously left in a state that was non-recoverable. We
// check if the existing stored resource has a grace period as 0 and if so
// attempt to delete immediately in order to recover from this scenario.
if
objectMeta
.
DeletionGracePeriodSeconds
==
nil
||
*
objectMeta
.
DeletionGracePeriodSeconds
==
0
{
return
false
,
false
,
nil
return
false
,
false
,
nil
}
}
// only a shorter grace period may be provided by a user
// only a shorter grace period may be provided by a user
...
...
pkg/registry/generic/registry/store_test.go
View file @
14730841
...
@@ -616,6 +616,43 @@ func TestStoreDelete(t *testing.T) {
...
@@ -616,6 +616,43 @@ func TestStoreDelete(t *testing.T) {
}
}
}
}
// TestGracefulStoreCanDeleteIfExistingGracePeriodZero tests recovery from
// race condition where the graceful delete is unable to complete
// in prior operation, but the pod remains with deletion timestamp
// and grace period set to 0.
func
TestGracefulStoreCanDeleteIfExistingGracePeriodZero
(
t
*
testing
.
T
)
{
deletionTimestamp
:=
unversioned
.
NewTime
(
time
.
Now
())
deletionGracePeriodSeconds
:=
int64
(
0
)
initialGeneration
:=
int64
(
1
)
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"foo"
,
Generation
:
initialGeneration
,
DeletionGracePeriodSeconds
:
&
deletionGracePeriodSeconds
,
DeletionTimestamp
:
&
deletionTimestamp
,
},
Spec
:
api
.
PodSpec
{
NodeName
:
"machine"
},
}
testContext
:=
api
.
WithNamespace
(
api
.
NewContext
(),
"test"
)
destroyFunc
,
registry
:=
NewTestGenericStoreRegistry
(
t
)
registry
.
EnableGarbageCollection
=
false
defaultDeleteStrategy
:=
testRESTStrategy
{
api
.
Scheme
,
api
.
SimpleNameGenerator
,
true
,
false
,
true
}
registry
.
DeleteStrategy
=
testGracefulStrategy
{
defaultDeleteStrategy
}
defer
destroyFunc
()
graceful
,
gracefulPending
,
err
:=
rest
.
BeforeDelete
(
registry
.
DeleteStrategy
,
testContext
,
pod
,
api
.
NewDeleteOptions
(
0
))
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
if
graceful
{
t
.
Fatalf
(
"graceful should be false if object has DeletionTimestamp and DeletionGracePeriodSeconds is 0"
)
}
if
gracefulPending
{
t
.
Fatalf
(
"gracefulPending should be false if object has DeletionTimestamp and DeletionGracePeriodSeconds is 0"
)
}
}
func
TestGracefulStoreHandleFinalizers
(
t
*
testing
.
T
)
{
func
TestGracefulStoreHandleFinalizers
(
t
*
testing
.
T
)
{
initialGeneration
:=
int64
(
1
)
initialGeneration
:=
int64
(
1
)
podWithFinalizer
:=
&
api
.
Pod
{
podWithFinalizer
:=
&
api
.
Pod
{
...
...
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