mem

package
v0.0.0-...-432d548 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package mem is a generated GoMock package.

Index

Constants

View Source
const (
	// MetricPersistMarshalTime marshal time in persist
	// labels: [namespace, batch_name, kind]
	MetricPersistMarshalTime = "persist_marshal_time"
	// MetricPersistWriteTime write marshaled data in store time
	// labels: [namespace, batch_name, kind]
	MetricPersistWriteTime = "persist_write_time"
	// MetricPersistFileSize the final file size write to storage
	// labels: [namespace, batch_name, kind]
	MetricPersistFileSize = "persist_file_size"
	// MetricPersistCountInBatch the items count in 1 batch
	// labels: [namespace, batch_name, kind]
	MetricPersistCountInBatch = "persist_count_in_batch"
	// MetricStoreRunTime the cost time each store.run
	// labels: [name, namespace, kind]
	MetricStoreRunTime = "store_run_time"
	// MetricWatchSendTime send watch event time
	// labels: [kind, source]
	MetricWatchSendTime = "watch_send_time"
)
View Source
const (
	// MemObjectVersionAnnoKey the label key name for object version
	MemObjectVersionAnnoKey = "memkube/object-version"
	// MemObjectVersionAnnoValue version
	MemObjectVersionAnnoValue = "2.0.0"
	// MemObjectOwnerRefsKey the annotation key to hold mem object refs
	MemObjectOwnerRefsKey = "memkube/owner-refs"
)
View Source
const (
	//TouchName new start touch file name
	TouchName = ".meta"
)

Variables

View Source
var (
	// ErrInvalidOwnerRefs invalid owner refs
	ErrInvalidOwnerRefs = errors.New("invalid mem-obj owner refs")
)
View Source
var (
	// ErrObjectInvalid the object to add/update is invalid
	ErrObjectInvalid = errors.New("object is invalid")
)
View Source
var (
	// ErrWaitTimeout wait operation timeout
	ErrWaitTimeout = errors.New("wait the operation result timeout")
)

Metrics is a metric factory.

View Source
var PersistedVersion = version.Must(version.NewVersion(MemObjectVersionAnnoValue))

PersistedVersion all tag version < PersistedVersion will NOT be persisted. Some fields in runtime.Object doesn't need to persisted, here we use `"github.com/liip/sheriff"` library to filter these fields. e.g: Metas map[string]string `json:"metas" until:"1.0.0"`, when 1.0.0 < PersistedVersion, `Metas` will not be persisted.

Functions

func Describe

func Describe(o runtime.Object) string

Describe describes a runtime.Object, only used to log.

func DuplicateInformerCache

func DuplicateInformerCache(informer cache.SharedIndexInformer, newIndexers cache.Indexers) cache.Indexer

DuplicateInformerCache duplicates cache from informer, it binds event handlers to the informer, and update items in duplicated cache. NOTE: If use this cache to get objects, but register handlers on the raw informer, data mismatched (notified by v2, but only get v1)

func FilterMarshal

func FilterMarshal(obj runtime.Object) ([]byte, error)

FilterMarshal filter some fields for a runtime.Object

func GetControllerOf

func GetControllerOf(controllee metav1.Object) (*metav1.OwnerReference, error)

GetControllerOf returns a pointer to a copy of the controllerRef if controllee has a controller

func GetOwneeReferences

func GetOwneeReferences(owner runtime.Object, gvk schema.GroupVersionKind) ([]metav1.OwnerReference, error)

GetOwneeReferences constructs owner references for an object. If the owner is mem-object, return its owner refs.

func IsMemObject

func IsMemObject(obj metav1.Object) bool

IsMemObject checks if an object is mem-kube object.

func IsUIDEqual

func IsUIDEqual(obj0, obj1 runtime.Object) (bool, error)

IsUIDEqual check if two objects has equal uid.

func Kind

func Kind(obj runtime.Object) string

Kind gets kind string for object.

func Memorize

func Memorize(obj runtime.Object) error

Memorize make a normal kubenetes object into memory object.

func MergeOwnerReferences

func MergeOwnerReferences(src []metav1.OwnerReference, dst []metav1.OwnerReference) []metav1.OwnerReference

MergeOwnerReferences merge owner refs

func MetaAccessors

func MetaAccessors(fn func(accessor ...metav1.Object) error, objs ...runtime.Object) error

MetaAccessors gets meta accessors for objects and call operation function.

func MetaName

func MetaName(obj runtime.Object) string

MetaName return the name of a runtime object.

func MetaNameKey

