mirror of https://github.com/knative/caching.git
Auto-update dependencies (#66)
Produced via: `dep ensure -update knative.dev/test-infra knative.dev/pkg` /assign @mattmoor
This commit is contained in:
parent
9dbdb2f91c
commit
a75c7402a9
|
@ -927,7 +927,7 @@
|
|||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:bb229ac008f2b7ddcd122f857584627de4cf78f31f3001ca79560f48659db88f"
|
||||
digest = "1:a54bc33aee102c303962336ef74981e9c49f4a4a26f411c5bd9f6b6b248fd3c3"
|
||||
name = "knative.dev/pkg"
|
||||
packages = [
|
||||
"apis",
|
||||
|
@ -946,7 +946,7 @@
|
|||
"metrics/metricskey",
|
||||
]
|
||||
pruneopts = "T"
|
||||
revision = "2b848f71969c997809a2dbea8351eaadb23e9bc9"
|
||||
revision = "8a10634b4fa4df6dc450bfd883e85a33e76f2471"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
|
|
@ -26,15 +26,35 @@ import (
|
|||
const (
|
||||
longest = 63
|
||||
md5Len = 32
|
||||
head = longest - md5Len
|
||||
head = longest - md5Len // How much to truncate to fit the hash.
|
||||
)
|
||||
|
||||
// ChildName generates a name for the resource based upon the parent resource and suffix.
|
||||
// If the concatenated name is longer than K8s permits the name is hashed and truncated to permit
|
||||
// construction of the resource, but still keeps it unique.
|
||||
// If the suffix itself is longer than 31 characters, then the whole string will be hashed
|
||||
// and `parent|hash|suffix` will be returned, where parent and suffix will be trimmed to
|
||||
// fit (prefix of parent at most of length 31, and prefix of suffix at most length 30).
|
||||
func ChildName(parent, suffix string) string {
|
||||
n := parent
|
||||
if len(parent) > (longest - len(suffix)) {
|
||||
// If the suffix is longer than the longest allowed suffix, then
|
||||
// we hash the whole combined string and use that as the suffix.
|
||||
if head-len(suffix) <= 0 {
|
||||
h := md5.Sum([]byte(parent + suffix))
|
||||
// 1. trim parent, if needed
|
||||
if head < len(parent) {
|
||||
parent = parent[:head]
|
||||
}
|
||||
// Format the return string, if it's shorter than longest: pad with
|
||||
// beginning of the suffix. This happens, for example, when parent is
|
||||
// short, but the suffix is very long.
|
||||
ret := parent + fmt.Sprintf("%x", h)
|
||||
if d := longest - len(ret); d > 0 {
|
||||
ret += suffix[:d]
|
||||
}
|
||||
return ret
|
||||
}
|
||||
n = fmt.Sprintf("%s%x", parent[:head-len(suffix)], md5.Sum([]byte(parent)))
|
||||
}
|
||||
return n + suffix
|
||||
|
|
Loading…
Reference in New Issue