resource_cache

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheConfig

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

func NewCacheConfig added in v0.0.2

func NewCacheConfig(scheme *runtime.Scheme, logKey interface{}, protectedGVKs map[schema.GroupVersionKind]bool, debugOptions DebugOptions) *CacheConfig

type DebugOptions added in v0.0.7

type DebugOptions struct {
	Create bool
	Update bool
	Apply  bool
}

type ObjectCache

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

ObjectCache is the main caching provider object. It holds references to some anciliary objects as well as a Data structure that is used to hold the K8sResources.

func NewObjectCache

func NewObjectCache(ctx context.Context, kclient client.Client, config *CacheConfig) ObjectCache

NewObjectCache returns an instance of the ObjectCache which defers all applys until the end of the reconciliation process, and allows providers to pull objects out of the cache for modification.

func (*ObjectCache) ApplyAll

func (o *ObjectCache) ApplyAll() error

ApplyAll takes all the items in the cache and tries to apply them, given the boolean by the update field on the internal resource. If the update is true, then the object will by applied, if it is false, then the object will be created.

func (*ObjectCache) Create

func (o *ObjectCache) Create(resourceIdent ResourceIdent, nn types.NamespacedName, object client.Object) error

Create first attempts to fetch the object from k8s for initial population. If this fails, the blank object is stored in the cache it is imperative that the user of this function call Create before modifying the obejct they wish to be placed in the cache.

func (*ObjectCache) Debug

func (o *ObjectCache) Debug()

Debug prints out the contents of the cache.

func (*ObjectCache) Get

func (o *ObjectCache) Get(resourceIdent ResourceIdent, object client.Object, nn ...types.NamespacedName) error

Get pulls the item from the cache and populates the given empty object. An error is returned if the items are of different types and also if the item is not in the cache. A get should be used by a downstream provider. If modifications are made to the object, it should be updated using the Update call.

func (*ObjectCache) GetScheme added in v0.0.5

func (o *ObjectCache) GetScheme() *runtime.Scheme

func (*ObjectCache) List

func (o *ObjectCache) List(resourceIdent ResourceIdentMulti, object runtime.Object) error

List returns a list of objects stored in the cache for the given ResourceIdent. This list behanves like a standard k8s List object although the revision cannot be relied upon. It is simply to return something that is familiar to users of k8s client-go. It internally converts the objects in the list to JSON and adds them to a JSON string, before converting the entire object into a List object of the type passed in by the user.

func (*ObjectCache) Reconcile

func (o *ObjectCache) Reconcile(ownedUID types.UID, opts ...client.ListOption) error

Reconcile performs the delete on objects that are no longer required

func (*ObjectCache) Status

func (o *ObjectCache) Status(resourceIdent ResourceIdent, object client.Object) error

Status marks the object for having a status update

func (*ObjectCache) Update

func (o *ObjectCache) Update(resourceIdent ResourceIdent, object client.Object) error

Update takes the item and tries to update the version in the cache. This will fail if the item is not in the cache. A previous provider should have "created" the item before it can be updated.

type ResourceIdent

type ResourceIdent interface {
	GetProvider() string
	GetPurpose() string
	GetType() client.Object
	GetWriteNow() bool
}

type ResourceIdentMulti

type ResourceIdentMulti struct {
	Provider string
	Purpose  string
	Type     client.Object
	WriteNow bool
}

ResourceIdent is a simple struct declaring a providers identifier and the type of resource to be put into the cache. It functions as an identifier allowing multiple objects to be returned if they all come from the same provider and have the same purpose. Think a list of Jobs created by a Job creator.

func NewMultiResourceIdent added in v0.2.1

func NewMultiResourceIdent(provider string, purpose string, object client.Object, opts ...ResourceOptions) ResourceIdentMulti

NewMultiResourceIdent is a helper function that returns a ResourceIdent object.

func (ResourceIdentMulti) GetProvider

func (r ResourceIdentMulti) GetProvider() string

func (ResourceIdentMulti) GetPurpose

func (r ResourceIdentMulti) GetPurpose() string

func (ResourceIdentMulti) GetType

func (r ResourceIdentMulti) GetType() client.Object

func (ResourceIdentMulti) GetWriteNow added in v0.0.4

func (r ResourceIdentMulti) GetWriteNow() bool

type ResourceIdentSingle

type ResourceIdentSingle struct {
	Provider string
	Purpose  string
	Type     client.Object
	WriteNow bool
}

ResourceIdent is a simple struct declaring a providers identifier and the type of resource to be put into the cache. It functions as an identifier allowing multiple objects to be returned if they all come from the same provider and have the same purpose. Think a list of Jobs created by a Job creator.

func NewSingleResourceIdent added in v0.2.1

func NewSingleResourceIdent(provider string, purpose string, object client.Object, opts ...ResourceOptions) ResourceIdentSingle

NewSingleResourceIdent is a helper function that returns a ResourceIdent object.

func (ResourceIdentSingle) GetProvider

func (r ResourceIdentSingle) GetProvider() string

func (ResourceIdentSingle) GetPurpose

func (r ResourceIdentSingle) GetPurpose() string

func (ResourceIdentSingle) GetType

func (r ResourceIdentSingle) GetType() client.Object

func (ResourceIdentSingle) GetWriteNow added in v0.0.4

func (r ResourceIdentSingle) GetWriteNow() bool

type ResourceOptions added in v0.0.4

type ResourceOptions struct {
	WriteNow bool
}

Jump to

Keyboard shortcuts

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