inventory

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2021 License: Apache-2.0 Imports: 29 Imported by: 19

Documentation

Index

Constants

View Source
const (
	Empty inventoryIDMatchStatus = iota
	Match
	NoMatch
)

Variables

This section is empty.

Functions

func AddInventoryIDAnnotation added in v0.22.2

func AddInventoryIDAnnotation(obj *unstructured.Unstructured, inv InventoryInfo)

func CanApply added in v0.22.2

func CanApply(inv InventoryInfo, obj *unstructured.Unstructured, policy InventoryPolicy) (bool, error)

func CanPrune added in v0.22.2

func CanPrune(inv InventoryInfo, obj *unstructured.Unstructured, policy InventoryPolicy) bool

func FindInventoryObj

func FindInventoryObj(objs object.UnstructuredSet) *unstructured.Unstructured

FindInventoryObj returns the "Inventory" object (ConfigMap with inventory label) if it exists, or nil if it does not exist.

func InvInfoToConfigMap added in v0.22.0

func InvInfoToConfigMap(inv InventoryInfo) *unstructured.Unstructured

func InventoryIDMatch added in v0.26.0

func InventoryIDMatch(inv InventoryInfo, obj *unstructured.Unstructured) inventoryIDMatchStatus

func IsInventoryObject

func IsInventoryObject(obj *unstructured.Unstructured) bool

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

func SplitUnstructureds added in v0.21.0

splitUnstructureds takes a set of unstructured.Unstructured objects and splits it into one set that contains the inventory object templates and another one that contains the remaining resources.

func ValidateNoInventory added in v0.21.1

func ValidateNoInventory(objs object.UnstructuredSet) error

ValidateNoInventory takes a set of unstructured.Unstructured objects and validates that no inventory object is in the input slice.

Types

type ClusterInventoryClient

type ClusterInventoryClient struct {
	InventoryFactoryFunc InventoryFactoryFunc

	InfoHelper info.InfoHelper
	// contains filtered or unexported fields
}

ClusterInventoryClient is a concrete implementation of the InventoryClient interface.

func NewInventoryClient

func NewInventoryClient(factory cmdutil.Factory,
	invFunc InventoryFactoryFunc,
	invToUnstructuredFunc InventoryToUnstructuredFunc) (*ClusterInventoryClient, error)

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

func (*ClusterInventoryClient) ApplyInventoryNamespace added in v0.20.0

func (cic *ClusterInventoryClient) ApplyInventoryNamespace(obj *unstructured.Unstructured, dryRun common.DryRunStrategy) error

ApplyInventoryNamespace creates the passed namespace if it does not already exist, or returns an error if one happened. NOTE: No error if already exists.

func (*ClusterInventoryClient) DeleteInventoryObj added in v0.18.0

func (cic *ClusterInventoryClient) DeleteInventoryObj(localInv InventoryInfo, dryRun common.DryRunStrategy) error

DeleteInventoryObj deletes the inventory object from the cluster.

func (*ClusterInventoryClient) GetClusterInventoryInfo added in v0.22.5

func (cic *ClusterInventoryClient) GetClusterInventoryInfo(inv InventoryInfo, dryRun common.DryRunStrategy) (*unstructured.Unstructured, error)

getClusterInventoryObj returns a pointer to the cluster inventory object, or an error if one occurred. Returns the cached cluster inventory object if it has been previously retrieved. Uses the ResourceBuilder to retrieve the inventory object in the cluster, using the namespace, group resource, and inventory label. Merges multiple inventory objects into one if it retrieves more than one (this should be very rare).

TODO(seans3): Remove the special case code to merge multiple cluster inventory objects once we've determined that this case is no longer possible.

func (*ClusterInventoryClient) GetClusterInventoryObjs added in v0.25.0

func (cic *ClusterInventoryClient) GetClusterInventoryObjs(inv InventoryInfo) (object.UnstructuredSet, error)

func (*ClusterInventoryClient) GetClusterObjs added in v0.18.0

