providers

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProvidersRegistration providersRegistration

ProvidersRegistration is an instance of the provider registration system. It is responsible for adding new providers to the registry so that they can be executed in the correct order.

Functions

func CachedMakeComponent

func CachedMakeComponent(cache *ObjectCache, objList []ResourceIdent, o obj.ClowdObject, suffix string, fn makeFnCache, usePVC bool, nodePort bool) error

CachedMakeComponent is a generalised function that, given a ClowdObject will make the given service, deployment and PVC, based on the makeFn that is passed in.

func ExtractSecretData

func ExtractSecretData(secrets []core.Secret, fn ExtractFn, keys ...string)

ExtractSecretData takes a list of secrets, checks that the correct 'keys' are present and then runs the extract function on them.

func ExtractSecretDataAnno

func ExtractSecretDataAnno(secrets []core.Secret, fn ExtractFnAnno, annoKey string, keys ...string)

ExtractSecretDataAnno is just like ExtractSecretData except it expects an annotation to be present on the secret that will provide one of the values needed to extract the data out of the secret

func GetNamespacedName

func GetNamespacedName(o obj.ClowdObject, suffix string) types.NamespacedName

GetNamespacedName returns a unique name of an object in the format name-suffix.

func MakeOrGetSecret

func MakeOrGetSecret(ctx context.Context, obj obj.ClowdObject, cache *ObjectCache, resourceIdent ResourceIdent, nn types.NamespacedName, dataInit func() map[string]string) (*map[string]string, error)

MakeOrGetSecret tries to get the secret described by nn, if it exists it populates a map with the key/value pairs from the secret. If it doesn't exist the dataInit function is run and the resulting data is returned, as well as the secret being created.

func StrPtr

func StrPtr(s string) *string

StrPtr returns a pointer to a string.

Types

type ClowderProvider

type ClowderProvider interface {
	// Provide is the main function that performs the duty of the provider on a ClowdApp object, as
	// opposed to a ClowdEnvironment object.
	Provide(app *crd.ClowdApp, c *config.AppConfig) error
}

ClowderProvider is an interface providing a way for a provider to perform its duty.

type ExtractFn

type ExtractFn func(m *core.Secret)

ExtractFn is a function that can extract secret data from a function, the result of this function is usually declared as part of the function so no arguments are passed.

type ExtractFnAnno

type ExtractFnAnno func(m *core.Secret, annoVal string)

ExtractFnAnno is just like ExtractFn except it reads in the value of an annotation

type Labels

type Labels map[string]string

Labels is a map containing a key/value style map intended to hold k8s label information.

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, scheme *runtime.Scheme) 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 imperitive 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) 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(clowdObj object.ClowdObject) 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 ObjectMap

type ObjectMap map[ResourceIdent]client.Object

ObjectMap providers a map of ResourceIdents to objects, it is used internally and for testing.

type Provider

type Provider struct {
	Client client.Client
	Ctx    context.Context
	Env    *crd.ClowdEnvironment
	Cache  *ObjectCache
	Log    logr.Logger
}

Provider is a struct that holds a client/context and ClowdEnvironment object.

type ResourceIdent

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

type ResourceIdentMulti

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

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

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

NewResourceIdent 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

type ResourceIdentSingle

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

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

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

NewResourceIdent 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

Jump to

Keyboard shortcuts

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