package allocator
import "k8s.io/kubernetes/pkg/registry/core/service/allocator"
Index ¶
- type AllocationBitmap
- func NewAllocationMap(max int, rangeSpec string) *AllocationBitmap
- func NewAllocationMapWithOffset(max int, rangeSpec string, offset int) *AllocationBitmap
- func (r *AllocationBitmap) Allocate(offset int) (bool, error)
- func (r *AllocationBitmap) AllocateNext() (int, bool, error)
- func (r *AllocationBitmap) Destroy()
- func (r *AllocationBitmap) ForEach(fn func(int))
- func (r *AllocationBitmap) Free() int
- func (r *AllocationBitmap) Has(offset int) bool
- func (r *AllocationBitmap) Release(offset int) error
- func (r *AllocationBitmap) Restore(rangeSpec string, data []byte) error
- func (r *AllocationBitmap) Snapshot() (string, []byte)
- type AllocatorFactory
- type AllocatorWithOffsetFactory
- type Interface
- type Snapshottable
Types ¶
type AllocationBitmap ¶
type AllocationBitmap struct {
// contains filtered or unexported fields
}
AllocationBitmap is a contiguous block of resources that can be allocated atomically.
Each resource has an offset. The internal structure is a bitmap, with a bit for each offset.
If a resource is taken, the bit at that offset is set to one. r.count is always equal to the number of set bits and can be recalculated at any time by counting the set bits in r.allocated.
TODO: use RLE and compact the allocator to minimize space.
func NewAllocationMap ¶
func NewAllocationMap(max int, rangeSpec string) *AllocationBitmap
NewAllocationMap creates an allocation bitmap using the random scan strategy.
func NewAllocationMapWithOffset ¶
func NewAllocationMapWithOffset(max int, rangeSpec string, offset int) *AllocationBitmap
NewAllocationMapWithOffset creates an allocation bitmap using a random scan strategy that allows to pass an offset that divides the allocation bitmap in two blocks. The first block of values will not be used for random value assigned by the AllocateNext() method until the second block of values has been exhausted. The offset value must be always smaller than the bitmap size.
func (*AllocationBitmap) Allocate ¶
func (r *AllocationBitmap) Allocate(offset int) (bool, error)
Allocate attempts to reserve the provided item. Returns true if it was allocated, false if it was already in use
func (*AllocationBitmap) AllocateNext ¶
func (r *AllocationBitmap) AllocateNext() (int, bool, error)
AllocateNext reserves one of the items from the pool. (0, false, nil) may be returned if there are no items left.
func (*AllocationBitmap) Destroy ¶
func (r *AllocationBitmap) Destroy()
Destroy cleans up everything on shutdown.
func (*AllocationBitmap) ForEach ¶
func (r *AllocationBitmap) ForEach(fn func(int))
ForEach calls the provided function for each allocated bit. The AllocationBitmap may not be modified while this loop is running.
func (*AllocationBitmap) Free ¶
func (r *AllocationBitmap) Free() int
Free returns the count of items left in the range.
func (*AllocationBitmap) Has ¶
func (r *AllocationBitmap) Has(offset int) bool
Has returns true if the provided item is already allocated and a call to Allocate(offset) would fail.
func (*AllocationBitmap) Release ¶
func (r *AllocationBitmap) Release(offset int) error
Release releases the item back to the pool. Releasing an unallocated item or an item out of the range is a no-op and returns no error.
func (*AllocationBitmap) Restore ¶
func (r *AllocationBitmap) Restore(rangeSpec string, data []byte) error
Restore restores the pool to the previously captured state.
func (*AllocationBitmap) Snapshot ¶
func (r *AllocationBitmap) Snapshot() (string, []byte)
Snapshot saves the current state of the pool.
type AllocatorFactory ¶
type AllocatorWithOffsetFactory ¶
type Interface ¶
type Interface interface { Allocate(int) (bool, error) AllocateNext() (int, bool, error) Release(int) error ForEach(func(int)) Has(int) bool Free() int // Destroy shuts down all internal structures. // Destroy needs to be implemented in thread-safe way and be prepared for being // called more than once. Destroy() }
Interface manages the allocation of items out of a range. Interface should be threadsafe.
type Snapshottable ¶
type Snapshottable interface { Interface Snapshot() (string, []byte) Restore(string, []byte) error }
Snapshottable is an Interface that can be snapshotted and restored. Snapshottable should be threadsafe.
Source Files ¶
bitmap.go interfaces.go utils.go
Directories ¶
Path | Synopsis |
---|---|
pkg/registry/core/service/allocator/storage |
- Version
- v1.33.0 (latest)
- Published
- Apr 23, 2025
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 3 hours ago –
Tools for package owners.