Documentation
¶
Index ¶
- Constants
- Variables
- func Expirable(ctx context.Context) bool
- func TableNameForModel(db *gorm.DB, model any) string
- func WithExpirable(parent context.Context) context.Context
- func WithUpdateDamping(ctx context.Context, threshold time.Duration) context.Context
- type Prefix
- type SQLiteIPAMStorage
- func (sqlis *SQLiteIPAMStorage) Add(ctx context.Context, prefix types.Prefix) error
- func (sqlis *SQLiteIPAMStorage) Delete(ctx context.Context, prefix types.Prefix) error
- func (sqlis *SQLiteIPAMStorage) Get(ctx context.Context, name string, parent types.Prefix) (types.Prefix, error)
- func (sqlis *SQLiteIPAMStorage) GetChilds(ctx context.Context, prefix types.Prefix) ([]types.Prefix, error)
- func (sqlis *SQLiteIPAMStorage) GetTableNameForTest() string
- func (sqlis *SQLiteIPAMStorage) InitForTest() error
- func (sqlis *SQLiteIPAMStorage) MigrateForTest(ctx context.Context) error
- func (sqlis *SQLiteIPAMStorage) RunGarbageCollectorOnceForTest(ctx context.Context, threshold time.Duration) error
- func (sqlis *SQLiteIPAMStorage) StartGarbageCollector(ctx context.Context, interval time.Duration, threshold time.Duration)
- func (sqlis *SQLiteIPAMStorage) Update(ctx context.Context, prefix types.Prefix) error
Constants ¶
const BridgeName = "bridge" // prefix with name "bridge" is special because it's not periodically updated
Variables ¶
var ErrCIDRConflict = prefix.ErrCIDRConflict // alias to simplify usage in this package
Functions ¶
func TableNameForModel ¶ added in v1.2.2
TableNameForModel infers the table name for a given model
func WithExpirable ¶ added in v1.1.2
WithExpirable - Stores in context whether the sqlite record must be expirable
Types ¶
type Prefix ¶
type Prefix struct {
Id string `gorm:"primaryKey"`
Name string `gorm:"index"` // supposedly indexing could improve query performance
Cidr string `gorm:"uniqueIndex:idx_parent_id_cidr"` // composite uniqueIndex should be helpful in resolving race conditions in concurrent allocation attempts considering the hierarchical allocation logic of prefix.Allocate
ParentID string `gorm:"index;uniqueIndex:idx_parent_id_cidr"`
Parent *Prefix
UpdatedAt time.Time `gorm:"index"` // supposedly indexing could improve query performance
Expirable *bool `gorm:"index;default:false"` // indicates whether prefix can expire and thus be subject to garbage collection
}
type SQLiteIPAMStorage ¶
func New ¶
func New(datastore string) (*SQLiteIPAMStorage, error)
func NewForTest ¶ added in v1.2.2
func NewForTest(db *gorm.DB) (*SQLiteIPAMStorage, error)
NewForTest is a constructor for testing purposes. It accepts an already opened *gorm.DB instance. It DOES NOT perform AutoMigrate or run init() automatically. This gives tests explicit control over schema setup and migration steps.
func (*SQLiteIPAMStorage) Add ¶
Add adds prefix to database. Also sets the expirable field based on the context.
func (*SQLiteIPAMStorage) Get ¶
func (sqlis *SQLiteIPAMStorage) Get(ctx context.Context, name string, parent types.Prefix) (types.Prefix, error)
Get finds and returns the first database record matching the given prefix. Note: default or unset fields are ignored by the GORM query
func (*SQLiteIPAMStorage) GetTableNameForTest ¶ added in v1.2.2
func (sqlis *SQLiteIPAMStorage) GetTableNameForTest() string
func (*SQLiteIPAMStorage) InitForTest ¶ added in v1.2.2
func (sqlis *SQLiteIPAMStorage) InitForTest() error
InitForTest is an exported helper for testing the internal init() logic. It performs AutoMigrate of the current Prefix model and runs the migrate function.
func (*SQLiteIPAMStorage) MigrateForTest ¶ added in v1.2.2
func (sqlis *SQLiteIPAMStorage) MigrateForTest(ctx context.Context) error
MigrateForTest is an exported helper for testing the internal migrate() logic. It provides direct access to the migration function.
func (*SQLiteIPAMStorage) RunGarbageCollectorOnceForTest ¶ added in v1.2.2
func (sqlis *SQLiteIPAMStorage) RunGarbageCollectorOnceForTest(ctx context.Context, threshold time.Duration) error
RunGarbageCollectorOnceForTest is an exported helper for testing internal garbageCollector() logic.
func (*SQLiteIPAMStorage) StartGarbageCollector ¶ added in v1.1.2
func (sqlis *SQLiteIPAMStorage) StartGarbageCollector(ctx context.Context, interval time.Duration, threshold time.Duration)
StartGarbageCollector - StartGarbageCollector periodically runs a garbage collector to clean up outdated expirable records with valid updatedAt values (where threshold determines what is considered outdated).
func (*SQLiteIPAMStorage) Update ¶ added in v1.1.2
Update - Updates or adds the database entry. Currently, the whole purpose of this function is to update the UpdatedAt field in the database that is used by garbage collector logic to clean up unused entries that haven't been updated for a long time. And to keep the expirable field set for records that can expire based on the context. (GORM Save() considers unset entries as well to update the record, thus expirable field must be set to either false or true.)