object

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: 17 Imported by: 57

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CoreNamespace   = CoreV1Namespace.GroupKind()
	CoreV1Namespace = corev1.SchemeGroupVersion.WithKind("Namespace")
	ExtensionsCRD   = ExtensionsV1CRD.GroupKind()
	ExtensionsV1CRD = extensionsv1.SchemeGroupVersion.WithKind("CustomResourceDefinition")
)
View Source
var (
	NilObjMetadata = ObjMetadata{}
)
View Source
var RBACGroupKind = map[schema.GroupKind]bool{
	{Group: rbacv1.GroupName, Kind: "Role"}:               true,
	{Group: rbacv1.GroupName, Kind: "ClusterRole"}:        true,
	{Group: rbacv1.GroupName, Kind: "RoleBinding"}:        true,
	{Group: rbacv1.GroupName, Kind: "ClusterRoleBinding"}: true,
}

RBACGroupKind is a map of the RBAC resources. Needed since name validation is different than other k8s resources.

Functions

func GetCRDGroupKind added in v0.26.0

func GetCRDGroupKind(u *unstructured.Unstructured) (schema.GroupKind, bool)

GetCRDGroupKind returns the GroupKind stored in the passed Unstructured CustomResourceDefinition and true if the passed object is a CRD.

func InfoToUnstructured added in v0.21.0

func InfoToUnstructured(info *resource.Info) *unstructured.Unstructured

InfoToUnstructured transforms the passed info object into unstructured format.

func InfosToUnstructureds added in v0.21.0

func InfosToUnstructureds(infos []*resource.Info) []*unstructured.Unstructured

InfosToUnstructureds transforms the passed objects in Info format to Unstructured.

func IsCRD added in v0.26.0

func IsCRD(u *unstructured.Unstructured) bool

IsCRD returns true if the passed Unstructured object has GroupKind == Extensions/CustomResourceDefinition; false otherwise.

func IsKindNamespace added in v0.26.0

func IsKindNamespace(u *unstructured.Unstructured) bool

IsKindNamespace returns true if the passed Unstructured object is GroupKind == Core/Namespace (no version checked); false otherwise.

func IsNamespaced added in v0.26.0

func IsNamespaced(u *unstructured.Unstructured) bool

IsNamespaced returns true if the passed Unstructured object is namespace-scoped (not cluster-scoped); false otherwise.

func LookupResourceScope added in v0.26.0

func LookupResourceScope(u *unstructured.Unstructured, crds []*unstructured.Unstructured, mapper meta.RESTMapper) (meta.RESTScope, error)

LookupResourceScope tries to look up the scope of the type of the provided resource, looking at both the types known to the cluster (through the RESTMapper) and the provided CRDs. If no information about the type can be found, an UnknownTypeError wil be returned.

func ObjMetadataSetEquals added in v0.26.0

func ObjMetadataSetEquals(setA []ObjMetadata, setB []ObjMetadata) bool

UnstructuredSetEquals returns true if the slice of objects in setA equals the slice of objects in setB.

func UnstructuredSetEquals added in v0.26.0

func UnstructuredSetEquals(setA []*unstructured.Unstructured, setB []*unstructured.Unstructured) bool

UnstructuredSetEquals returns true if the slice of objects in setA equals the slice of objects in setB.

func UnstructuredToInfo added in v0.21.0

func UnstructuredToInfo(obj *unstructured.Unstructured) (*resource.Info, error)

UnstructuredToInfo transforms the passed Unstructured object into Info format, or an error if one occurs.

func UnstructuredsToInfos added in v0.21.0

func UnstructuredsToInfos(objs []*unstructured.Unstructured) ([]*resource.Info, error)

UnstructuredsToInfos transforms the passed Unstructured objects into Info format or an error if one occurs.

Types

type MultiValidationError added in v0.26.0

type MultiValidationError struct {
	Errors []*ValidationError
}

MultiValidationError captures validation errors for multiple resources.

func (MultiValidationError) Error added in v0.26.0

func (ae MultiValidationError) Error() string

type ObjMetadata

type ObjMetadata struct {
	Namespace string
	Name      string
	GroupKind schema.GroupKind
}

ObjMetadata organizes and stores the indentifying information for an object. This struct (as a string) is stored in a inventory object to keep track of sets of applied objects.

func CreateObjMetadata

func CreateObjMetadata(namespace string, name string, gk schema.GroupKind) (ObjMetadata, error)

CreateObjMetadata returns an ObjMetadata struct filled with the passed values. This function normalizes and validates the passed fields and returns an error for bad parameters.

func InfoToObjMeta added in v0.8.0

func InfoToObjMeta(info *resource.Info) (ObjMetadata, error)

InfoToObjMeta takes information from the provided info and returns an ObjMetadata that identifies the resource.

func InfosToObjMetas added in v0.8.0

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

InfosToObjMetas returns object metadata (ObjMetadata) for the passed objects (infos); returns an error if one occurs.

func ParseObjMetadata

func ParseObjMetadata(s string) (ObjMetadata, error)

ParseObjMetadata takes a string, splits it into its four fields, and returns an ObjMetadata struct storing the four fields. Example inventory string:

test-namespace_test-name_apps_ReplicaSet

Returns an error if unable to parse and create the ObjMetadata struct.

NOTE: name field can contain double underscore (__), which represents a colon. RBAC resources can have this additional character (:) in their name.

func RuntimeToObjMeta added in v0.22.1

func RuntimeToObjMeta(obj runtime.Object) (ObjMetadata, error)

RuntimeToObjMeta extracts the object metadata information from a runtime.Object and returns it as ObjMetadata.

func UnstructuredToObjMeta added in v0.21.0

