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
17588f0f
Commit
17588f0f
authored
Jan 21, 2019
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not move deletionTimestamp to the future
parent
5e86fa43
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
5 deletions
+53
-5
store.go
...c/k8s.io/apiserver/pkg/registry/generic/registry/store.go
+9
-5
store_test.go
....io/apiserver/pkg/registry/generic/registry/store_test.go
+44
-0
No files found.
staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store.go
View file @
17588f0f
...
@@ -841,21 +841,25 @@ func deletionFinalizersForGarbageCollection(ctx context.Context, e *Store, acces
...
@@ -841,21 +841,25 @@ func deletionFinalizersForGarbageCollection(ctx context.Context, e *Store, acces
}
}
// markAsDeleting sets the obj's DeletionGracePeriodSeconds to 0, and sets the
// markAsDeleting sets the obj's DeletionGracePeriodSeconds to 0, and sets the
// DeletionTimestamp to "now". Finalizers are watching for such updates and will
// DeletionTimestamp to "now" if there is no existing deletionTimestamp or if the existing
// deletionTimestamp is further in future. Finalizers are watching for such updates and will
// finalize the object if their IDs are present in the object's Finalizers list.
// finalize the object if their IDs are present in the object's Finalizers list.
func
markAsDeleting
(
obj
runtime
.
Object
)
(
err
error
)
{
func
markAsDeleting
(
obj
runtime
.
Object
,
now
time
.
Time
)
(
err
error
)
{
objectMeta
,
kerr
:=
meta
.
Accessor
(
obj
)
objectMeta
,
kerr
:=
meta
.
Accessor
(
obj
)
if
kerr
!=
nil
{
if
kerr
!=
nil
{
return
kerr
return
kerr
}
}
now
:=
metav1
.
NewTime
(
time
.
Now
())
// This handles Generation bump for resources that don't support graceful
// This handles Generation bump for resources that don't support graceful
// deletion. For resources that support graceful deletion is handle in
// deletion. For resources that support graceful deletion is handle in
// pkg/api/rest/delete.go
// pkg/api/rest/delete.go
if
objectMeta
.
GetDeletionTimestamp
()
==
nil
&&
objectMeta
.
GetGeneration
()
>
0
{
if
objectMeta
.
GetDeletionTimestamp
()
==
nil
&&
objectMeta
.
GetGeneration
()
>
0
{
objectMeta
.
SetGeneration
(
objectMeta
.
GetGeneration
()
+
1
)
objectMeta
.
SetGeneration
(
objectMeta
.
GetGeneration
()
+
1
)
}
}
objectMeta
.
SetDeletionTimestamp
(
&
now
)
existingDeletionTimestamp
:=
objectMeta
.
GetDeletionTimestamp
()
if
existingDeletionTimestamp
==
nil
||
existingDeletionTimestamp
.
After
(
now
)
{
metaNow
:=
metav1
.
NewTime
(
now
)
objectMeta
.
SetDeletionTimestamp
(
&
metaNow
)
}
var
zero
int64
=
0
var
zero
int64
=
0
objectMeta
.
SetDeletionGracePeriodSeconds
(
&
zero
)
objectMeta
.
SetDeletionGracePeriodSeconds
(
&
zero
)
return
nil
return
nil
...
@@ -910,7 +914,7 @@ func (e *Store) updateForGracefulDeletionAndFinalizers(ctx context.Context, name
...
@@ -910,7 +914,7 @@ func (e *Store) updateForGracefulDeletionAndFinalizers(ctx context.Context, name
// set the DeleteGracePeriods to 0 if the object has pendingFinalizers but not supporting graceful deletion
// set the DeleteGracePeriods to 0 if the object has pendingFinalizers but not supporting graceful deletion
if
pendingFinalizers
{
if
pendingFinalizers
{
klog
.
V
(
6
)
.
Infof
(
"update the DeletionTimestamp to
\"
now
\"
and GracePeriodSeconds to 0 for object %s, because it has pending finalizers"
,
name
)
klog
.
V
(
6
)
.
Infof
(
"update the DeletionTimestamp to
\"
now
\"
and GracePeriodSeconds to 0 for object %s, because it has pending finalizers"
,
name
)
err
=
markAsDeleting
(
existing
)
err
=
markAsDeleting
(
existing
,
time
.
Now
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store_test.go
View file @
17588f0f
...
@@ -2108,3 +2108,47 @@ func TestDeletionFinalizersForGarbageCollection(t *testing.T) {
...
@@ -2108,3 +2108,47 @@ func TestDeletionFinalizersForGarbageCollection(t *testing.T) {
}
}
}
}
}
}
func
TestMarkAsDeleting
(
t
*
testing
.
T
)
{
now
:=
time
.
Now
()
soon
:=
now
.
Add
(
time
.
Second
)
past
:=
now
.
Add
(
-
time
.
Second
)
newTimePointer
:=
func
(
t
time
.
Time
)
*
metav1
.
Time
{
metaTime
:=
metav1
.
NewTime
(
t
)
return
&
metaTime
}
testcases
:=
[]
struct
{
name
string
deletionTimestamp
*
metav1
.
Time
expectDeletionTimestamp
*
metav1
.
Time
}{
{
name
:
"unset"
,
deletionTimestamp
:
nil
,
expectDeletionTimestamp
:
newTimePointer
(
now
),
},
{
name
:
"set to future"
,
deletionTimestamp
:
newTimePointer
(
soon
),
expectDeletionTimestamp
:
newTimePointer
(
now
),
},
{
name
:
"set to past"
,
deletionTimestamp
:
newTimePointer
(
past
),
expectDeletionTimestamp
:
newTimePointer
(
past
),
},
}
for
_
,
tc
:=
range
testcases
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
rs
:=
&
example
.
ReplicaSet
{}
rs
.
DeletionTimestamp
=
tc
.
deletionTimestamp
if
err
:=
markAsDeleting
(
rs
,
now
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
reflect
.
DeepEqual
(
*
rs
.
DeletionTimestamp
,
tc
.
expectDeletionTimestamp
)
{
t
.
Errorf
(
"expected %v, got %v"
,
tc
.
expectDeletionTimestamp
,
*
rs
.
DeletionTimestamp
)
}
})
}
}
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