Documentation ¶
Index ¶
- func DefaultErrorRetryChecker(err error) (bool, error)
- func DefaultResponseRetryChecker(resp *Response) (bool, error)
- func IsStatusOK(resp *Response) (bool, error)
- func ResolveEndpoint(ctx context.Context, kubeClientset kubernetes.Interface, domain string, ...) (string, func(string) string, error)
- type ErrorRetryChecker
- type RequestOption
- type Response
- type ResponseChecker
- type ResponseRetryChecker
- type SpoofingClient
- func (sc *SpoofingClient) Check(req *http.Request, inState ResponseChecker, checkers ...interface{}) (*Response, error)
- func (sc *SpoofingClient) CheckEndpointState(ctx context.Context, url *url.URL, inState ResponseChecker, desc string, ...) (*Response, error)
- func (sc *SpoofingClient) Do(req *http.Request, errorRetryCheckers ...interface{}) (*Response, error)
- func (sc *SpoofingClient) Poll(req *http.Request, inState ResponseChecker, checkers ...interface{}) (*Response, error)
- func (sc *SpoofingClient) WaitForEndpointState(ctx context.Context, url *url.URL, inState ResponseChecker, desc string, ...) (*Response, error)
- type TransportOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultErrorRetryChecker ¶
DefaultErrorRetryChecker implements the defaults for retrying on error.
func DefaultResponseRetryChecker ¶
DefaultResponseRetryChecker implements the defaults for retrying on response.
func IsStatusOK ¶
IsStatusOK checks that the response code is a 200.
func ResolveEndpoint ¶
func ResolveEndpoint(ctx context.Context, kubeClientset kubernetes.Interface, domain string, resolvable bool, endpointOverride string) (string, func(string) string, error)
ResolveEndpoint resolves the endpoint address considering whether the domain is resolvable and taking into account whether the user overrode the endpoint address externally
Types ¶
type ErrorRetryChecker ¶
ErrorRetryChecker is used to determine if an error should be retried or not. If an error should be retried, it should return true and the wrapped error to explain why to retry.
type RequestOption ¶
RequestOption enables configuration of requests when polling for endpoint states.
func WithHeader ¶
func WithHeader(header http.Header) RequestOption
WithHeader will add the provided headers to the request.
type Response ¶
Response is a stripped down subset of http.Response. The is primarily useful for ResponseCheckers to inspect the response body without consuming it. Notably, Body is a byte slice instead of an io.ReadCloser.
type ResponseChecker ¶
ResponseChecker is used to determine when SpoofingClient.Poll is done polling. This allows you to predicate wait.PollImmediate on the request's http.Response.
See the apimachinery wait package: https://github.com/kubernetes/apimachinery/blob/cf7ae2f57dabc02a3d215f15ca61ae1446f3be8f/pkg/util/wait/wait.go#L172
func IsOneOfStatusCodes ¶
func IsOneOfStatusCodes(codes ...int) ResponseChecker
IsOneOfStatusCodes checks that the response code is equal to the given one.
func MatchesAllBodies ¶
func MatchesAllBodies(all ...string) ResponseChecker
MatchesAllBodies checks that the *first* response body matches the "expected" body, otherwise failing.
func MatchesAllOf ¶
func MatchesAllOf(checkers ...ResponseChecker) ResponseChecker
MatchesAllOf combines multiple ResponseCheckers to one ResponseChecker with a logical AND. The checkers are executed in order. The first function to trigger an error or a retry will short-circuit the other functions (they will not be executed).
This is useful for combining a body with a status check like: MatchesAllOf(IsStatusOK, MatchesBody("test"))
The MatchesBody check will only be executed after the IsStatusOK has passed.
func MatchesBody ¶
func MatchesBody(expected string) ResponseChecker
MatchesBody checks that the *first* response body matches the "expected" body, otherwise failing.
type ResponseRetryChecker ¶
ResponseRetryChecker is used to determine if a response should be retried or not. If a response should be retried, it should return true and an error to explain why to retry.
This is distinct from ResponseChecker in that it shall be used to retry responses, where the HTTP request was technically successful (it returned something) but indicates an error (e.g. the overload page of a loadbalancer).
type SpoofingClient ¶
type SpoofingClient struct { Client *http.Client RequestInterval time.Duration RequestTimeout time.Duration Logf logging.FormatLogger }
SpoofingClient is a minimal HTTP client wrapper that spoofs the domain of requests for non-resolvable domains.
func New ¶
func New( ctx context.Context, kubeClientset kubernetes.Interface, logf logging.FormatLogger, domain string, resolvable bool, endpointOverride string, requestInterval, requestTimeout time.Duration, opts ...TransportOption) (*SpoofingClient, error)
New returns a SpoofingClient that rewrites requests if the target domain is not `resolvable`. It does this by looking up the ingress at construction time, so reusing a client will not follow the ingress if it moves (or if there are multiple ingresses).
If that's a problem, see test/request.go#WaitForEndpointState for oneshot spoofing.
func (*SpoofingClient) Check ¶
func (sc *SpoofingClient) Check(req *http.Request, inState ResponseChecker, checkers ...interface{}) (*Response, error)
func (*SpoofingClient) CheckEndpointState ¶
func (sc *SpoofingClient) CheckEndpointState( ctx context.Context, url *url.URL, inState ResponseChecker, desc string, opts ...RequestOption) (*Response, error)
func (*SpoofingClient) Do ¶
func (sc *SpoofingClient) Do(req *http.Request, errorRetryCheckers ...interface{}) (*Response, error)
Do dispatches to the underlying http.Client.Do, spoofing domains as needed and transforming the http.Response into a spoof.Response. Each response is augmented with "ZipkinTraceID" header that identifies the zipkin trace corresponding to the request.
func (*SpoofingClient) Poll ¶
func (sc *SpoofingClient) Poll(req *http.Request, inState ResponseChecker, checkers ...interface{}) (*Response, error)
Poll executes an http request until it satisfies the inState condition or, if there's an error, none of the error retry checkers permit a retry. If no retry checkers are specified `DefaultErrorRetryChecker` will be used.
func (*SpoofingClient) WaitForEndpointState ¶
func (sc *SpoofingClient) WaitForEndpointState( ctx context.Context, url *url.URL, inState ResponseChecker, desc string, opts ...RequestOption) (*Response, error)