func UnstructuredToObjMeta(obj *unstructured.Unstructured) (ObjMetadata, error)

UnstructuredToObjMeta extracts the identifying information from an Unstructured object and returns it as Objmetadata. If the values doesn't pass validation, an error will be returned.

func UnstructuredToObjMetaOrDie added in v0.26.0

func UnstructuredToObjMetaOrDie(obj *unstructured.Unstructured) ObjMetadata

UnstructuredToObjMetaOrDie extracts the identifying information from an Unstructured object and returns it as Objmetadata. If the values doesn't pass validation, the function will panic.

func UnstructuredsToObjMetas added in v0.21.0

func UnstructuredsToObjMetas(objs []*unstructured.Unstructured) ([]ObjMetadata, error)

UnstructuredsToObjMetas converts a slice of unstructureds to a slice of ObjMetadata. If the values for any of the unstructured objects doesn't pass validation, an error will be returned.

func UnstructuredsToObjMetasOrDie added in v0.26.0

func UnstructuredsToObjMetasOrDie(objs []*unstructured.Unstructured) []ObjMetadata

UnstructuredsToObjMetasOrDie converts a slice of unstructureds to a slice of ObjMetadata. If the values for any of the unstructured objects doesn't pass validation, the function will panic.

func (*ObjMetadata) Equals

func (o *ObjMetadata) Equals(other *ObjMetadata) bool

Equals compares two ObjMetadata and returns true if they are equal. This does not contain any special treatment for the extensions API group.

func (ObjMetadata) String

func (o ObjMetadata) String() string

String create a string version of the ObjMetadata struct. For RBAC resources, the "name" field transcodes ":" into double underscore for valid storing as the label of a ConfigMap.

type ObjMetadataSet added in v0.26.0

type ObjMetadataSet []ObjMetadata

ObjMetadataSet is an ordered list of ObjMetadata that acts like an unordered set for comparison purposes.

func FromStringMap added in v0.26.0

func FromStringMap(in map[string]string) (ObjMetadataSet, error)

FromStringMap returns a set from a serializable map, with objMeta keys and empty string values. Errors if parsing fails.

func (ObjMetadataSet) Contains added in v0.26.0

func (setA ObjMetadataSet) Contains(id ObjMetadata) bool

Contains checks if the provided ObjMetadata exists in the set.

func (ObjMetadataSet) Diff added in v0.26.0

Diff returns the set of objects that exist in set A, but not in set B (A - B).

func (ObjMetadataSet) Equal added in v0.26.0

func (setA ObjMetadataSet) Equal(setB ObjMetadataSet) bool

Equal returns true if the two sets contain equivalent objects. Duplicates are ignored. This function satisfies the cmp.Equal interface from github.com/google/go-cmp

func (ObjMetadataSet) Hash added in v0.26.0

func (setA ObjMetadataSet) Hash() (string, error)

Hash the objects in the set by serializing, sorting, concatonating, and hashing the result with the 32-bit FNV-1a algorithm.

func (ObjMetadataSet) Remove added in v0.26.0

func (setA ObjMetadataSet) Remove(obj ObjMetadata) ObjMetadataSet

Remove the object from the set and return the updated set.

func (ObjMetadataSet) ToStringMap added in v0.26.0

func (setA ObjMetadataSet) ToStringMap() map[string]string

ToStringMap returns the set as a serializable map, with objMeta keys and empty string values.

func (ObjMetadataSet) Union added in v0.26.0

func (setA ObjMetadataSet) Union(setB ObjMetadataSet) ObjMetadataSet

Union returns the set of unique objects from the merging of set A and set B.

type UnknownTypeError added in v0.26.0

type UnknownTypeError struct {
	GroupKind schema.GroupKind
}

UnknownTypeError captures information about a type for which no information could be found in the cluster or among the known CRDs.

func (*UnknownTypeError) Error added in v0.26.0

func (e *UnknownTypeError) Error() string

type UnstructuredSet added in v0.26.0

type UnstructuredSet []*unstructured.Unstructured

UnstructuredSet is an ordered list of Unstructured that acts like an unordered set for comparison purposes.

func (UnstructuredSet) Equal added in v0.26.0

func (setA UnstructuredSet) Equal(setB UnstructuredSet) bool

type ValidationError added in v0.26.0

type ValidationError struct {
	GroupVersionKind schema.GroupVersionKind
	Name             string
	Namespace        string
	FieldErrors      field.ErrorList
}

ValidationError captures errors resulting from validation of a resources.

func (*ValidationError) Error added in v0.26.0

func (e *ValidationError) Error() string

type Validator added in v0.26.0

type Validator struct {
	Mapper meta.RESTMapper
}

Validator contains functionality for validating a set of resources prior to being used by the Apply functionality. This imposes some constraint not always required, such as namespaced resources must have the namespace set.

func (*Validator) Validate added in v0.26.0

func (v *Validator) Validate(resources []*unstructured.Unstructured) error

Validate validates the provided resources. A RESTMapper will be used to fetch type information from the live cluster.

type YamlStringer added in v0.26.0

type YamlStringer struct {
	O *unstructured.Unstructured
}

YamlStringer delays YAML marshalling for logging until String() is called.

func (YamlStringer) String added in v0.26.0

func (ys YamlStringer) String() string

String marshals the wrapped object to a YAML string. If serializing errors, the error string will be returned instead. This is primarily for use with verbose logging.

Directories

Path Synopsis
This package provides a object sorting functionality based on the explicit "depends-on" annotation, and implicit object dependencies like namespaces and CRD's.
This package provides a object sorting functionality based on the explicit "depends-on" annotation, and implicit object dependencies like namespaces and CRD's.

Jump to

Keyboard shortcuts

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