Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ijaz Ahmad
ksonnet
Commits
4b260d7d
Unverified
Commit
4b260d7d
authored
Jul 25, 2018
by
Bryan Liles
Committed by
GitHub
Jul 25, 2018
Browse files
Merge pull request #787 from Fresh-Tracks/fetch-before-retry
Get a new version of the object when retrying on conflict
parents
4ae36223
5ac8a7fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
pkg/cluster/apply.go
pkg/cluster/apply.go
+13
-0
pkg/cluster/apply_test.go
pkg/cluster/apply_test.go
+8
-0
No files found.
pkg/cluster/apply.go
View file @
4b260d7d
...
...
@@ -204,6 +204,11 @@ func (a *Apply) upsert(obj *unstructured.Unstructured) (string, error) {
if
!
kerrors
.
IsConflict
(
cause
)
{
return
""
,
err
}
// In order for the next try to work, update the resource version on the object
updatedObj
,
err
:=
a
.
getUpdatedObject
(
obj
)
if
err
==
nil
{
obj
.
SetResourceVersion
(
updatedObj
.
GetResourceVersion
())
}
time
.
Sleep
(
a
.
conflictTimeout
)
continue
...
...
@@ -215,6 +220,14 @@ func (a *Apply) upsert(obj *unstructured.Unstructured) (string, error) {
return
""
,
errApplyConflict
}
func
(
a
*
Apply
)
getUpdatedObject
(
obj
*
unstructured
.
Unstructured
)
(
*
unstructured
.
Unstructured
,
error
)
{
rc
,
err
:=
a
.
resourceClientFactory
(
*
a
.
clientOpts
,
obj
)
if
err
!=
nil
{
return
nil
,
err
}
return
rc
.
Get
(
metav1
.
GetOptions
{})
}
// setupGC setups ksonnet's garbage collection process for objects.
func
(
a
*
Apply
)
setupGC
(
obj
*
unstructured
.
Unstructured
)
{
if
a
.
GcTag
!=
""
{
...
...
pkg/cluster/apply_test.go
View file @
4b260d7d
...
...
@@ -20,13 +20,16 @@ import (
kerrors
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"github.com/ksonnet/ksonnet/pkg/app"
amocks
"github.com/ksonnet/ksonnet/pkg/app/mocks"
"github.com/ksonnet/ksonnet/pkg/client"
"github.com/ksonnet/ksonnet/pkg/cluster/mocks"
"github.com/ksonnet/ksonnet/pkg/util/test"
"github.com/pkg/errors"
"github.com/spf13/afero"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
)
...
...
@@ -130,6 +133,11 @@ func Test_Apply_retry_on_conflict(t *testing.T) {
obj
:=
&
unstructured
.
Unstructured
{
Object
:
genObject
()}
apply
.
clientOpts
=
&
clientOpts
{}
apply
.
resourceClientFactory
=
func
(
opts
clientOpts
,
object
runtime
.
Object
)
(
ResourceClient
,
error
)
{
rc
:=
&
mocks
.
ResourceClient
{}
rc
.
On
(
"Get"
,
mock
.
Anything
)
.
Return
(
obj
,
nil
)
return
rc
,
nil
}
apply
.
findObjectsFn
=
func
(
a
app
.
App
,
envName
string
,
componentNames
[]
string
)
([]
*
unstructured
.
Unstructured
,
error
)
{
objects
:=
[]
*
unstructured
.
Unstructured
{
obj
}
...
...
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