Back to godoc.org

Package sidecar

v0.5.3
Latest Go to latest

The latest major version is .

Published: Aug 6, 2020 | Licenses: Apache-2.0 , MIT | Module: github.com/testground/testground

Index

Constants

const (
	EnvRedisHost    = "REDIS_HOST"
	EnvInfluxdbHost = "INFLUXDB_HOST"
)

Variables

var PublicAddr = net.ParseIP("1.1.1.1")

PublicAddr points to an IP address in the public range. It helps us discover the IP address of the gateway (i.e. the Docker host) on the control network (the learned route will be via the control network because, at this point, the only network that's attached to the container is the control network).

Sidecar doesn't whitelist traffic to public addresses, but it special-cases traffic between the container and the host, so that pprof, metrics and other ports can be exposed to the Docker host.

func GetRunners

func GetRunners() []string

GetRunners lists the available sidecar environments.

func Run

func Run(runnerName string) error

Run runs the sidecar in the given runner environment.

type AllowedService

type AllowedService struct {
	Name string
	IP   net.IP
}

type DockerNetwork

type DockerNetwork struct {
	// contains filtered or unexported fields
}

func (*DockerNetwork) Close

func (dn *DockerNetwork) Close() error

func (*DockerNetwork) ConfigureNetwork

func (dn *DockerNetwork) ConfigureNetwork(ctx context.Context, cfg *sdknw.Config) error

func (*DockerNetwork) ListActive

func (dn *DockerNetwork) ListActive() []string

func (*DockerNetwork) ListAvailable

func (dn *DockerNetwork) ListAvailable() []string

type DockerReactor

type DockerReactor struct {
	gosync.Mutex
	// contains filtered or unexported fields
}

func (*DockerReactor) Close

func (d *DockerReactor) Close() error

func (*DockerReactor) Handle

func (d *DockerReactor) Handle(globalctx context.Context, handler InstanceHandler) error

func (*DockerReactor) ResolveServices

func (d *DockerReactor) ResolveServices(runid string)

type Instance

type Instance struct {
	logging.Logging

	Hostname string
	Client   sync.Client
	RunEnv   *runtime.RunEnv
	Network  Network
}

Instance is a test instance as seen by the sidecar.

func NewInstance

func NewInstance(client sync.Client, runenv *runtime.RunEnv, hostname string, network Network) (*Instance, error)

NewInstance constructs a new test instance handle.

func (*Instance) Close

func (inst *Instance) Close() error

Close closes the instance. It should not be used after closing.

type InstanceHandler

type InstanceHandler func(context.Context, *Instance) error

type K8sNetwork

type K8sNetwork struct {
	// contains filtered or unexported fields
}

func (*K8sNetwork) Close

func (n *K8sNetwork) Close() error

func (*K8sNetwork) ConfigureNetwork

func (n *K8sNetwork) ConfigureNetwork(ctx context.Context, cfg *network.Config) error

func (*K8sNetwork) ListActive

func (n *K8sNetwork) ListActive() []string

type K8sReactor

type K8sReactor struct {
	gosync.Mutex
	// contains filtered or unexported fields
}

func (*K8sReactor) Close

func (d *K8sReactor) Close() error

func (*K8sReactor) Handle

func (d *K8sReactor) Handle(ctx context.Context, handler InstanceHandler) error

func (*K8sReactor) ResolveServices

func (d *K8sReactor) ResolveServices(runid string)

type MockNetwork

type MockNetwork struct {
	Active     map[string]*network.Config // A map of *active* networks.
	Configured []*network.Config          // A list of all the configurations we've seen
	Closed     bool
	L          gosync.Locker
}

Network

func NewMockNetwork

func NewMockNetwork() *MockNetwork

func (*MockNetwork) Close

func (m *MockNetwork) Close() error

func (*MockNetwork) ConfigureNetwork

func (m *MockNetwork) ConfigureNetwork(ctx context.Context, cfg *network.Config) error

func (*MockNetwork) ListActive

func (m *MockNetwork) ListActive() []string

type MockReactor

type MockReactor struct {
	RunParams *runtime.RunParams
	RunEnv    *runtime.RunEnv
	Network   *MockNetwork
	Client    sync.Client
	Hostname  string
}

Reactor

func (*MockReactor) Close

func (*MockReactor) Close() error

func (*MockReactor) Handle

func (r *MockReactor) Handle(ctx context.Context, handler InstanceHandler) error
type NetlinkLink struct {
	netlink.Link
	// contains filtered or unexported fields
}

NetlinkLink abstracts operations over a network interface.

NetlinkLink shapes the egress traffic on the link using TC. To do so, it configures the following TC tree:

[________HTB Qdisc_________] - root
   0 |      1 |     n | ...  - queue; 0 is the default.
[HTB Class]                  - bandwidth (rate limiting)
     |
[Netem Qdisc]                - latency, jitter, etc. (per-packet attributes)

At the moment, only one queue is supported. When support for multiple subnets is added, additional classes/queues will be added per-subnet.

NetlinkLink also supports setting the network device up/down and changing the IP address.

NOTE: Not all run environments will react well to the IP address changing. Don't use this feature with docker.

func NewNetlinkLink(handle *netlink.Handle, link netlink.Link) (*NetlinkLink, error)

NewNetlinkLink constructs a new netlink link handle.

func (*NetlinkLink) AddRules

func (l *NetlinkLink) AddRules(rules []network.LinkRule) error

TODO(cory) actually process the shape per network. For now, this simply adds a route based on the Filter

func (*NetlinkLink) AddrAdd

func (l *NetlinkLink) AddrAdd(ip *net.IPNet) error

AddrAdd adds an address to the link.

NOTE: This won't work in docker; use docker connect/disconnect.

func (*NetlinkLink) AddrDel

func (l *NetlinkLink) AddrDel(ip *net.IPNet) error

AddrDel removes an address from the link.

NOTE: This won't work in docker; use docker connect/disconnect.

func (*NetlinkLink) Down

func (l *NetlinkLink) Down() error

Down takes the link down.

func (*NetlinkLink) ListV4

func (l *NetlinkLink) ListV4() ([]*net.IPNet, error)

ListV4 lists all IPv4 addresses associated with the link.

func (*NetlinkLink) ListV6

func (l *NetlinkLink) ListV6() ([]*net.IPNet, error)

ListV6 lists all IPv6 addresses associated with the link.

func (*NetlinkLink) Shape

func (l *NetlinkLink) Shape(shape network.LinkShape) error

Shape applies the link "shape" to the link, setting the bandwidth, latency, jitter, etc.

func (*NetlinkLink) Up

func (l *NetlinkLink) Up() error

Up sets the link up.

type Network

type Network interface {
	io.Closer

	ConfigureNetwork(ctx context.Context, cfg *network.Config) error
	ListActive() []string
}

Network is a test instance's network, as seen by the sidecar.

Sidecar runners must implement this interface.

type Reactor

type Reactor interface {
	io.Closer

	Handle(context.Context, InstanceHandler) error
}

func NewDockerReactor

func NewDockerReactor() (Reactor, error)

func NewK8sReactor

func NewK8sReactor() (Reactor, error)

func NewMockReactor

func NewMockReactor() (Reactor, error)

A MockReactor with the information for a single instance. A typicial reactor watches the docker socket for containers. This one creates enough information for a single instace, or a single reaction for testing purposes. A mock network and inmem SDK client are instantiated here as well. To use, instantiate the NewMockReactor and run Handle(). Any messages passed through the inmem SDK client are handled as though the come from the mocked instance.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier