fleet

package
v0.0.0-...-a216e23 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2016 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Overview

Package fleet implements a fleet client providing basic operations against a fleet endpoint through fleet's HTTP API. Higher level scheduling and management should be built on top of that.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsIPNotFound

func IsIPNotFound(err error) bool

IsIPNotFound checks whether the given error indicates the problem of an IP not being found or not. In case you want to lookup the IP of a unit that cannot be found on any machine, an error that you can identify using this method is returned.

func IsInvalidEndpoint

func IsInvalidEndpoint(err error) bool

IsInvalidEndpoint checks whether the given error indicates a invalid endpoint to the operation that was performed.

func IsInvalidUnitStatus

func IsInvalidUnitStatus(err error) bool

IsInvalidUnitStatus checks whether the given error indicates the problem of an unexpected unit status response. In case you want to lookup the state of a unit that cannot be found on any machine or exists multiple times (what should never happen), an error that you can identify using this method is returned.

func IsUnitNotFound

func IsUnitNotFound(err error) bool

IsUnitNotFound checks whether the given error indicates the problem of an unit not being found or not. In case you want to lookup the state of a unit that cannot be found on any machine, an error that you can identify using this method is returned.

Types

type Config

type Config struct {
	Client    *http.Client
	Endpoint  url.URL
	SSHTunnel SSHTunnel

	// Logger provides an initialised logger.
	Logger logging.Logger
}

Config provides all necessary and injectable configurations for a new fleet client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig provides a set of configurations with default values by best effort.

type DummyConfig

type DummyConfig struct {
	Logger logging.Logger
}

DummyConfig holds configuration for the DummyFleet struct.

func DefaultDummyConfig

func DefaultDummyConfig() DummyConfig

DefaultDummyConfig returns a best-effort configuration for the DummyFleet struct.

type DummyFleet

type DummyFleet struct {
	Config DummyConfig
	Units  map[string]UnitStatus
	Mutex  sync.Mutex
}

DummyFleet is an implementation of the Fleet interface, that is primarily intended to be used for testing.

func NewDummyFleet

func NewDummyFleet(DummyConfig) *DummyFleet

NewDummyFleet returns a DummyFleet, given a DummyConfig.

func (*DummyFleet) Destroy

func (f *DummyFleet) Destroy(ctx context.Context, name string) error

Destroy remove the UnitStatus from the internal store.

func (*DummyFleet) GetStatus

func (f *DummyFleet) GetStatus(ctx context.Context, name string) (UnitStatus, error)

GetStatus returns the UnitStatus for the given name.

func (*DummyFleet) GetStatusWithMatcher

func (f *DummyFleet) GetStatusWithMatcher(m func(string) bool) ([]UnitStatus, error)

GetStatusWithMatcher returns all UnitStatus that match.

func (*DummyFleet) Start

func (f *DummyFleet) Start(ctx context.Context, name string) error

Start sets the Current and Desired state of the stored UnitStatus to unitStateLaunched.

func (*DummyFleet) Stop

func (f *DummyFleet) Stop(ctx context.Context, name string) error

Stop sets the Current and Desired state of the stored UnitStatus to unitStateLoaded.

func (*DummyFleet) Submit

func (f *DummyFleet) Submit(ctx context.Context, name, content string) error

Submit creates a UnitStatus, and stores it.

type Fleet

type Fleet interface {
	// Submit schedules a unit on the configured fleet cluster. This is done by
	// setting the unit's target state to loaded.
	Submit(ctx context.Context, name, content string) error

	// Start starts a unit on the configured fleet cluster. This is done by
	// setting the unit's target state to launched.
	Start(ctx context.Context, name string) error

	// Stop stops a unit on the configured fleet cluster. This is done by
	// setting the unit's target state to loaded.
	Stop(ctx context.Context, name string) error

	// Destroy delets a unit on the configured fleet cluster. This is done by
	// setting the unit's target state to inactive.
	Destroy(ctx context.Context, name string) error

	// GetStatus fetches the current status of a unit. If the unit cannot be
	// found, an error that you can identify using IsUnitNotFound is returned.
	GetStatus(ctx context.Context, name string) (UnitStatus, error)

	// GetStatusWithMatcher returns a []UnitStatus, with an element for
	// each unit where the given matcher returns true.
	GetStatusWithMatcher(func(string) bool) ([]UnitStatus, error)
}

Fleet defines the interface a fleet client needs to implement to provide basic operations against a fleet endpoint.

func NewFleet

func NewFleet(config Config) (Fleet, error)

NewFleet creates a new Fleet that is configured with the given settings.

newConfig := fleet.DefaultConfig()
newConfig.Endpoint = myCustomEndpoint
newFleet := fleet.NewFleet(newConfig)

type MachineStatus

type MachineStatus struct {
	// ID represents the machines fleet agent ID where the related unit is
	// running on.
	ID string

	// IP represents the machines IP where the related unit is running on.
	IP net.IP

	// SystemdActive represents the unit's systemd active state.
	SystemdActive string

	// SystemdSub represents the unit's systemd sub state.
	SystemdSub string

	// UnitHash represents a unique token to identify the content of the unitfile.
	UnitHash string
}

MachineStatus represents a unit's status scheduled on a certain machine.

type SSHTunnel

type SSHTunnel interface {
	http.RoundTripper

	// IsActive determines whether the tunnel should be used. This is decided by
	// the given tunnel configuration. In case this is empty, the SSH tunnel is
	// not active.
	IsActive() bool
}

SSHTunnel provides a synchronized wrapper around http.RoundTripper for safe use of tunneled ssh connections.

func NewSSHTunnel

func NewSSHTunnel(config SSHTunnelConfig) (SSHTunnel, error)

NewSSHTunnel creates a new SSH tunnel that is configured with the given settings.

type SSHTunnelConfig

type SSHTunnelConfig struct {
	Endpoint              url.URL
	KnownHostsFile        string
	Logger                logging.Logger
	StrictHostKeyChecking bool
	Tunnel                string
	Timeout               time.Duration
	Username              string
}

SSHTunnelConfig contains the information needed to create a new ssh tunnel.

func DefaultSSHTunnelConfig

func DefaultSSHTunnelConfig() SSHTunnelConfig

type UnitStatus

type UnitStatus struct {
	// Current represents the current status within the fleet cluster.
	Current string

	// Desired represents the desired status within the fleet cluster.
	Desired string

	// Machine represents the status within a machine. For normal units that are
	// scheduled on only one machine there will be one MachineStatus returned.
	// For global units that are scheduled on multiple machines there will be
	// multiple MachineStatus returned. If a unit is not yet scheduled to any
	// machine, this will be empty.
	Machine []MachineStatus

	// Name represents the unit file name.
	Name string

	// Slice represents the slice ID. E.g. 1, or foo, or 5., etc..
	SliceID string
}

UnitStatus represents the status of a unit.

Jump to

Keyboard shortcuts

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