Documentation
¶
Overview ¶
Package maps contains utility functions to manage maps.
Index ¶
- func DeSerializeCache(s string) []string
- func Filter[K comparable, V any](m map[K]V, filter FilterType[K]) map[K]V
- func FilteredDeletedAnnotations(annots, templateAnnots map[string]string) map[string]string
- func FilteredDeletedEntries(m1, m2 map[string]string, cache []string) map[string]string
- func FilteredDeletedLabels(annots, labs, templateLabs map[string]string) map[string]string
- func GetNestedField(m map[string]any, path string) (any, error)
- func Merge[K comparable, V any](m1, m2 map[K]V) map[K]V
- func SerializeMap(m map[string]string) string
- func SliceToMap[T comparable](slice []T) map[T]any
- func SmartMergeAnnotations(obj metav1.Object, templateAnnots map[string]string)
- func SmartMergeLabels(obj metav1.Object, templateLabels map[string]string)
- func Sub[K comparable, V any](m1, m2 map[K]V) map[K]V
- func UpdateCache(annots, template map[string]string, cacheKey string) map[string]string
- type FilterType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeSerializeCache ¶ added in v1.0.0
DeSerializeCache splits a serialized map.
func Filter ¶
func Filter[K comparable, V any](m map[K]V, filter FilterType[K]) map[K]V
Filter filters a map, returning a duplicate which contains only the elements matching the filter function.
func FilteredDeletedAnnotations ¶ added in v1.0.0
FilteredDeletedAnnotations returns the annotations of the object after deleting the annotations not present in the template but present in the cached template annotations (e.g., the ones added by the template).
func FilteredDeletedEntries ¶ added in v1.0.0
FilteredDeletedEntries deletes entries of map m1 that are not present in map m2, excluding the ones not stored in a cache of keys.
func FilteredDeletedLabels ¶ added in v1.0.0
FilteredDeletedLabels returns the labels of the object after deleting the labels not present in the template but present in the cached template labels (e.g., the ones added by the template).
func GetNestedField ¶ added in v1.0.0
GetNestedField returns the nested field of a map. Example: GetNestedField(map[string]any{"a": map[string]any{"b": "c"}}, "a.b") returns "c".
func SerializeMap ¶ added in v1.0.0
SerializeMap convert a map in a string of concatenated keys seprated by commas.
func SliceToMap ¶ added in v1.0.0
func SliceToMap[T comparable](slice []T) map[T]any
SliceToMap takes a slice of a generic type and returns a map where the keys are the array elements.
func SmartMergeAnnotations ¶ added in v1.0.0
SmartMergeAnnotations merges annotations from a template map in a map, and remember what annotations were added in the object from the template, storing them in a custom annotation. This allows the function to also delete the annotations that were added by the template previously, but that they are no longer present in the template. This is useful to avoid to accumulate annotations in the object that are not present in the template anymore.
func SmartMergeLabels ¶ added in v1.0.0
SmartMergeLabels merges labels from a template map in a map, and remember what labels were added in the object from the template, storing them in a custom annotation. This allows the function to also delete the labels that were added by the template previously, but that they are no longer present in the template. This is useful to avoid to accumulate labels in the object that are not present in the template anymore.
func Sub ¶
func Sub[K comparable, V any](m1, m2 map[K]V) map[K]V
Sub removes elements of m2 from m1.
Types ¶
type FilterType ¶
type FilterType[K comparable] func(key K) bool
FilterType is a function type used to filter a map.
func FilterBlacklist ¶
func FilterBlacklist[K comparable](blacklist ...K) FilterType[K]
FilterBlacklist returns a filter function returning true if the key is not the blacklist.
func FilterWhitelist ¶
func FilterWhitelist[K comparable](whitelist ...K) FilterType[K]
FilterWhitelist returns a filter function returning true if the key is in the whitelist.