idalloc

package
Version: v3.3.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package idalloc is responsible for allocation of numeric identifiers in distributed manner, where each node in the cluster needs to be able to allocate an unique ID from the given pool for a given purpose identified by a string label, but once allocated, other nodes can not change / allocate a different ID for given purpose (label).

Index

Constants

This section is empty.

Variables

View Source
var DefaultPlugin = *NewPlugin()

DefaultPlugin is a default instance of IDAlloc plugin.

Functions

This section is empty.

Types

type API

type API interface {
	// InitPool initializes ID allocation pool with given name and ID range.
	// If the pool already exists, returns success if the pool range matches with
	// existing one (and effectively does nothing), false otherwise.
	InitPool(name string, poolRange *idallocation.AllocationPool_Range) (err error)

	// GetOrAllocateID returns allocated ID in given pool for given label. If the ID was
	// not already allocated, allocates new available ID.
	GetOrAllocateID(poolName string, idLabel string) (id uint32, err error)

	// ReleaseID releases existing allocation for given pool and label.
	// NOOP if the allocation does not exist.
	ReleaseID(poolName string, idLabel string) (err error)
}

API defines methods provided by the IDAllocator plugin for use by other plugins to query pod memif allocation info and release pod memif allocations.

type Deps

type Deps struct {
	infra.PluginDeps

	ServiceLabel servicelabel.ReaderAPI
	ContivConf   contivconf.API
	RemoteDB     nodesync.KVDBWithAtomic
}

Deps lists dependencies of the IDAllocator plugin.

type IDAllocator

type IDAllocator struct {
	Deps
	// contains filtered or unexported fields
}

IDAllocator plugin implements allocation of numeric identifiers in distributed manner.

func NewPlugin

func NewPlugin(opts ...Option) *IDAllocator

NewPlugin creates a new Plugin with the provides Options

func (*IDAllocator) Close

func (a *IDAllocator) Close() error

Close cleans up the resources.

func (*IDAllocator) GetOrAllocateID

func (a *IDAllocator) GetOrAllocateID(poolName string, idLabel string) (id uint32, err error)

GetOrAllocateID returns allocated ID in given pool for given label. If the ID was not already allocated, allocates new available ID.

func (*IDAllocator) HandlesEvent

func (a *IDAllocator) HandlesEvent(event controller.Event) bool

HandlesEvent selects:

- Resync
- KubeStateChange for ID allocation db resource

func (*IDAllocator) Init

func (a *IDAllocator) Init() (err error)

Init initializes plugin internals.

func (*IDAllocator) InitPool

func (a *IDAllocator) InitPool(name string, poolRange *idallocation.AllocationPool_Range) (err error)

InitPool initializes ID allocation pool with given name and ID range. If the pool already exists, returns success if the pool range matches with existing one (and effectively does nothing), false otherwise.

func (*IDAllocator) ReleaseID

func (a *IDAllocator) ReleaseID(poolName string, idLabel string) (err error)

ReleaseID releases existing allocation for given pool and label. NOOP if the pool or allocation does not exist.

func (*IDAllocator) Resync

func (a *IDAllocator) Resync(event controller.Event, kubeStateData controller.KubeStateData,
	resyncCount int, txn controller.ResyncOperations) (err error)

Resync resynchronizes ID Allocator.

func (*IDAllocator) Revert

func (a *IDAllocator) Revert(event controller.Event) error

Revert is NOOP - never called.

func (*IDAllocator) Update

func (a *IDAllocator) Update(event controller.Event, txn controller.UpdateOperations) (changeDescription string, err error)

Update handles ID allocation db change events.

type Option

type Option func(*IDAllocator)

Option is a function that acts on a Plugin to inject Dependencies or configuration

func UseDeps

func UseDeps(cb func(*Deps)) Option

UseDeps returns Option that can inject custom dependencies.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL