portallocator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetupRuntimePortAllocator

func SetupRuntimePortAllocator(client client.Client, pr *net.PortRange, allocatePolicyStr string, getReservedPorts func(client client.Client) (ports []int, err error)) error

SetupRuntimePortAllocator instantiates the global singleton rpa, set up port allocating policy according to the given allocatePolicyStr. Currently the valid policies are either "random" or "bitmap".

func SetupRuntimePortAllocatorWithType added in v0.8.0

func SetupRuntimePortAllocatorWithType(client client.Client, pr *net.PortRange, allocatePolicy AllocatePolicy, getReservedPorts func(client client.Client) (ports []int, err error))

SetupRuntimePortAllocatorWithType instantiates the global singleton rpa with specified port allocating policy

Types

type AllocatePolicy added in v0.8.0

type AllocatePolicy string
const (
	Random AllocatePolicy = "random"
	BitMap AllocatePolicy = "bitmap"
)

func ValidateEnum added in v0.8.4

func ValidateEnum(allocatePolicyStr string) (AllocatePolicy, error)

type BatchAllocatorInterface added in v0.8.0

type BatchAllocatorInterface interface {
	Allocate(int) error

	Release(int) error

	AllocateBatch(portNum int) ([]int, error)
	// contains filtered or unexported methods
}

type BitMapAllocator added in v0.8.0

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

func (*BitMapAllocator) Allocate added in v0.8.0

func (b *BitMapAllocator) Allocate(port int) error

func (*BitMapAllocator) AllocateBatch added in v0.8.0

func (b *BitMapAllocator) AllocateBatch(portNum int) (ports []int, err error)

func (*BitMapAllocator) Release added in v0.8.0

func (b *BitMapAllocator) Release(port int) error

type RandomAllocator added in v0.8.0

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

func (*RandomAllocator) Allocate added in v0.8.0

func (r *RandomAllocator) Allocate(port int) error

func (*RandomAllocator) AllocateBatch added in v0.8.0

func (r *RandomAllocator) AllocateBatch(portNum int) (ports []int, err error)

func (*RandomAllocator) Release added in v0.8.0

func (r *RandomAllocator) Release(i int) error

type RuntimePortAllocator

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

RuntimePortAllocator is an allocator resonsible for maintaining port usage information given a user-defined port range. It allocates and releases ports when a port is requested or reclaimed by a runtime.

func GetRuntimePortAllocator

func GetRuntimePortAllocator() (*RuntimePortAllocator, error)

GetRuntimePortAllocator restore the port allocator and gets the global singleton. This should be the only way others access the RuntimePortAllocator and it must be called after SetupRuntimePortAllocator

func (*RuntimePortAllocator) GetAvailablePorts

func (alloc *RuntimePortAllocator) GetAvailablePorts(portNum int) (ports []int, err error)

GetAvailablePorts requests portNum ports from the port allocator. It returns an int array with allocated ports in it.

func (*RuntimePortAllocator) ReleaseReservedPorts

func (alloc *RuntimePortAllocator) ReleaseReservedPorts(ports []int)

ReleaseReservedPorts releases all the ports in the given int array.

Jump to

Keyboard shortcuts

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