maps

package
v0.11.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package maps contains utility functions to manage maps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeSerializeCache

func DeSerializeCache(s string) []string

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

func FilteredDeletedAnnotations(annots, templateAnnots map[string]string) map[string]string

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

func FilteredDeletedEntries(m1, m2 map[string]string, cache []string) map[string]string

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

func FilteredDeletedLabels(annots, labs, templateLabs map[string]string) map[string]string

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 Merge

func Merge[K comparable, V any](m1, m2 map[K]V) map[K]V

Merge merges two maps.

func SerializeMap

func SerializeMap(m map[string]string) string

SerializeMap convert a map in a string of concatenated keys seprated by commas.

func SmartMergeAnnotations

func SmartMergeAnnotations(obj metav1.Object, templateAnnots map[string]string)

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

func SmartMergeLabels(obj metav1.Object, templateLabels map[string]string)

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.

func UpdateCache

func UpdateCache(annots, template map[string]string, cacheKey string) map[string]string

UpdateCache updates the cache with the latest entries from template.

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.

Jump to

Keyboard shortcuts

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