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 Merge[K comparable, V any](m1, m2 map[K]V) map[K]V
- func SerializeMap(m map[string]string) string
- 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 ¶
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 ¶
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 ¶
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 ¶
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 SerializeMap ¶
SerializeMap convert a map in a string of concatenated keys seprated by commas.
func SmartMergeAnnotations ¶
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 ¶
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.