Auto-update dependencies (#66)

Produced via:
  `dep ensure -update knative.dev/test-infra knative.dev/pkg`
/assign @mattmoor
This commit is contained in:
mattmoor-sockpuppet 2019-08-05 07:16:55 -07:00 committed by Knative Prow Robot
parent 9dbdb2f91c
commit a75c7402a9
2 changed files with 23 additions and 3 deletions

4
Gopkg.lock generated
View File

@ -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"

View File

@ -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