spoof

package
v0.0.0-...-628bc19 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetServiceEndpoint

func GetServiceEndpoint(kubeClientset *kubernetes.Clientset) (*string, error)

GetServiceEndpoint gets the endpoint IP or hostname to use for the service

Types

type Interface

type Interface interface {
	Do(*http.Request) (*Response, error)
	Poll(*http.Request, ResponseChecker) (*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.

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
	// contains filtered or unexported fields
}

SpoofingClient is a minimal http client wrapper that spoofs the domain of requests for non-resolvable domains.

func New

func New(kubeClientset *kubernetes.Clientset, logger *logging.BaseLogger, domain string, resolvable bool) (*SpoofingClient, error)

New returns a SpoofingClient that rewrites requests if the target domain is not `resolveable`. 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) LogZipkinTrace

func (sc *SpoofingClient) LogZipkinTrace(traceID string) error

LogZipkinTrace provides support to log Zipkin Trace for param: traceID

func (*SpoofingClient) Poll

func (sc *SpoofingClient) Poll(req *http.Request, inState ResponseChecker) (*Response, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL