From a75c7402a9e7f796f67dda62041086afd6e7eec8 Mon Sep 17 00:00:00 2001 From: mattmoor-sockpuppet Date: Mon, 5 Aug 2019 07:16:55 -0700 Subject: [PATCH] Auto-update dependencies (#66) Produced via: `dep ensure -update knative.dev/test-infra knative.dev/pkg` /assign @mattmoor --- Gopkg.lock | 4 ++-- vendor/knative.dev/pkg/kmeta/names.go | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 2fef577e..5d18ea0e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -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" diff --git a/vendor/knative.dev/pkg/kmeta/names.go b/vendor/knative.dev/pkg/kmeta/names.go index 6d5b2184..0e6bea26 100644 --- a/vendor/knative.dev/pkg/kmeta/names.go +++ b/vendor/knative.dev/pkg/kmeta/names.go @@ -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