subnet

package
v0.20.2 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func CheckNetworkConfig added in v0.20.0

func CheckNetworkConfig(config *Config) error

func GetFlannelIPv6Network added in v0.20.0

func GetFlannelIPv6Network(config *Config) ip.IP6Net

func GetFlannelNetwork added in v0.20.0

func GetFlannelNetwork(config *Config) ip.IP4Net

func MakeSubnetKey added in v0.5.6

func MakeSubnetKey(sn ip.IP4Net, sn6 ip.IP6Net) string

func ParseSubnetKey added in v0.5.6

func ParseSubnetKey(s string) (*ip.IP4Net, *ip.IP6Net)

func WatchLease added in v0.5.6

func WatchLease(ctx context.Context, sm Manager, sn ip.IP4Net, sn6 ip.IP6Net, 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 added in v0.5.0

func WatchLeases(ctx context.Context, sm Manager, 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

Types

type Config

type Config struct {
	EnableIPv4    bool
	EnableIPv6    bool
	Network       ip.IP4Net
	IPv6Network   ip.IP6Net
	Networks      []ip.IP4Net
	IPv6Networks  []ip.IP6Net
	SubnetMin     ip.IP4
	SubnetMax     ip.IP4
	IPv6SubnetMin *ip.IP6
	IPv6SubnetMax *ip.IP6
	SubnetLen     uint
	IPv6SubnetLen uint
	BackendType   string          `json:"-"`
	Backend       json.RawMessage `json:",omitempty"`
}

func ParseConfig

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

type Event

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

type EventType

type EventType int
const (
	EventAdded EventType = iota
	EventRemoved
)

func (EventType) MarshalJSON added in v0.5.0

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

func (*EventType) UnmarshalJSON added in v0.5.0

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

type Lease added in v0.5.0

type Lease struct {
	EnableIPv4 bool
	EnableIPv6 bool
	Subnet     ip.IP4Net
	IPv6Subnet ip.IP6Net
	Attrs      LeaseAttrs
	Expiration time.Time

	Asof int64
}

func (*Lease) Key added in v0.5.0

func (l *Lease) Key() string

type LeaseAttrs added in v0.2.0

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

type LeaseWatchResult added in v0.5.6

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 Manager added in v0.5.0

type Manager interface {
	GetNetworkConfig(ctx context.Context) (*Config, error)
	AcquireLease(ctx context.Context, attrs *LeaseAttrs) (*Lease, error)
	RenewLease(ctx context.Context, lease *Lease) error
	WatchLease(ctx context.Context, sn ip.IP4Net, sn6 ip.IP6Net, cursor interface{}) (LeaseWatchResult, error)
	WatchLeases(ctx context.Context, cursor interface{}) (LeaseWatchResult, error)
	CompleteLease(ctx context.Context, lease *Lease, wg *sync.WaitGroup) error

	Name() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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