spoof

package
Version: v0.0.0-...-87426b5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// RequestTimeout is the default timeout for the polling requests.
	RequestTimeout = 5 * time.Minute
)

Variables

This section is empty.

Functions

func DefaultErrorRetryChecker

func DefaultErrorRetryChecker(err error) (bool, error)

DefaultErrorRetryChecker implements the defaults for retrying on error.

func ResolveEndpoint

func ResolveEndpoint(kubeClientset *kubernetes.Clientset, domain string, resolvable bool, endpointOverride 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

type ErrorRetryChecker func(e error) (retry bool, err error)

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 Interface

type Interface interface {
	Do(*http.Request) (*Response, error)
	Poll(*http.Request, ResponseChecker, ...ErrorRetryChecker) (*Response, error)
}

Interface defines the actions that can be performed by the spoofing client.

type Response

type Response struct {
	Status     string
	StatusCode int
	Header     http.Header
	Body       []byte
}

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.

func (*Response) String

func (r *Response) String() string

type ResponseChecker

type ResponseChecker func(resp *Response) (done bool, err error)

ResponseChecker is used to determine when SpoofinClient.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

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(
	kubeClientset *kubernetes.Clientset,
	logf logging.FormatLogger,
	domain string,
	resolvable bool,
	endpointOverride string,
	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) Do

func (sc *SpoofingClient) Do(req *http.Request) (*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, errorRetryCheckers ...ErrorRetryChecker) (*Response, error)

Poll executes an http request until it satisfies the inState condition or encounters an error.

type TransportOption

type TransportOption func(transport *http.Transport) *http.Transport

TransportOption allows callers to customize the http.Transport used by a SpoofingClient

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto