Documentation ¶
Overview ¶
Package truncate provides functions for truncating Kubernetes values in a predictable way offering mildly collision safe values usable in deterministic field searches.
Index ¶
Constants ¶
const ( // LabelNameLength is the max length of a name fragment in a label LabelNameLength = 63 // LabelValueLength is the max length of a label value LabelValueLength = 63 // ResourceNameLength is the max length of a resource name or a label with // optional prefix and name ResourceNameLength = 253 // DefaultSuffixLength is the length of combined separator and checksum // characters that will be used as a truncation suffix in Label and Resource // truncation functions DefaultSuffixLength = 6 )
Variables ¶
This section is empty.
Functions ¶
func LabelName ¶
LabelName predictably truncates the supplied string using label name length restrictions and a uniform distribution suffix based on the string
func LabelValue ¶
LabelValue predictably truncates the supplied string using label value length restrictions and a uniform distribution suffix based on the string
func ResourceName ¶
ResourceName predictably truncates the supplied string using resource name length restrictions and a uniform distribution suffix based on the string
func Truncate ¶
Truncate replaces the suffixLength number of trailing characters from str with a consistent hash fragment based on that string. The suffix will include a leading hyphen.
An error will be returned if the truncation length is less than the suffixLength, or truncation length is greater than sha1Length, or the suffix length is less than 2.
Example: If the base32 sum of a digest of "aaaaaaaaaaa" is "ovo", with a suffix length of 4:
Truncating this string to a length of 11 would result in "aaaaaaaaaaa" Truncating this string to a length of 8 would result in "aaaa-ovo" Truncating this string to a length of 7 would result in "aaa-ovo" Truncating this string to a length of 5 would result in "a-ovo" Truncating this string to a length of 4 would result in "-ovo"
Types ¶
This section is empty.