object

package
v0.36.0-flux.4 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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 FieldPath

func FieldPath(fieldPath []interface{}) string

FieldPath formats a list of KRM field keys as a JSONPath expression. The only valid field keys in KRM are strings (map keys) and ints (list keys). Simple strings (see isSimpleString) will be delimited with a period. Complex strings will be wrapped with square brackets and double quotes. Integers will be wrapped with square brackets. All other types will be formatted best-effort within square brackets.

func GetCRDGroupKind

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

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

InfoToUnstructured transforms the passed info object into unstructured format.

func InfosToUnstructureds

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

InfosToUnstructureds transforms the passed objects in Info format to Unstructured.

func Invalid

func Invalid(fieldPath []interface{}, value interface{}, detail string) *field.Error

Invalid returns a *Error indicating "invalid value". This is used to report malformed values (e.g. failed regex match, too long, out of bounds).

func InvalidType

func InvalidType(fieldPath []interface{}, value interface{}, validTypes string) *field.Error

InvalidType returns a *Error indicating "invalid value type". This is used to report malformed values (e.g. found int, expected string).

func IsCRD

func IsCRD(u *unstructured.Unstructured) bool

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

func IsKindNamespace

func IsKindNamespace(u *unstructured.Unstructured) bool

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

func IsNamespace

func IsNamespace(u *unstructured.Unstructured) bool

IsNamespace returns true if the passed Unstructured object is Namespace in the core (empty string) group.

func IsNamespaced

func IsNamespaced(u *unstructured.Unstructured) bool

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

func LookupResourceScope

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 NestedField

func NestedField(obj map[string]interface{}, fields ...interface{}) (interface{}, bool, error)

NestedField gets a value from a KRM map, if it exists, otherwise nil. Fields can be string (map key) or int (array index).

func NotFound

func NotFound(fieldPath []interface{}, value interface{}) *field.Error

NotFound returns a *Error indicating "value not found". This is used to report failure to find a requested value (e.g. looking up an ID).

func ObjMetadataSetEquals

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 StripKyamlAnnotations

func StripKyamlAnnotations(u *unstructured.Unstructured)

StripKyamlAnnotations removes any path and index annotations from the unstructured resource.

func UnstructuredSetEquals

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

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

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 InvalidAnnotationError

type InvalidAnnotationError struct {
	Annotation string
	Cause      error
}

InvalidAnnotationError represents an invalid annotation. Fields are exposed to allow callers to perform introspection.

func (InvalidAnnotationError) Error

func (iae InvalidAnnotationError) Error() string

func (InvalidAnnotationError) Unwrap

func (iae InvalidAnnotationError) Unwrap() error

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 InfoToObjMeta

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

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

func InfosToObjMetas

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

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

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

func UnstructuredToObjMetadata

func UnstructuredToObjMetadata(obj *unstructured.Unstructured) ObjMetadata

UnstructuredToObjMetadata extracts the identifying information from an Unstructured object and returns it as ObjMetadata object.

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

type ObjMetadataSet []ObjMetadata

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

func FromStringMap

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 ObjMetadataSetFromMap

func ObjMetadataSetFromMap(mapA map[ObjMetadata]struct{}) ObjMetadataSet

ObjMetadataSetFromMap constructs a set from a map

func UnstructuredSetToObjMetadataSet

func UnstructuredSetToObjMetadataSet(objs UnstructuredSet) ObjMetadataSet

UnstructuredSetToObjMetadataSet converts a UnstructuredSet to a ObjMetadataSet.

func (ObjMetadataSet) Contains

func (setA ObjMetadataSet) Contains(id ObjMetadata) bool

Contains checks if the provided ObjMetadata exists in the set.

func (ObjMetadataSet) Diff

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

func (ObjMetadataSet) Equal

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

func (setA ObjMetadataSet) Hash() string

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

func (ObjMetadataSet) Intersection

func (setA ObjMetadataSet) Intersection(setB ObjMetadataSet) ObjMetadataSet

Intersection returns the set of unique objects in both set A and set B.

func (ObjMetadataSet) Remove

func (setA ObjMetadataSet) Remove(obj ObjMetadata) ObjMetadataSet

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

func (ObjMetadataSet) ToMap

func (setA ObjMetadataSet) ToMap() map[ObjMetadata]struct{}

ToMap returns the set as a map, with objMeta keys and empty struct values.

func (ObjMetadataSet) ToStringMap

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

func (setA ObjMetadataSet) Union(setB ObjMetadataSet) ObjMetadataSet

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

func (ObjMetadataSet) Unique

func (setA ObjMetadataSet) Unique() ObjMetadataSet

Unique returns the set with duplicates removed. Order may or may not remain consistent.

type UnknownTypeError

type UnknownTypeError struct {
	GroupVersionKind schema.GroupVersionKind
}

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

func (*UnknownTypeError) Error

func (e *UnknownTypeError) Error() string

type UnstructuredSet

type UnstructuredSet []*unstructured.Unstructured

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

func (UnstructuredSet) Equal

func (setA UnstructuredSet) Equal(setB UnstructuredSet) bool

type YamlStringer

type YamlStringer struct {
	O *unstructured.Unstructured
}

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

func (YamlStringer) String

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