func MetaNameKey(obj interface{}) (string, error)

MetaNameKey used in cache.Indexer.

func MetaResourceVersion

func MetaResourceVersion(obj runtime.Object) (uint64, error)

MetaResourceVersion get resource version for an object.

func ParseResourceVersion

func ParseResourceVersion(rv string) (uint64, error)

ParseResourceVersion parse resource version

func SetMetaResourceVersion

func SetMetaResourceVersion(obj runtime.Object, ver uint64) (uint64, error)

SetMetaResourceVersion set the resource version

func SetOwnerReferences

func SetOwnerReferences(owner runtime.Object, ownerGvk schema.GroupVersionKind, ownee metav1.Object) error

SetOwnerReferences set owner references to object.

  • If the owner is a k8s object, it's the real owner, set the owner to `OwnerReferences`
  • If the owner is a mem object, then get the k8s owner of it (from `OwnerReferences`), and set the real k8s owner to ownee's OwnerReferences, and set the direct mem owner to ownee's Annotations.

func Stringify

func Stringify(o interface{}) string

Stringify stringify a go object

func TweakObjectMetas

func TweakObjectMetas(obj runtime.Object, ver uint64) error

TweakObjectMetas tweats some required properties for an object.

func TweakTypeMetas

func TweakTypeMetas(gvk schema.GroupVersionKind, obj runtime.Object) error

TweakTypeMetas tweats object type metas.

func Unmemorize

func Unmemorize(obj runtime.Object) error

Unmemorize strips memory object as a normal kubenetes object.

Types

type BatchObject

type BatchObject struct {
	Name string `json:"name"`
	// Traits are some special properties parsed from object, to identify this batchObject. E.g: shardId in c2.
	Traits map[string]string `json:"traits,omitempty"`
	Items  pendingList       `json:"items"`
	// contains filtered or unexported fields
}

BatchObject is a batch of object.

func NewBatchObject

func NewBatchObject(name string) *BatchObject

NewBatchObject creates a new batch object.

func (*BatchObject) IsDrity

func (b *BatchObject) IsDrity() bool

IsDrity persist only if the batch is dirty

func (*BatchObject) Marshal

func (b *BatchObject) Marshal(encodig encodingType) ([]byte, error)

Marshal marshal this batch object

type Batcher

type Batcher interface {
	Batch([]*pendingObject) ([]*BatchObject, error)
}

Batcher batch a list of objects into batches.

type FakePersister

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

FakePersister is a persister.

func NewFakePersister

func NewFakePersister() *FakePersister

NewFakePersister create a fake persister

func (*FakePersister) Close

func (p *FakePersister) Close() error

Close close persister

func (*FakePersister) Persist

func (p *FakePersister) Persist(b *BatchObject) error

Persist persists batch object.

func (*FakePersister) PersistMeta

func (p *FakePersister) PersistMeta(*MetaInfo) error

PersistMeta persist meta info

func (*FakePersister) Recover

func (p *FakePersister) Recover(fn NewObjectFunc) ([]*BatchObject, *MetaInfo, error)

Recover reload all objects.

type FilterMarshaler

type FilterMarshaler interface {
	FilterMarshalJSON() ([]byte, error)
}

FilterMarshaler marshals object to a json string.

type FsPersister

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

FsPersister is a file system persister which used fstorage.

func NewFsPersister

func NewFsPersister(url, backupURL string, namespace string, gvk schema.GroupVersionKind, matcher TraitsMatcher) (*FsPersister, error)

NewFsPersister create a new FsPersister.

func (*FsPersister) Close

func (p *FsPersister) Close() error

Close close persister

func (*FsPersister) NegotiateEncoding

func (p *FsPersister) NegotiateEncoding(o runtime.Object)

NegotiateEncoding negotiate encoding by object

func (*FsPersister) Persist

func (p *FsPersister) Persist(obj *BatchObject) error

Persist persists batch object.

func (*FsPersister) PersistMeta

func (p *FsPersister) PersistMeta(meta *MetaInfo) error

PersistMeta persist meta info

func (*FsPersister) Recover

func (p *FsPersister) Recover(fn NewObjectFunc) ([]*BatchObject, *MetaInfo, error)

Recover reload all objects.

type FuncBatcher

type FuncBatcher struct {
	TraitsFunc TraitsFunc
	KeyFunc    KeyFunc
}

FuncBatcher batch objects by a custom function.

func (*FuncBatcher) Batch

func (b *FuncBatcher) Batch(items []*pendingObject) ([]*BatchObject, error)

Batch batch objects. Try the best to batch all objects, skip these failed objects.