func (cic *ClusterInventoryClient) GetClusterObjs(localInv InventoryInfo, dryRun common.DryRunStrategy) (object.ObjMetadataSet, error)

GetClusterObjs returns the objects stored in the cluster inventory object, or an error if one occurred.

func (*ClusterInventoryClient) Merge added in v0.18.0

Merge stores the union of the passed objects with the objects currently stored in the cluster inventory object. Retrieves and caches the cluster inventory object. Returns the set differrence of the cluster inventory objects and the currently applied objects. This is the set of objects to prune. Creates the initial cluster inventory object storing the passed objects if an inventory object does not exist. Returns an error if one occurred.

func (*ClusterInventoryClient) Replace added in v0.18.0

Replace stores the passed objects in the cluster inventory object, or an error if one occurred.

type ClusterInventoryClientFactory added in v0.26.0

type ClusterInventoryClientFactory struct {
}

ClusterInventoryClientFactory is a factory that creates instances of ClusterInventoryClient inventory client.

func (ClusterInventoryClientFactory) NewInventoryClient added in v0.26.0

func (ClusterInventoryClientFactory) NewInventoryClient(factory cmdutil.Factory) (InventoryClient, error)

type FakeBuilder added in v0.18.0

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

FakeBuilder encapsulates a resource Builder which will hard-code the return of an inventory object with the encoded past invObjs.

func (*FakeBuilder) GetBuilder added in v0.18.0

func (fb *FakeBuilder) GetBuilder() func() *resource.Builder

Returns the fake resource Builder with the fake client, test restmapper, and the fake category expander.

func (*FakeBuilder) SetInventoryObjs added in v0.18.0

func (fb *FakeBuilder) SetInventoryObjs(objs object.ObjMetadataSet)

SetInventoryObjs sets the objects which will be encoded in an inventory object to be returned when queried for the cluster inventory object.

type FakeInventoryClient

type FakeInventoryClient struct {
	Objs object.ObjMetadataSet
	Err  error
}

FakeInventoryClient is a testing implementation of the InventoryClient interface.

func NewFakeInventoryClient

func NewFakeInventoryClient(initObjs object.ObjMetadataSet) *FakeInventoryClient

NewFakeInventoryClient returns a FakeInventoryClient.

func (*FakeInventoryClient) ApplyInventoryNamespace added in v0.20.0

func (fic *FakeInventoryClient) ApplyInventoryNamespace(*unstructured.Unstructured, common.DryRunStrategy) error

func (*FakeInventoryClient) ClearError added in v0.18.0

func (fic *FakeInventoryClient) ClearError()

ClearError clears the force error

func (*FakeInventoryClient) DeleteInventoryObj added in v0.18.0

func (fic *FakeInventoryClient) DeleteInventoryObj(InventoryInfo, common.DryRunStrategy) error

DeleteInventoryObj returns an error if one is forced; does nothing otherwise.

func (*FakeInventoryClient) GetClusterInventoryInfo added in v0.22.5

func (*FakeInventoryClient) GetClusterInventoryObjs added in v0.25.0

func (fic *FakeInventoryClient) GetClusterInventoryObjs(_ InventoryInfo) (object.UnstructuredSet, error)

func (*FakeInventoryClient) GetClusterObjs added in v0.18.0

GetClusterObjs returns currently stored set of objects.

func (*FakeInventoryClient) Merge added in v0.18.0

Merge stores the passed objects with the current stored cluster inventory objects. Returns the set difference of the current set of objects minus the passed set of objects, or an error if one is set up.

func (*FakeInventoryClient) Replace added in v0.18.0

func (*FakeInventoryClient) SetError added in v0.18.0

func (fic *FakeInventoryClient) SetError(err error)

SetError forces an error on the subsequent client call if it returns an error.

type FakeInventoryClientFactory added in v0.26.0

type FakeInventoryClientFactory object.ObjMetadataSet

func (FakeInventoryClientFactory) NewInventoryClient added in v0.26.0

func (f FakeInventoryClientFactory) NewInventoryClient(factory cmdutil.Factory) (InventoryClient, error)

