Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/test/client: retry cleanup function if cluster is temporarily unavailable #2277

Merged
merged 1 commit into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Changed
- Changed error wrapping according to Go version 1.13+ [error handling](https://blog.golang.org/go1.13-errors). ([#2355](https://github.com/operator-framework/operator-sdk/pull/2355))
- Added retry logic to the cleanup function from the e2e test framework in order to allow it to be achieved in the scenarios where temporary network issues are faced. ([#2277](https://github.com/operator-framework/operator-sdk/pull/2277))

### Deprecated

Expand Down
9 changes: 8 additions & 1 deletion pkg/test/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
dynclient "sigs.k8s.io/controller-runtime/pkg/client"
Copy link
Contributor

@camilamacedo86 camilamacedo86 Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JAORMX the entry in CHANGELOG is no longer here :-(
Could you please add it again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which entry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An entry describing the change/fix/add to let the users know what was changed. Was not it added before?
See here
Following my suggestion.

...
## Changed
- Added retry logic to the cleanup function from the e2e test framework in order to allow it to be achieved in the scenarios where temporary network issues are faced. ([#2277](https://github.com/operator-framework/operator-sdk/pull/2277))

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sonuds good to me! thanks!

)

Expand All @@ -38,6 +39,10 @@ type FrameworkClient interface {
Update(gCtx goctx.Context, obj runtime.Object) error
}

func retryOnAnyError(err error) bool {
return !apierrors.IsNotFound(err)
}

// Create uses the dynamic client to create an object and then adds a
// cleanup function to delete it when Cleanup is called. In addition to
// the standard controller-runtime client options
Expand All @@ -57,7 +62,9 @@ func (f *frameworkClient) Create(gCtx goctx.Context, obj runtime.Object, cleanup
cleanupOptions.TestContext.t.Logf("resource type %+v with namespace/name (%+v) created\n", objCopy.GetObjectKind().GroupVersionKind().Kind, key)
}
cleanupOptions.TestContext.AddCleanupFn(func() error {
err = f.Client.Delete(gCtx, objCopy)
err = retry.OnError(retry.DefaultRetry, retryOnAnyError, func() error {
return f.Client.Delete(gCtx, objCopy)
})
if err != nil && !apierrors.IsNotFound(err) {
return err
}
Expand Down