type KeyFunc

type KeyFunc func(runtime.Object) (string, error)

KeyFunc format a key for an object.

func HashedNameFuncLabelValue

func HashedNameFuncLabelValue(key string, hashNum uint32) KeyFunc

HashedNameFuncLabelValue labelValue+hash

func KeyFuncHashName

func KeyFuncHashName(hashNum uint32, prefixFn func(metav1.Object) (string, error)) KeyFunc

KeyFuncHashName return $prefixFn(obj)-hash($name) % hashNum

func KeyFuncLabelValue

func KeyFuncLabelValue(key string) KeyFunc

KeyFuncLabelValue create a KeyFunc by label value.

type MetaInfo

type MetaInfo struct {
	// [1, N], the current max version
	VersionSeed uint64 `json:"versionSeed"`
}

MetaInfo tracks the meta info for the specified resource

func NewMetaInfo

func NewMetaInfo() *MetaInfo

NewMetaInfo new a meta info

func (*MetaInfo) CurrentVersion

func (mi *MetaInfo) CurrentVersion() uint64

CurrentVersion get current version

func (*MetaInfo) DeepCopy

func (mi *MetaInfo) DeepCopy() *MetaInfo

DeepCopy deep copy this

func (*MetaInfo) Equal

func (mi *MetaInfo) Equal(other *MetaInfo) bool

Equal check if equals

func (*MetaInfo) IncVersionSeed

func (mi *MetaInfo) IncVersionSeed() uint64

IncVersionSeed inc the version seed

type MockPersister

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

MockPersister is a mock of Persister interface.

func NewMockPersister

func NewMockPersister(ctrl *gomock.Controller) *MockPersister

NewMockPersister creates a new mock instance.

func (*MockPersister) Close

func (m *MockPersister) Close() error

Close mocks base method.

func (*MockPersister) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPersister) Persist

func (m *MockPersister) Persist(arg0 *BatchObject) error

Persist mocks base method.

func (*MockPersister) PersistMeta

func (m *MockPersister) PersistMeta(arg0 *MetaInfo) error

PersistMeta mocks base method.

func (*MockPersister) Recover

func (m *MockPersister) Recover(fn NewObjectFunc) ([]*BatchObject, *MetaInfo, error)

Recover mocks base method.

type MockPersisterMockRecorder

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

MockPersisterMockRecorder is the mock recorder for MockPersister.

func (*MockPersisterMockRecorder) Close

func (mr *MockPersisterMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockPersisterMockRecorder) Persist

func (mr *MockPersisterMockRecorder) Persist(arg0 interface{}) *gomock.Call

Persist indicates an expected call of Persist.

func (*MockPersisterMockRecorder) PersistMeta

func (mr *MockPersisterMockRecorder) PersistMeta(arg0 interface{}) *gomock.Call

PersistMeta indicates an expected call of PersistMeta.

func (*MockPersisterMockRecorder) Recover

func (mr *MockPersisterMockRecorder) Recover(fn interface{}) *gomock.Call

Recover indicates an expected call of Recover.

type MocknegotiatedPersister

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

MocknegotiatedPersister is a mock of negotiatedPersister interface.

func NewMocknegotiatedPersister

func NewMocknegotiatedPersister(ctrl *gomock.Controller) *MocknegotiatedPersister

NewMocknegotiatedPersister creates a new mock instance.

func (*MocknegotiatedPersister) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MocknegotiatedPersister) NegotiateEncoding

func (m *MocknegotiatedPersister) NegotiateEncoding(o runtime.Object)

NegotiateEncoding mocks base method.

type MocknegotiatedPersisterMockRecorder

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

MocknegotiatedPersisterMockRecorder is the mock recorder for MocknegotiatedPersister.

func (*MocknegotiatedPersisterMockRecorder) NegotiateEncoding

func (mr *MocknegotiatedPersisterMockRecorder) NegotiateEncoding(o interface{}) *gomock.Call

NegotiateEncoding indicates an expected call of NegotiateEncoding.

type NamespacePersisterFactory

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

NamespacePersisterFactory persister factory

func NewNamespacePersisterFactory

func NewNamespacePersisterFactory(url, backupURL, namespace string) (*NamespacePersisterFactory, error)

NewNamespacePersisterFactory new fac

func (*NamespacePersisterFactory) Check

func (f *NamespacePersisterFactory) Check() error

Check check url vaild

func (*NamespacePersisterFactory) NewFsPersister

NewFsPersister new FsPersister

type NewObjectFunc