type Inventory

type Inventory interface {
	// Load retrieves the set of object metadata from the inventory object
	Load() (object.ObjMetadataSet, error)
	// Store the set of object metadata in the inventory object
	Store(objs object.ObjMetadataSet) error
	// GetObject returns the object that stores the inventory
	GetObject() (*unstructured.Unstructured, error)
}

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

func WrapInventoryObj

func WrapInventoryObj(inv *unstructured.Unstructured) 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 {
	// GetCluster 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.
	GetClusterObjs(inv InventoryInfo, dryRun common.DryRunStrategy) (object.ObjMetadataSet, error)
	// Merge applies the union of the passed objects with the currently
	// stored objects in the inventory object. Returns the set of
	// objects which are not in the passed objects (objects to be pruned).
	// Otherwise, returns an error if one happened.
	Merge(inv InventoryInfo, objs object.ObjMetadataSet, dryRun common.DryRunStrategy) (object.ObjMetadataSet, error)
	// Replace replaces the set of objects stored in the inventory
	// object with the passed set of objects, or an error if one occurs.
	Replace(inv InventoryInfo, objs object.ObjMetadataSet, dryRun common.DryRunStrategy) error
	// DeleteInventoryObj deletes the passed inventory object from the APIServer.
	DeleteInventoryObj(inv InventoryInfo, dryRun common.DryRunStrategy) error
	// ApplyInventoryNamespace applies the Namespace that the inventory object should be in.
	ApplyInventoryNamespace(invNamespace *unstructured.Unstructured, dryRun common.DryRunStrategy) error
	// GetClusterInventoryInfo returns the cluster inventory object.
	GetClusterInventoryInfo(inv InventoryInfo, dryRun common.DryRunStrategy) (*unstructured.Unstructured, error)
	// GetInventoryObjs looks up the inventory objects from the cluster.
	GetClusterInventoryObjs(inv InventoryInfo) (object.UnstructuredSet, error)
}

InventoryClient expresses an interface for interacting with objects which store references to objects (inventory objects).

type InventoryClientFactory added in v0.26.0

type InventoryClientFactory interface {
	NewInventoryClient(factory cmdutil.Factory) (InventoryClient, error)
}

InventoryClientFactory is a factory that constructs new InventoryClient instances.

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() (*unstructured.Unstructured, error)

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

func (*InventoryConfigMap) ID added in v0.22.0

func (icm *InventoryConfigMap) ID() string

func (*InventoryConfigMap) Load

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

func (*InventoryConfigMap) Name added in v0.22.0

func (icm *InventoryConfigMap) Name() string

func (*InventoryConfigMap) Namespace added in v0.22.0

func (icm *InventoryConfigMap) Namespace() string

func (*InventoryConfigMap) Store

func (icm *InventoryConfigMap) Store(objMetas object.ObjMetadataSet) error

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

func (*InventoryConfigMap) Strategy added in v0.25.0

func (icm *InventoryConfigMap) Strategy() InventoryStrategy

func (*InventoryConfigMap) UnstructuredInventory added in v0.22.0

func (icm *InventoryConfigMap) UnstructuredInventory() *unstructured.Unstructured

type InventoryFactoryFunc added in v0.18.0

type InventoryFactoryFunc func(*unstructured.Unstructured) Inventory

InventoryFactoryFunc creates the object which implements the Inventory interface from the passed info object.

type InventoryInfo added in v0.22.0

type InventoryInfo interface {
	// Namespace of the inventory object.
	// It should be the value of the field .metadata.namespace.
	Namespace() string

	// Name of the inventory object.
	// It should be the value of the field .metadata.name.
	Name() string

	// ID of the inventory object. It is optional.
	// The Provider contained in the applier should know
	// if the Id is necessary and how to use it for pruning objects.
	ID() string

	Strategy() InventoryStrategy
}

InventoryInfo provides the minimal information for the applier to create, look up and update an inventory. The inventory object can be any type, the Provider in the applier needs to know how to create, look up and update it based on the InventoryInfo.

