-
Notifications
You must be signed in to change notification settings - Fork 152
Implement Status Updater Retrying on Failures #1062
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8a12ef7
Add retrying logic
bjee19 3700daf
WIP
bjee19 1b12225
Use imported retry function and address review feedback
bjee19 977e594
Delete unused fake client
bjee19 c66f3e5
Add back deleted documentation
bjee19 c1f7bc3
Move comments around
bjee19 1fdb2a3
Fix renaming mistake
bjee19 5922b7e
Switch to using ToNot instead of ShouldNot
bjee19 2d17d36
Remove unnecessary goroutines
bjee19 b1fcff1
Remove lastError and add debug level logs
bjee19 eab8773
Add error to debug message
bjee19 936ca4c
WIP
bjee19 c62b364
Add testing for ConditionWithContextFunc
bjee19 c304fa2
Change naming and add subtests
bjee19 1149c6f
Add review feedback
bjee19 4ee28e9
Add small comment fix
bjee19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package status | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| ) | ||
|
|
||
| //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . K8sUpdater | ||
|
|
||
| // K8sUpdater updates a resource from the k8s API. | ||
| // It allows us to mock the client.Reader.Status.Update method. | ||
| type K8sUpdater interface { | ||
| // Update is from client.StatusClient.SubResourceWriter. | ||
| Update(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error | ||
| } |
117 changes: 117 additions & 0 deletions
117
internal/framework/status/statusfakes/fake_k8s_updater.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| package status_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
|
|
||
| . "github.com/onsi/gomega" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
| "sigs.k8s.io/gateway-api/apis/v1beta1" | ||
|
|
||
| "github.com/nginxinc/nginx-gateway-fabric/internal/framework/controller/controllerfakes" | ||
| "github.com/nginxinc/nginx-gateway-fabric/internal/framework/status" | ||
| "github.com/nginxinc/nginx-gateway-fabric/internal/framework/status/statusfakes" | ||
| ) | ||
|
|
||
| func TestNewRetryUpdateFunc(t *testing.T) { | ||
| tests := []struct { | ||
| getReturns error | ||
| updateReturns error | ||
| name string | ||
| expConditionPassed bool | ||
| }{ | ||
| { | ||
| getReturns: errors.New("failed to get resource"), | ||
| updateReturns: nil, | ||
| name: "get fails", | ||
| expConditionPassed: false, | ||
| }, | ||
| { | ||
| getReturns: apierrors.NewNotFound(schema.GroupResource{}, "not found"), | ||
| updateReturns: nil, | ||
| name: "get fails and apierrors is not found", | ||
| expConditionPassed: true, | ||
| }, | ||
| { | ||
| getReturns: nil, | ||
| updateReturns: errors.New("failed to update resource"), | ||
| name: "update fails", | ||
| expConditionPassed: false, | ||
| }, | ||
| { | ||
| getReturns: nil, | ||
| updateReturns: nil, | ||
| name: "nothing fails", | ||
| expConditionPassed: true, | ||
| }, | ||
| } | ||
|
|
||
| fakeStatusUpdater := &statusfakes.FakeK8sUpdater{} | ||
| fakeGetter := &controllerfakes.FakeGetter{} | ||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| g := NewWithT(t) | ||
| fakeStatusUpdater.UpdateReturns(test.updateReturns) | ||
| fakeGetter.GetReturns(test.getReturns) | ||
| f := status.NewRetryUpdateFunc( | ||
| fakeGetter, | ||
| fakeStatusUpdater, | ||
| types.NamespacedName{}, | ||
| &v1beta1.GatewayClass{}, | ||
| zap.New(), | ||
| func(client.Object) {}) | ||
| conditionPassed, err := f(context.Background()) | ||
|
|
||
| // For now, the function should always return nil | ||
| g.Expect(err).ToNot(HaveOccurred()) | ||
| g.Expect(conditionPassed).To(Equal(test.expConditionPassed)) | ||
| }) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.