type NewObjectFunc func() runtime.Object

NewObjectFunc create an empty object.

type OneBatcher

type OneBatcher struct {
	Name string
}

OneBatcher batch all object into one batch.

func (*OneBatcher) Batch

func (b *OneBatcher) Batch(items []*pendingObject) ([]*BatchObject, error)

Batch batch objects.

type OpResult

type OpResult interface {
	Wait(timeout time.Duration) error
}

OpResult represents store operation results.

type Persister

type Persister interface {
	Persist(*BatchObject) error
	PersistMeta(*MetaInfo) error
	Recover(fn NewObjectFunc) ([]*BatchObject, *MetaInfo, error)
	Close() error
}

Persister persists a list of batch objects.

type ReadResult

type ReadResult interface {
	OpResult
	List() []runtime.Object
}

ReadResult for read operations.

type ResourceScheme

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

ResourceScheme tracks the resource to kind mapping.

func NewResourceScheme

func NewResourceScheme(scheme *runtime.Scheme) *ResourceScheme

NewResourceScheme create a new ResourceScheme

func (*ResourceScheme) KindFor

KindFor get the kind for a resource.

func (*ResourceScheme) LogInfo

func (s *ResourceScheme) LogInfo()

LogInfo log details of this scheme.

func (*ResourceScheme) New

New create an runtime.Object by resource type, similar with schema.Scheme.New

func (*ResourceScheme) NewList

NewList create a XXXList runtime.Obejct for resource.

func (*ResourceScheme) Scheme

func (s *ResourceScheme) Scheme() *runtime.Scheme

Scheme returns the runtime scheme.

type SelectionPredicate

type SelectionPredicate struct {
	Label labels.Selector
}

SelectionPredicate filter events

func (*SelectionPredicate) Match

func (s *SelectionPredicate) Match(obj runtime.Object) (bool, error)

Match check if this obj matches

type Store

type Store interface {
	Start(stopCh <-chan struct{}) error
	List(labels.Selector) ([]runtime.Object, uint64, error)
	Watch(*WatchOptions) (watch.Interface, error)
	Get(name string) (ReadResult, error)
	Peek(name string) (runtime.Object, error)
	Add(obj runtime.Object) (WriteResult, error)
	Update(obj runtime.Object) (WriteResult, error)
	Delete(name string) (WriteResult, error)
}

Store stores memory objects.

func NewStore

func NewStore(scheme *runtime.Scheme, gvk schema.GroupVersionKind, namespace string, batcher Batcher, persister Persister, opts ...StoreOption) Store

NewStore creates a store.

func NewTestStore

func NewTestStore(stopCh chan struct{}, persistPeriod time.Duration) Store

NewTestStore creates a store for test

type StoreOption

type StoreOption func(*persistedStore) *persistedStore

StoreOption defines the options for store.

func WithSilentWatchConsumer

func WithSilentWatchConsumer(stopCh <-chan struct{}) StoreOption

WithSilentWatchConsumer consumes all events from this store and drop the events.

func WithStoreConcurrentPersist

func WithStoreConcurrentPersist(worker int, qsize int) StoreOption

WithStoreConcurrentPersist set persist concurrent options.

func WithStorePersistPeriod

func WithStorePersistPeriod(period time.Duration) StoreOption

WithStorePersistPeriod set persist period. Default 500ms

type TraitsFunc

type TraitsFunc func(runtime.Object) (map[string]string, error)

TraitsFunc parse traits from object.

func TraitsFuncLabels

func TraitsFuncLabels(keys ...string) TraitsFunc

TraitsFuncLabels create a TraitsFunc by a list of labels.

type TraitsMatcher

type TraitsMatcher func(map[string]string) bool

TraitsMatcher check if traits matches in persiter recover.

type WatchBroadcaster

type WatchBroadcaster interface {
	Watch(opts *WatchOptions, pred SelectionPredicate) (watch.Interface, error)
	Action(event watch.Event) error
	Shutdown()
}

WatchBroadcaster broadcasts watch events

func NewCacheWatchBroadcaster

func NewCacheWatchBroadcaster(cap int, kind string) WatchBroadcaster

NewCacheWatchBroadcaster creates a cached watch broadcaster

type WatchOptions

type WatchOptions struct {
	metav1.ListOptions
	// Set to true if watch in same process, default true
	LocalWatch *bool
	// Identify source
	Source string
}

WatchOptions options for watch

type WriteResult

type WriteResult interface {
	OpResult
	Object() runtime.Object
}

WriteResult is write operation result.

Jump to

Keyboard shortcuts

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