func WrapInventoryInfoObj added in v0.22.0

func WrapInventoryInfoObj(inv *unstructured.Unstructured) InventoryInfo

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

type InventoryNamespaceInSet added in v0.18.0

type InventoryNamespaceInSet struct {
	Namespace string
}

func (InventoryNamespaceInSet) Error added in v0.18.0

func (g InventoryNamespaceInSet) Error() string

type InventoryOverlapError added in v0.22.2

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

func NewInventoryOverlapError added in v0.22.2

func NewInventoryOverlapError(err error) *InventoryOverlapError

func (*InventoryOverlapError) Error added in v0.22.2

func (e *InventoryOverlapError) Error() string

type InventoryPolicy added in v0.22.2

type InventoryPolicy int

InventoryPolicy defines if an inventory object can take over objects that belong to another inventory object or don't belong to any inventory object. This is done by determining if the apply/prune operation can go through for a resource based on the comparison the inventory-id value in the package and the owning-inventory annotation in the live object.

const (
	// InvnetoryPolicyMustMatch: This policy enforces that the resources being applied can not
	// have any overlap with objects in other inventories or objects that already exist
	// in the cluster but don't belong to an inventory.
	//
	// The apply operation can go through when
	// - A new resources in the package doesn't exist in the cluster
	// - An existing resource in the package doesn't exist in the cluster
	// - An existing resource exist in the cluster. The owning-inventory annotation in the live object
	//   matches with that in the package.
	//
	// The prune operation can go through when
	// - The owning-inventory annotation in the live object match with that
	//   in the package.
	InventoryPolicyMustMatch InventoryPolicy = iota

	// AdoptIfNoInventory: This policy enforces that resources being applied
	// can not have any overlap with objects in other inventories, but are
	// permitted to take ownership of objects that don't belong to any inventories.
	//
	// The apply operation can go through when
	// - New resource in the package doesn't exist in the cluster
	// - If a new resource exist in the cluster, its owning-inventory annotation is empty
	// - Existing resource in the package doesn't exist in the cluster
	// - If existing resource exist in the cluster, its owning-inventory annotation in the live object
	//   is empty
	// - An existing resource exist in the cluster. The owning-inventory annotation in the live object
	//   matches with that in the package.
	//
	// The prune operation can go through when
	// - The owning-inventory annotation in the live object match with that
	//   in the package.
	// - The live object doesn't have the owning-inventory annotation.
	AdoptIfNoInventory

	// AdoptAll: This policy will let the current inventory take ownership of any objects.
	//
	// The apply operation can go through for any resource in the package even if the
	// live object has an unmatched owning-inventory annotation.
	//
	// The prune operation can go through when
	// - The owning-inventory annotation in the live object match or doesn't match with that
	//   in the package.
	// - The live object doesn't have the owning-inventory annotation.
	AdoptAll
)

func (InventoryPolicy) String added in v0.26.0

func (i InventoryPolicy) String() string

type InventoryStrategy added in v0.25.0

type InventoryStrategy string
const (
	NameStrategy  InventoryStrategy = "name"
	LabelStrategy InventoryStrategy = "label"
)

type InventoryToUnstructuredFunc added in v0.22.0

type InventoryToUnstructuredFunc func(InventoryInfo) *unstructured.Unstructured

InventoryToUnstructuredFunc returns the unstructured object for the given InventoryInfo.

type MultipleInventoryObjError

type MultipleInventoryObjError struct {
	InventoryObjectTemplates object.UnstructuredSet
}

func (MultipleInventoryObjError) Error

type NeedAdoptionError added in v0.22.2

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

func NewNeedAdoptionError added in v0.22.2

func NewNeedAdoptionError(err error) *NeedAdoptionError

func (*NeedAdoptionError) Error added in v0.22.2

func (e *NeedAdoptionError) Error() string

type NoInventoryObjError

type NoInventoryObjError struct{}

func (NoInventoryObjError) Error

func (g NoInventoryObjError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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