inventory

package
v0.23.4 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 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 []*unstructured.Unstructured) *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 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 slice of unstructured.Unstructured objects and splits it into one slice that contains the inventory object templates and another one that contains the remaining resources.

func ValidateNoInventory added in v0.21.1

func ValidateNoInventory(objs []*unstructured.Unstructured) error

ValidateNoInventory takes a slice 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) 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) error

DeleteInventoryObj deletes the inventory object from the cluster.

func (*ClusterInventoryClient) GetClusterInventoryInfo added in v0.22.5

func (cic *ClusterInventoryClient) GetClusterInventoryInfo(inv InventoryInfo) (*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) GetClusterObjs added in v0.18.0

func (cic *ClusterInventoryClient) GetClusterObjs(localInv InventoryInfo) ([]object.ObjMetadata, 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

func (cic *ClusterInventoryClient) Replace(localInv InventoryInfo, objs []object.ObjMetadata) error

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

func (*ClusterInventoryClient) SetDryRunStrategy added in v0.18.0

func (cic *ClusterInventoryClient) SetDryRunStrategy(drs common.DryRunStrategy)

SetDryRun sets whether the inventory client will mutate the inventory object in the cluster.

func (*ClusterInventoryClient) UpdateLabels added in v0.22.5

func (cic *ClusterInventoryClient) UpdateLabels(inv InventoryInfo, labels map[string]string) 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.ObjMetadata)

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.ObjMetadata
	Err  error
}

FakeInventoryClient is a testing implementation of the InventoryClient interface.

func NewFakeInventoryClient

func NewFakeInventoryClient(initObjs []object.ObjMetadata) *FakeInventoryClient

NewFakeInventoryClient returns a FakeInventoryClient.

func (*FakeInventoryClient) ApplyInventoryNamespace added in v0.20.0

func (fic *FakeInventoryClient) ApplyInventoryNamespace(inv *unstructured.Unstructured) 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(inv InventoryInfo) error

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

func (*FakeInventoryClient) GetClusterInventoryInfo added in v0.22.5

func (fic *FakeInventoryClient) GetClusterInventoryInfo(inv InventoryInfo) (*unstructured.Unstructured, error)

func (*FakeInventoryClient) GetClusterObjs added in v0.18.0

func (fic *FakeInventoryClient) GetClusterObjs(inv InventoryInfo) ([]object.ObjMetadata, error)

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 (fic *FakeInventoryClient) Replace(inv InventoryInfo, objs []object.ObjMetadata) error

Replace the stored cluster inventory objs with the passed obj, or an error if one is set up.

func (*FakeInventoryClient) SetDryRunStrategy added in v0.18.0

func (fic *FakeInventoryClient) SetDryRunStrategy(drs common.DryRunStrategy)

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.

func (*FakeInventoryClient) UpdateLabels added in v0.22.5

func (fic *FakeInventoryClient) UpdateLabels(inv InventoryInfo, labels map[string]string) error

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() (*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) ([]object.ObjMetadata, error)
	// Merge applies the union of the passed objects with the currently
	// stored objects in the inventory object. Returns the slice of
	// objects which are a set diff (objects to be pruned). Otherwise,
	// returns an error if one happened.
	Merge(inv InventoryInfo, objs []object.ObjMetadata) ([]object.ObjMetadata, 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.ObjMetadata) error
	// DeleteInventoryObj deletes the passed inventory object from the APIServer.
	DeleteInventoryObj(inv InventoryInfo) error
	// SetDryRunStrategy sets the dry run strategy on whether this we actually mutate.
	SetDryRunStrategy(drs common.DryRunStrategy)
	// ApplyInventoryNamespace applies the Namespace that the inventory object should be in.
	ApplyInventoryNamespace(invNamespace *unstructured.Unstructured) error
	// GetClusterInventoryInfo returns the cluster inventory object.
	GetClusterInventoryInfo(inv InventoryInfo) (*unstructured.Unstructured, error)
	// UpdateLabels updates the labels of the cluster inventory object if it exists.
	UpdateLabels(InventoryInfo, map[string]string) error
}

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

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

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) 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.ObjMetadata) error

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

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
}

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
)

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 []*unstructured.Unstructured
}

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