client

package
v2.0.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2018 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultEtcdPrefix    = "/romana"
	DefaultEtcdEndpoints = "localhost:2379"

	PoliciesPrefix  = "/policies"
	RomanaVIPPrefix = "/romanavip"
)
View Source
const (
	DefaultAgentPort = 9604
	DefaultBlockMask = 29
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Atomizable

type Atomizable interface {
	GetPrevKVPair() *libkvStore.KVPair
	SetPrevKVPair(*libkvStore.KVPair)
}

Atomizable defines an interface on which it is possible to execute Atomic operations from the point of view of KVStore.

type Block

type Block struct {
	CIDR     CIDR           `json:"cidr"`
	Pool     *idring.IDRing `json:"pool"`
	Revision int            `json:"revision"`
}

Block represents a CIDR that is owned by an Owner, and thus can have addresses allocated in it it.

func (Block) ListAllocatedAddresses

func (b Block) ListAllocatedAddresses() []string

ListAllocatedAddresses lists all allocated adresses in the block

func (Block) ListAvailableAddresses

func (b Block) ListAvailableAddresses() []string

ListAvailableAddresses lists all available adresses in the block

func (Block) String

func (b Block) String() string

type BlocksCallback

type BlocksCallback func(api.IPAMBlocksResponse)

type CIDR

type CIDR struct {
	// Represents the IPNet object corresponding to this CIDR.
	*net.IPNet
	StartIP    net.IP `json:"start_ip"`
	StartIPInt uint64 `json:"start_ip_int"`
	EndIP      net.IP `json:"end_ip"`
	EndIPInt   uint64 `json:"end_ip_int"`
}

CIDR represents a CIDR (net.IPNet, effectively) with some extra functionality for convenience.

func NewCIDR

func NewCIDR(s string) (CIDR, error)

NewCIDR creates a CIDR object from a string.

func (CIDR) Contains

func (c CIDR) Contains(c2 CIDR) bool

Contains returns true if this CIDR fully contains (is equivalent to or a superset of) the provided CIDR.

func (CIDR) ContainsIP

func (c CIDR) ContainsIP(ip net.IP) bool

func (CIDR) DebugString

func (c CIDR) DebugString() string

func (CIDR) MarshalText

func (c CIDR) MarshalText() ([]byte, error)

func (CIDR) String

func (c CIDR) String() string

func (*CIDR) UnmarshalText

func (cidr *CIDR) UnmarshalText(data []byte) error

type Client

type Client struct {
	Store *Store

	IPAM *IPAM
	// contains filtered or unexported fields
}

func NewClient

func NewClient(config *common.Config) (*Client, error)

NewClient creates a new Client object based on provided config

func (*Client) AddPolicy

func (c *Client) AddPolicy(policy api.Policy) error

AddPolicy adds a policy (or modifies it if policy with such ID already exists)

func (*Client) AddRomanaVIP

func (c *Client) AddRomanaVIP(key string, e api.ExposedIPSpec) error

AddRomanaVIP adds romana VIP information for service to the store.

func (*Client) DeletePolicy

func (c *Client) DeletePolicy(id string) (bool, error)

DeletePolicy attempts to delete policy. If the policy does not exist, false is returned, instead of an error.

func (*Client) DeleteRomanaVIP

func (c *Client) DeleteRomanaVIP(key string) error

DeleteRomanaVIP deletes romana VIP information for service from store.

func (*Client) GetPolicy

func (c *Client) GetPolicy(id string) (api.Policy, error)

GetPolicy attempts to retrieve a policy.

func (*Client) GetTopology

func (c *Client) GetTopology() (interface{}, error)

GetTopology returns the representation of latest topology in store.

func (*Client) ListHosts

func (c *Client) ListHosts() api.HostList

func (*Client) ListPolicies

func (c *Client) ListPolicies() ([]api.Policy, error)

func (*Client) ListRomanaVIPs

func (c *Client) ListRomanaVIPs() (map[string]api.ExposedIPSpec, error)

ListRomanaVIPs lists romana VIP information for services in the store.

func (*Client) ListTenants

func (c *Client) ListTenants() []api.Tenant

ListTenants is a temporary method to satisfy current agent cache.

func (*Client) WatchBlocks

func (c *Client) WatchBlocks(stopCh <-chan struct{}) (<-chan api.IPAMBlocksResponse, error)

WatchBlocks is similar to Watch of libkv store, but specific to watching for blocks.

func (*Client) WatchBlocksWithCallback

func (c *Client) WatchBlocksWithCallback(cb BlocksCallback) error

func (*Client) WatchHosts

func (c *Client) WatchHosts(stopCh <-chan struct{}) (<-chan api.HostList, error)

WatchHosts is similar to Watch of libkv store, but specific to watching for host list.

func (*Client) WatchHostsWithCallback

func (c *Client) WatchHostsWithCallback(cb HostListCallback) error

type Group

type Group struct {
	Name   string   `json:"name"`
	Hosts  []*Host  `json:"hosts"`
	Groups []*Group `json:"groups"`
	// CIDR which is to be subdivided among hosts or sub-groups of this group.
	CIDR CIDR `json:"cidr"`

	BlockToOwner  map[int]string   `json:"block_to_owner"`
	OwnerToBlocks map[string][]int `json:"owner_to_block"`

	BlockToHost map[int]string `json:"block_to_host"`

	Blocks         []*Block          `json:"blocks"`
	ReusableBlocks []int             `json:"reusable_blocks"`
	Assignment     map[string]string `json:"assignment"`
	Routing        string            `json:"routing"`

	Dummy bool `json:"dummy"`
	// contains filtered or unexported fields
}

Group holds either a list of hosts at a given level; it cannot be a mix. In other words, the invariant is:

  • Either Hosts or Groups field is nil

func (*Group) GetBlocks

func (hg *Group) GetBlocks() []api.IPAMBlockResponse

GetBlocks returns list of blocks for the provided group including extra information about a block (host, tenant/segment, etc.) - corresponding to api.IPAMBlockResponse.

func (*Group) ListBlocks

func (hg *Group) ListBlocks() []*Block

func (*Group) ListHosts

func (hg *Group) ListHosts() []*Host

listHosts lists all hosts in this group.

func (*Group) String

func (hg *Group) String() string

type Host

type Host struct {
	Name      string                 `json:"name"`
	IP        net.IP                 `json:"ip"`
	AgentPort uint                   `json:"agent_port"`
	Tags      map[string]string      `json:"tags"`
	K8SInfo   map[string]interface{} `json:"k8s_info"`
	// contains filtered or unexported fields
}

Host represents a host in Romana topology.

func (Host) String

func (h Host) String() string

type HostListCallback

type HostListCallback func(api.HostList)

type IPAM

type IPAM struct {
	Networks map[string]*Network `json:"networks"`

	// Revision of the state of allocations
	AllocationRevision int
	// Revision of topology information (only changes if hosts are added)
	TopologyRevision int

	// Map of address name to IP
	AddressNameToIP map[string]net.IP `json:"address_name_to_ip"`

	TenantToNetwork map[string][]string `json:"tenant_to_network"`
	// contains filtered or unexported fields
}

func NewIPAM

func NewIPAM(saver Saver, locker Locker) (*IPAM, error)

NewIPAM creates a new IPAM object. If locker is not provided, mutexLocker is used. If an HA deployment is expected, then the locker based on some external resource, e.g., a DB, should be provided.

func (*IPAM) AddHost

func (ipam *IPAM) AddHost(host api.Host) error

AddHost adds host to the current IPAM.

func (*IPAM) AllocateIP

func (ipam *IPAM) AllocateIP(addressName string, host string, tenant string, segment string) (net.IP, error)

AllocateIP allocates an IP for the provided tenant and segment, and associates the provided name with it. That name can afterwards be used for deallocation. It will first attempt to allocate an IP from an existing block, and if all are exhausted, will try to allocate a new block for this tenant/segment pair. Will return nil as IP if the entire network is exhausted.

func (*IPAM) BlackOut

func (ipam *IPAM) BlackOut(cidrStr string) error

BlackOut removes a CIDR from consideration. It is an error if CIDR is within any of the exising allocated blocks. Fragmentation may result if CIDRs smaller than ipam. Blocks are blacked out and then un-blacked out.

func (*IPAM) DeallocateIP

func (ipam *IPAM) DeallocateIP(addressName string) error

DeallocateIP will deallocate the provided IP (returning an error if it never was allocated in the first place).

func (*IPAM) GetGroupsForNetwork

func (ipam *IPAM) GetGroupsForNetwork(netName string) *Group

GetGroupsForNetwork retrieves Group for the network with the provided name, or nil if not found.

func (*IPAM) GetPrevKVPair

func (ipam *IPAM) GetPrevKVPair() *libkvStore.KVPair

func (*IPAM) ListAllBlocks

func (ipam *IPAM) ListAllBlocks() *api.IPAMBlocksResponse

func (*IPAM) ListHosts

func (ipam *IPAM) ListHosts() api.HostList

func (*IPAM) ListNetworkBlocks

func (ipam *IPAM) ListNetworkBlocks(netName string) *api.IPAMBlocksResponse

func (*IPAM) RemoveHost

func (ipam *IPAM) RemoveHost(host api.Host) error

func (*IPAM) SetPrevKVPair

func (ipam *IPAM) SetPrevKVPair(kvp *libkvStore.KVPair)

func (*IPAM) UnBlackOut

func (ipam *IPAM) UnBlackOut(cidrStr string) error

UnBlackOut adds CIDR backs into the pool for consideration.

func (*IPAM) UpdateHostK8SInfo

func (ipam *IPAM) UpdateHostK8SInfo(host api.Host) error

func (*IPAM) UpdateHostLabels

func (ipam *IPAM) UpdateHostLabels(host api.Host) error

UpdateHostLabels updates host's labels. Note that this does not check the new labels against label assignment and whether that breaks anything; that is a TODO

func (*IPAM) UpdateTopology

func (ipam *IPAM) UpdateTopology(req api.TopologyUpdateRequest, lockAndSave bool) error

UpdateTopology updates the entire topology, returning an error if the current topology has IPs that cannot be allocated in the new one.

type Loader

type Loader func(ipam *IPAM, ch <-chan struct{}) error

Loader is a function for loading IPAM data from a store

type Locker

type Locker interface {
	Lock() (<-chan struct{}, error)
	Unlock()
	GetOwner() uint64
}

Locker implements an interface for locking and unlocking. sync.Locker was not good for our purpose it does not allow for returning an error on lock. libkv's Locker is too libkv-specific and we do not need a stop channel really; and since the use case is to defer Unlock(), no need for it to return an error

type Network

type Network struct {
	Name string `json:"name"`

	// CIDR of the network (likely 10/8).
	CIDR CIDR `json:"cidr"`

	// Size of tenant/segment block to allocate, in bits as mask
	// (specify 32 for size 1, e.g.)
	BlockMask uint `json:"block_mask"`

	BlackedOut []CIDR `json:"blacked_out"`

	Group *Group `json:"host_groups"`

	Revison int `json:"revision"`
	// contains filtered or unexported fields
}

Network is the main structure managing allocation of IP addresses in the provided CIDR.

type Saver

type Saver func(ipam *IPAM, ch <-chan struct{}) error

Saver defines a function that can save the state of the BlockIPAM to a persistent store. Saver is allowed to assume the BlockIPAM can be successfully marshaled to JSON.

type Store

type Store struct {
	libkvStore.Store
	// contains filtered or unexported fields
}

Store is a structure storing information specific to KV-based implementation of Store.

func NewStore

func NewStore(etcdEndpoints []string, prefix string) (*Store, error)

func (*Store) AtomicPut

func (s *Store) AtomicPut(key string, value Atomizable) error

func (*Store) Delete

func (s *Store) Delete(key string) (bool, error)

Delete wrapes Delete operation, returning: - true if deletion succeede - false and no error if deletion failed because key was not found - false and error if another error occurred

func (*Store) Exists

func (s *Store) Exists(key string) (bool, error)

func (*Store) Get

func (s *Store) Get(key string) (*libkvStore.KVPair, error)

func (*Store) GetBool

func (s *Store) GetBool(key string, defaultValue bool) (bool, error)

func (*Store) GetInt

func (s *Store) GetInt(key string, defaultValue int) (int, error)

func (*Store) GetObject

func (s *Store) GetObject(key string) (*libkvStore.KVPair, error)

func (*Store) GetString

func (s *Store) GetString(key string, defaultValue string) (string, error)

func (*Store) ListObjects

func (s *Store) ListObjects(key string) ([]*libkvStore.KVPair, error)

func (*Store) NewLocker

func (store *Store) NewLocker(name string) (Locker, error)

func (*Store) PutObject

func (s *Store) PutObject(key string, value []byte) error

func (*Store) ReconnectingWatch

func (s *Store) ReconnectingWatch(key string, stopCh <-chan struct{}) (<-chan *libkvStore.KVPair, error)

ReconnectingWatch wraps libkv Watch method, but attempts to re-establish the watch if it drop.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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