From 82b062f91d00c879e414cd5b0fbb8a4b0b773cfe Mon Sep 17 00:00:00 2001 From: Rohan Joseph Date: Thu, 23 Jul 2020 00:06:21 +0530 Subject: [PATCH] core: add comment warning to keep k8sutil hashing consistent The name generation utils need to provide consistent outputs across versions so that names generated based on values are consistent and older generated keys are not lost. Signed-off-by: Rohan CJ --- pkg/operator/k8sutil/k8sutil.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/operator/k8sutil/k8sutil.go b/pkg/operator/k8sutil/k8sutil.go index da4e8a858..8bd5c6bab 100644 --- a/pkg/operator/k8sutil/k8sutil.go +++ b/pkg/operator/k8sutil/k8sutil.go @@ -80,6 +80,8 @@ func GetK8SVersion(clientset kubernetes.Interface) (*version.Version, error) { } // Hash stableName computes a stable pseudorandom string suitable for inclusion in a Kubernetes object name from the given seed string. +// Do **NOT** edit this function in a way that would change its output as it needs to +// provide consistent mappings from string to hash accross versions of rook. func Hash(s string) string { h := sha256.Sum256([]byte(s)) return hex.EncodeToString(h[:16]) @@ -91,6 +93,8 @@ func Hash(s string) string { // For more information, see the following resources: // https://stackoverflow.com/a/50451893 // https://stackoverflow.com/a/32294443 +// Do **NOT** edit this function in a way that would change its output as it needs to +// provide consistent mappings from string to hash accross versions of rook. func TruncateNodeName(format, nodeName string) string { if len(nodeName)+len(fmt.Sprintf(format, "")) > validation.DNS1035LabelMaxLength { hashed := Hash(nodeName)