informer

package
v0.0.0-...-f16ff2c Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: Apache-2.0 Imports: 25 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InvalidColumnErr = errors.New("supplied column is invalid")
)

Functions

func UnsafeGet

func UnsafeGet(object any, field string) any

UnsafeGet returns the value of the passed object's for the passed field.

func UnsafeSet

func UnsafeSet(object any, field string, value any)

UnsafeSet replaces the passed object's field value with the passed value.

Types

type ByOptionsLister

type ByOptionsLister interface {
	ListByOptions(ctx context.Context, lo ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, int, string, error)
}

type DBClient

type DBClient interface {
	Begin() (db.TXClient, error)
	QueryForRows(ctx context.Context, stmt transaction.Stmt, params ...any) (*sql.Rows, error)
	ReadObjects(rows db.Rows, typ reflect.Type, shouldDecrypt bool) ([]any, error)
	ReadStrings(rows db.Rows) ([]string, error)
	ReadInt(rows db.Rows) (int, error)
	Prepare(stmt string) *sql.Stmt
	CloseStmt(stmt db.Closable) error
}

type Filter

type Filter struct {
	Field   []string
	Match   string
	Op      Op
	Partial bool
}

Filter represents a field to filter by. A subfield in an object is represented in a request query using . notation, e.g. 'metadata.name'. The subfield is internally represented as a slice, e.g. [metadata, name].

type Indexer

type Indexer struct {
	Store
	// contains filtered or unexported fields
}

Indexer is a SQLite-backed cache.Indexer which builds upon Store adding an index table

func NewIndexer

func NewIndexer(indexers cache.Indexers, s Store) (*Indexer, error)

NewIndexer returns a cache.Indexer backed by SQLite for objects of the given example type

func (*Indexer) AddIndexers

func (i *Indexer) AddIndexers(newIndexers cache.Indexers) error

AddIndexers adds more indexers to this Store. If you call this after you already have data in the Store, the results are undefined.

func (*Indexer) AfterUpsert

func (i *Indexer) AfterUpsert(key string, obj any, tx db.TXClient) error

AfterUpsert updates indices of an object

func (*Indexer) ByIndex

func (i *Indexer) ByIndex(indexName, indexedValue string) ([]any, error)

ByIndex returns the stored objects whose set of indexed values for the named index includes the given indexed value

func (*Indexer) GetIndexers

func (i *Indexer) GetIndexers() cache.Indexers

GetIndexers returns the indexers

func (*Indexer) Index

func (i *Indexer) Index(indexName string, obj any) ([]any, error)

Index returns a list of items that match the given object on the index function

func (*Indexer) IndexKeys

func (i *Indexer) IndexKeys(indexName, indexedValue string) ([]string, error)

IndexKeys returns a list of the Store keys of the objects whose indexed values in the given index include the given indexed value

func (*Indexer) ListIndexFuncValues

func (i *Indexer) ListIndexFuncValues(name string) []string

ListIndexFuncValues wraps safeListIndexFuncValues and panics in case of I/O errors

type Informer

type Informer struct {
	cache.SharedIndexInformer
	ByOptionsLister
}

Informer is a SQLite-backed cache.SharedIndexInformer that can execute queries on listprocessor structs

func NewInformer

func NewInformer(client dynamic.ResourceInterface, fields [][]string, gvk schema.GroupVersionKind, db sqlStore.DBClient, shouldEncrypt bool, namespaced bool) (*Informer, error)

NewInformer returns a new SQLite-backed Informer for the type specified by schema in unstructured.Unstructured form using the specified client

func (*Informer) ListByOptions

func (i *Informer) ListByOptions(ctx context.Context, lo ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, int, string, error)

ListByOptions returns objects according to the specified list options and partitions. Specifically:

  • an unstructured list of resources belonging to any of the specified partitions
  • the total number of resources (returned list might be a subset depending on pagination options in lo)
  • a continue token, if there are more pages after the returned one
  • an error instead of all of the above if anything went wrong

type ListOptionIndexer

type ListOptionIndexer struct {
	*Indexer
	// contains filtered or unexported fields
}

ListOptionIndexer extends Indexer by allowing queries based on ListOption

func NewListOptionIndexer

func NewListOptionIndexer(fields [][]string, s Store, namespaced bool) (*ListOptionIndexer, error)

NewListOptionIndexer returns a SQLite-backed cache.Indexer of unstructured.Unstructured Kubernetes resources of a certain GVK ListOptionIndexer is also able to satisfy ListOption queries on indexed (sub)fields Fields are specified as slices (eg. "metadata.resourceVersion" is ["metadata", "resourceVersion"])

func (*ListOptionIndexer) ListByOptions

func (l *ListOptionIndexer) ListByOptions(ctx context.Context, lo ListOptions, partitions []partition.Partition, namespace string) (*unstructured.UnstructuredList, int, string, error)

ListByOptions returns objects according to the specified list options and partitions. Specifically:

  • an unstructured list of resources belonging to any of the specified partitions
  • the total number of resources (returned list might be a subset depending on pagination options in lo)
  • a continue token, if there are more pages after the returned one
  • an error instead of all of the above if anything went wrong

type ListOptions

type ListOptions struct {
	ChunkSize  int
	Resume     string
	Filters    []OrFilter
	Sort       Sort
	Pagination Pagination
}

ListOptions represents the query parameters that may be included in a list request.

type Op

type Op string
const (
	Eq    Op = ""
	NotEq Op = "!="
)

type OrFilter

type OrFilter struct {
	Filters []Filter
}

OrFilter represents a set of possible fields to filter by, where an item may match any filter in the set to be included in the result.

type Pagination

type Pagination struct {
	PageSize int
	Page     int
}

Pagination represents how to return paginated results.

type Sort

type Sort struct {
	PrimaryField   []string
	SecondaryField []string
	PrimaryOrder   SortOrder
	SecondaryOrder SortOrder
}

Sort represents the criteria to sort on. The subfield to sort by is represented in a request query using . notation, e.g. 'metadata.name'. The subfield is internally represented as a slice, e.g. [metadata, name]. The order is represented by prefixing the sort key by '-', e.g. sort=-metadata.name.

type SortOrder

type SortOrder int

SortOrder represents whether the list should be ascending or descending.

const (
	// ASC stands for ascending order.
	ASC SortOrder = iota
	// DESC stands for descending (reverse) order.
	DESC
)

type Store

type Store interface {
	DBClient
	cache.Store

	GetByKey(key string) (item any, exists bool, err error)
	GetName() string
	RegisterAfterUpsert(f func(key string, obj any, tx db.TXClient) error)
	RegisterAfterDelete(f func(key string, tx db.TXClient) error)
	GetShouldEncrypt() bool
	GetType() reflect.Type
}

Directories

Path Synopsis
Package factory provides an cache factory for the sql-based cache.
Package factory provides an cache factory for the sql-based cache.

Jump to

Keyboard shortcuts

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