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
ed4c5085
Unverified
Commit
ed4c5085
authored
May 13, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 13, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #77619 from caesarxuchao/always-retry
In GuaranteedUpdate, retry on any error if we are working with cached data
parents
0252a323
5e53522a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
11 deletions
+56
-11
store_test.go
....io/apiserver/pkg/registry/generic/registry/store_test.go
+44
-0
store.go
staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go
+12
-11
No files found.
staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store_test.go
View file @
ed4c5085
...
...
@@ -1851,3 +1851,47 @@ func TestMarkAsDeleting(t *testing.T) {
})
}
}
type
staleGuaranteedUpdateStorage
struct
{
storage
.
Interface
cachedObj
runtime
.
Object
}
// GuaranteedUpdate overwrites the method with one that always suggests the cachedObj.
func
(
s
*
staleGuaranteedUpdateStorage
)
GuaranteedUpdate
(
ctx
context
.
Context
,
key
string
,
ptrToType
runtime
.
Object
,
ignoreNotFound
bool
,
preconditions
*
storage
.
Preconditions
,
tryUpdate
storage
.
UpdateFunc
,
_
...
runtime
.
Object
)
error
{
return
s
.
Interface
.
GuaranteedUpdate
(
ctx
,
key
,
ptrToType
,
ignoreNotFound
,
preconditions
,
tryUpdate
,
s
.
cachedObj
)
}
func
TestDeleteWithCachedObject
(
t
*
testing
.
T
)
{
podName
:=
"foo"
podWithFinalizer
:=
&
example
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
podName
,
Finalizers
:
[]
string
{
"foo.com/x"
}},
Spec
:
example
.
PodSpec
{
NodeName
:
"machine"
},
}
podWithNoFinalizer
:=
&
example
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
podName
},
Spec
:
example
.
PodSpec
{
NodeName
:
"machine"
},
}
ctx
:=
genericapirequest
.
WithNamespace
(
genericapirequest
.
NewContext
(),
"test"
)
destroyFunc
,
registry
:=
newTestGenericStoreRegistry
(
t
,
scheme
,
false
)
defer
destroyFunc
()
// cached object does not have any finalizer.
registry
.
Storage
.
Storage
=
&
staleGuaranteedUpdateStorage
{
Interface
:
registry
.
Storage
.
Storage
,
cachedObj
:
podWithNoFinalizer
}
// created object with pending finalizer.
_
,
err
:=
registry
.
Create
(
ctx
,
podWithFinalizer
,
rest
.
ValidateAllObjectFunc
,
&
metav1
.
CreateOptions
{})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// The object shouldn't be deleted, because the persisted object has pending finalizers.
_
,
_
,
err
=
registry
.
Delete
(
ctx
,
podName
,
nil
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// The object should still be there
_
,
err
=
registry
.
Get
(
ctx
,
podName
,
&
metav1
.
GetOptions
{})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
staging/src/k8s.io/apiserver/pkg/storage/etcd3/store.go
View file @
ed4c5085
...
...
@@ -301,19 +301,20 @@ func (s *store) GuaranteedUpdate(
ret
,
ttl
,
err
:=
s
.
updateState
(
origState
,
tryUpdate
)
if
err
!=
nil
{
// It's possible we were working with stale data
if
mustCheckData
&&
apierrors
.
IsConflict
(
err
)
{
// Actually fetch
origState
,
err
=
getCurrentState
()
if
err
!=
nil
{
return
err
}
mustCheckData
=
false
// Retry
continue
// If our data is already up to date, return the error
if
!
mustCheckData
{
return
err
}
return
err
// It's possible we were working with stale data
// Actually fetch
origState
,
err
=
getCurrentState
()
if
err
!=
nil
{
return
err
}
mustCheckData
=
false
// Retry
continue
}
data
,
err
:=
runtime
.
Encode
(
s
.
codec
,
ret
)
...
...
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