-
Notifications
You must be signed in to change notification settings - Fork 6
Adds WatchList to enable testing with WatchList/StreamingList #148
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 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1b8959c
Adds StaleWatchList and QuorumWatchList to enable testing with WatchL…
6c19f7d
Remove unused import.
6a2701a
Fix linter errors
1cb7622
Modifies based on feedback.
84eadf6
Modifies based on review. Moves StreamNoError check back to scheduler.
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 |
---|---|---|
|
@@ -29,3 +29,6 @@ tmp/ | |
|
||
#.txt files which contain response stats | ||
*.txt | ||
|
||
# VSCode settings | ||
.vscode/ |
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
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,78 @@ | ||
package request | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"net/url" | ||
"time" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
type Requester interface { | ||
Method() string | ||
URL() *url.URL | ||
Timeout(time.Duration) | ||
Do(context.Context) (bytes int64, err error) | ||
} | ||
|
||
type BaseRequester struct { | ||
method string | ||
req *rest.Request | ||
} | ||
|
||
func (reqr *BaseRequester) Method() string { | ||
return reqr.method | ||
} | ||
|
||
func (reqr *BaseRequester) URL() *url.URL { | ||
return reqr.req.URL() | ||
} | ||
|
||
func (reqr *BaseRequester) Timeout(timeout time.Duration) { | ||
reqr.req.Timeout(timeout) | ||
} | ||
|
||
type DiscardRequester struct { | ||
BaseRequester | ||
} | ||
|
||
func (reqr *DiscardRequester) Do(ctx context.Context) (bytes int64, err error) { | ||
respBody, err := reqr.req.Stream(ctx) | ||
bytes = 0 | ||
if err == nil { | ||
defer respBody.Close() | ||
bytes, err = io.Copy(io.Discard, respBody) | ||
// Based on HTTP2 Spec Section 8.1 [1], | ||
// | ||
// A server can send a complete response prior to the client | ||
// sending an entire request if the response does not depend | ||
// on any portion of the request that has not been sent and | ||
// received. When this is true, a server MAY request that the | ||
// client abort transmission of a request without error by | ||
// sending a RST_STREAM with an error code of NO_ERROR after | ||
// sending a complete response (i.e., a frame with the END_STREAM | ||
// flag). Clients MUST NOT discard responses as a result of receiving | ||
// such a RST_STREAM, though clients can always discard responses | ||
// at their discretion for other reasons. | ||
// | ||
// We should mark NO_ERROR as nil here. | ||
// | ||
// [1]: https://httpwg.org/specs/rfc7540.html#HttpSequence | ||
if err != nil && isHTTP2StreamNoError(err) { | ||
err = nil | ||
} | ||
} | ||
return bytes, err | ||
} | ||
|
||
type WatchListRequester struct { | ||
BaseRequester | ||
} | ||
|
||
func (reqr *WatchListRequester) Do(ctx context.Context) (bytes int64, err error) { | ||
result := &unstructured.UnstructuredList{} | ||
err = reqr.req.WatchList(ctx).Into(result) | ||
return 0, err | ||
} |
Oops, something went wrong.
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.