subnet

package
v0.0.0-...-b9fd9d2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DEFAULT_TTL time.Duration = 8760 * time.Hour // one year

Variables

View Source
var (
	ErrLeaseTaken  = errors.New("subnet: lease already taken")
	ErrNoMoreTries = errors.New("subnet: no more tries")
)

Functions

func MakeSubnetKey

func MakeSubnetKey(sn ip.IP4Net) string

func ParseSubnetKey

func ParseSubnetKey(s string) *ip.IP4Net

func WatchLease

func WatchLease(ctx context.Context, sm Manager, network string, sn ip.IP4Net, receiver chan Event)

WatchLease performs a long term watch of the given network's subnet lease and communicates addition/deletion events on receiver channel. It takes care of handling "fall-behind" logic where the history window has advanced too far and it needs to diff the latest snapshot with its saved state and generate events

func WatchLeases

func WatchLeases(ctx context.Context, sm Manager, network string, ownLease *Lease, receiver chan []Event)

WatchLeases performs a long term watch of the given network's subnet leases and communicates addition/deletion events on receiver channel. It takes care of handling "fall-behind" logic where the history window has advanced too far and it needs to diff the latest snapshot with its saved state and generate events

func WatchNetworks

func WatchNetworks(ctx context.Context, sm Manager, receiver chan []Event)

WatchNetworks performs a long term watch of flannel networks and communicates addition/deletion events on receiver channel. It takes care of handling "fall-behind" logic where the history window has advanced too far and it needs to diff the latest snapshot with its saved state and generate events

Types

type Config

type Config struct {
	Network     ip.IP4Net
	SubnetMin   ip.IP4
	SubnetMax   ip.IP4
	SubnetLen   uint
	VNI         int
	BackendType string          `json:"-"`
	Backend     json.RawMessage `json:",omitempty"`
}

func ParseConfig

func ParseConfig(s string) (*Config, error)

type EtcdConfig

type EtcdConfig struct {
	Endpoints []string
	Keyfile   string
	Certfile  string
	CAFile    string
	Prefix    string
	Username  string
	Password  string
}

type Event

type Event struct {
	Type    EventType `json:"type"`
	Lease   Lease     `json:"lease,omitempty"`
	Network string    `json:"network,omitempty"`
}

type EventType

type EventType int
const (
	EventAdded EventType = iota
	EventRemoved
)

func (EventType) MarshalJSON

func (et EventType) MarshalJSON() ([]byte, error)

func (*EventType) UnmarshalJSON

func (et *EventType) UnmarshalJSON(data []byte) error

type Lease

type Lease struct {
	Subnet     ip.IP4Net
	Attrs      LeaseAttrs
	Expiration time.Time
	// contains filtered or unexported fields
}

func (*Lease) Key

func (l *Lease) Key() string

type LeaseAttrs

type LeaseAttrs struct {
	PublicIP    ip.IP4
	BackendType string          `json:",omitempty"`
	BackendData json.RawMessage `json:",omitempty"`
}

type LeaseWatchResult

type LeaseWatchResult struct {
	// Either Events or Snapshot will be set.  If Events is empty, it means
	// the cursor was out of range and Snapshot contains the current list
	// of items, even if empty.
	Events   []Event     `json:"events"`
	Snapshot []Lease     `json:"snapshot"`
	Cursor   interface{} `json:"cursor"`
}

type LocalManager

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

func (*LocalManager) AcquireLease

func (m *LocalManager) AcquireLease(ctx context.Context, network string, attrs *LeaseAttrs) (*Lease, error)

func (*LocalManager) AddReservation

func (m *LocalManager) AddReservation(ctx context.Context, network string, r *Reservation) error

func (*LocalManager) GetNetworkConfig

func (m *LocalManager) GetNetworkConfig(ctx context.Context, network string) (*Config, error)

func (*LocalManager) ListReservations

func (m *LocalManager) ListReservations(ctx context.Context, network string) ([]Reservation, error)

func (*LocalManager) RemoveReservation

func (m *LocalManager) RemoveReservation(ctx context.Context, network string, subnet ip.IP4Net) error

RemoveReservation removes the subnet by setting TTL back to subnetTTL (24hours)

func (*LocalManager) RenewLease

func (m *LocalManager) RenewLease(ctx context.Context, network string, lease *Lease) error

func (*LocalManager) RevokeLease

func (m *LocalManager) RevokeLease(ctx context.Context, network string, sn ip.IP4Net) error

func (*LocalManager) WatchLease

func (m *LocalManager) WatchLease(ctx context.Context, network string, sn ip.IP4Net, cursor interface{}) (LeaseWatchResult, error)

func (*LocalManager) WatchLeases

func (m *LocalManager) WatchLeases(ctx context.Context, network string, cursor interface{}) (LeaseWatchResult, error)

func (*LocalManager) WatchNetworks

func (m *LocalManager) WatchNetworks(ctx context.Context, cursor interface{}) (NetworkWatchResult, error)

type Manager

type Manager interface {
	GetNetworkConfig(ctx context.Context, network string) (*Config, error)
	AcquireLease(ctx context.Context, network string, attrs *LeaseAttrs) (*Lease, error)
	RenewLease(ctx context.Context, network string, lease *Lease) error
	RevokeLease(ctx context.Context, network string, sn ip.IP4Net) error
	WatchLease(ctx context.Context, network string, sn ip.IP4Net, cursor interface{}) (LeaseWatchResult, error)
	WatchLeases(ctx context.Context, network string, cursor interface{}) (LeaseWatchResult, error)
	WatchNetworks(ctx context.Context, cursor interface{}) (NetworkWatchResult, error)

	AddReservation(ctx context.Context, network string, r *Reservation) error
	RemoveReservation(ctx context.Context, network string, subnet ip.IP4Net) error
	ListReservations(ctx context.Context, network string) ([]Reservation, error)
}

func NewLocalManager

func NewLocalManager(config *EtcdConfig) (Manager, error)

func NewMockManager

func NewMockManager(registry *MockSubnetRegistry) Manager

type MockSubnetRegistry

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

func NewMockRegistry

func NewMockRegistry(network, config string, initialSubnets []Lease) *MockSubnetRegistry

func (*MockSubnetRegistry) CreateNetwork

func (msr *MockSubnetRegistry) CreateNetwork(ctx context.Context, network, config string) error

func (*MockSubnetRegistry) DeleteNetwork

func (msr *MockSubnetRegistry) DeleteNetwork(ctx context.Context, network string) error

type NetworkWatchResult

type NetworkWatchResult struct {
	// Either Events or Snapshot will be set.  If Events is empty, it means
	// the cursor was out of range and Snapshot contains the current list
	// of items, even if empty.
	Events   []Event     `json:"events"`
	Snapshot []string    `json:"snapshot"`
	Cursor   interface{} `json:"cursor,omitempty"`
}

type Registry

type Registry interface {
	// contains filtered or unexported methods
}

type Reservation

type Reservation struct {
	Subnet   ip.IP4Net
	PublicIP ip.IP4
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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