inventory

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2020 License: Apache-2.0 Imports: 14 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddObjsToInventory

func AddObjsToInventory(infos []*resource.Info) error

Adds the metadata of all objects (passed as infos) to the inventory object. Returns an error if a inventory object does not exist, or we are unable to successfully add the metadata to the inventory object; nil otherwise. Each object is in unstructured.Unstructured format.

func ClearInventoryObj

func ClearInventoryObj(infos []*resource.Info) error

ClearInventoryObj finds the inventory object in the list of objects, and sets an empty inventory. Returns error if the inventory object is not Unstructured, the inventory object does not exist, or if we can't set the empty inventory on the inventory object. If successful, returns nil.

func CreateInventoryObj

func CreateInventoryObj(inventory Inventory, resources []*resource.Info) (*resource.Info, error)

CreateInventoryObj creates an inventory object based on a inventory object template. The passed "resources" parameter are applied at the same time as the inventory object, and metadata for each is stored in the inventory object.

func FindInventoryObj

func FindInventoryObj(infos []*resource.Info) (*resource.Info, bool)

FindInventoryObj returns the "Inventory" object (ConfigMap with inventory label) if it exists, and a boolean describing if it was found.

func IsInventoryObject

func IsInventoryObject(obj runtime.Object) bool

IsInventoryObject returns true if the passed object has the inventory label.

func RetrieveObjsFromInventory

func RetrieveObjsFromInventory(infos []*resource.Info) ([]*object.ObjMetadata, error)

RetrieveObjsFromInventoryObj returns a slice of pointers to the object metadata. This function finds the inventory object, then parses the stored resource metadata into ObjMetadata structs. Returns an error if there is a problem parsing the data into ObjMetadata structs, or if the inventory object is not in Unstructured format; nil otherwise. If a inventory object does not exist, or it does not have a "data" map, then returns an empty slice and no error.

func UnionPastObjs

func UnionPastObjs(pastInvs []*resource.Info) ([]object.ObjMetadata, error)

UnionPastObjs takes a set of inventory objects (infos), returning the union of the objects referenced by these inventory objects. Returns an error if any of the passed objects are not inventory objects, or if unable to retrieve the referenced objects from any inventory object.

Types

type ClusterInventoryClient

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

ClusterInventoryClient is a concrete implementation of the InventoryClient interface.

func NewInventoryClient

func NewInventoryClient(factory util.Factory) (*ClusterInventoryClient, error)

NewInventoryClient returns a concrete implementation of the InventoryClient interface or an error.

func (*ClusterInventoryClient) GetPreviousInventoryObjects

func (cic *ClusterInventoryClient) GetPreviousInventoryObjects(currentInv *resource.Info) ([]*resource.Info, error)

GetPreviousInventoryObjects returns the set of inventory objects that have the same label as the current inventory object. Removes the current inventory object from this set. Returns an error if there is a problem retrieving the inventory objects.

func (*ClusterInventoryClient) GetStoredObjRefs

func (cic *ClusterInventoryClient) GetStoredObjRefs(currentInv *resource.Info) ([]object.ObjMetadata, error)

GetStoredObjRefs returns the set of previously applied objects as ObjMetadata, or an error if one occurred. This set of previously applied object references is stored in the inventory objects living in the cluster. Uses information from the current inventory object to find the previously applied inventory objects.

type FakeInventoryClient

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

FakeInventoryClient is a testing implementation of the InventoryClient interface.

func NewFakeInventoryClient

func NewFakeInventoryClient(prevInventories []*resource.Info) *FakeInventoryClient

NewFakeInventoryClient returns a FakeInventoryClient.

func (*FakeInventoryClient) GetPreviousInventoryObjects

func (fic *FakeInventoryClient) GetPreviousInventoryObjects(currentInv *resource.Info) ([]*resource.Info, error)

GetPreviousInventoryObjects returns the hard-coded set of resource infos. This function ensures the fake implements the InventoryClient interface.

func (*FakeInventoryClient) GetStoredObjRefs

func (fic *FakeInventoryClient) GetStoredObjRefs(currentInv *resource.Info) ([]object.ObjMetadata, error)

GetStoredObjRefs returns the union of hard-coded object references stored in the prevInventories.

type Inventory

type Inventory interface {
	// Load retrieves the set of object metadata from the inventory object
	Load() ([]object.ObjMetadata, error)
	// Store the set of object metadata in the inventory object
	Store(objs []object.ObjMetadata) error
	// GetObject returns the object that stores the inventory
	GetObject() (*resource.Info, error)
}

Inventory describes methods necessary for an object which can persist the object metadata for pruning and other group operations.

func WrapInventoryObj

func WrapInventoryObj(info *resource.Info) Inventory

WrapInventoryObj takes a passed ConfigMap (as a resource.Info), wraps it with the InventoryConfigMap and upcasts the wrapper as an the Inventory interface.

type InventoryClient

type InventoryClient interface {
	// GetPreviousInventoryObjects returns the inventory objects (as *resource.Info)
	// that are currently stored in the cluster, or an error if one occurred. Uses
	// information from the current (recently) created inventory object to find
	// the previously applied inventory object in the cluster.
	GetPreviousInventoryObjects(currentInv *resource.Info) ([]*resource.Info, error)
	// GetStoredObjRefs returns the set of previously applied objects as ObjMetadata,
	// or an error if one occurred. This set of previously applied object references
	// is stored in the inventory objects living in the cluster. Uses information
	// from the current inventory object to find the previously applied inventory
	// objects.
	GetStoredObjRefs(currentInv *resource.Info) ([]object.ObjMetadata, error)
}

InventoryClient expresses an interface for retrieving Inventory objects in the clus

type InventoryConfigMap

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

InventoryConfigMap wraps a ConfigMap resource and implements the Inventory interface. This wrapper loads and stores the object metadata (inventory) to and from the wrapped ConfigMap.

func (*InventoryConfigMap) GetObject

func (icm *InventoryConfigMap) GetObject() (*resource.Info, error)

GetObject returns the wrapped object (ConfigMap) as a resource.Info or an error if one occurs.

func (*InventoryConfigMap) Load

func (icm *InventoryConfigMap) Load() ([]object.ObjMetadata, error)

Load is an Inventory interface function returning the set of object metadata from the wrapped ConfigMap, or an error.

func (*InventoryConfigMap) Store

func (icm *InventoryConfigMap) Store(objMetas []object.ObjMetadata) error

Store is an Inventory interface function implemented to store the object metadata in the wrapped ConfigMap. Actual storing happens in "GetObject".

type MultipleInventoryObjError

type MultipleInventoryObjError struct {
	InventoryObjectTemplates []*resource.Info
}

func (MultipleInventoryObjError) Error

type NoInventoryObjError

type NoInventoryObjError struct{}

func (NoInventoryObjError) Error

func (g NoInventoryObjError) Error() string

Jump to

Keyboard shortcuts

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