From 3c2cfd9a4fdc7afb79503b13beccf55991f66504 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Fri, 1 Sep 2023 07:51:41 +0200 Subject: [PATCH] resource claim controller: separate generated suffix from base When the resource claim name inside the pod had some suffix like "1a" in "resource-1a", the generated name suffix got added directly after that, leading to "my-pod-resource-1ax6zgt". Adding another hyphen makes the result more readable: "my-pod-resource-1a-x6zgt". --- pkg/controller/resourceclaim/controller.go | 2 +- pkg/controller/resourceclaim/controller_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/controller/resourceclaim/controller.go b/pkg/controller/resourceclaim/controller.go index 430a2fab838..16eb7de5ae9 100644 --- a/pkg/controller/resourceclaim/controller.go +++ b/pkg/controller/resourceclaim/controller.go @@ -616,7 +616,7 @@ func (ec *Controller) handleClaim(ctx context.Context, pod *v1.Pod, podClaim v1. annotations = make(map[string]string) } annotations[podResourceClaimAnnotation] = podClaim.Name - generateName := pod.Name + "-" + podClaim.Name + generateName := pod.Name + "-" + podClaim.Name + "-" maxBaseLen := 57 // Leave space for hyphen and 5 random characters in a name with 63 characters. if len(generateName) > maxBaseLen { // We could leave truncation to the apiserver, but as diff --git a/pkg/controller/resourceclaim/controller_test.go b/pkg/controller/resourceclaim/controller_test.go index 6ca1422cee7..b7a98ffa13e 100644 --- a/pkg/controller/resourceclaim/controller_test.go +++ b/pkg/controller/resourceclaim/controller_test.go @@ -62,7 +62,7 @@ var ( testClaimReserved = reserveClaim(testClaimAllocated, testPodWithResource) testClaimReservedTwice = reserveClaim(testClaimReserved, otherTestPod) - generatedTestClaim = makeGeneratedClaim(podResourceClaimName, testPodName+"-"+podResourceClaimName, testNamespace, className, 1, makeOwnerReference(testPodWithResource, true)) + generatedTestClaim = makeGeneratedClaim(podResourceClaimName, testPodName+"-"+podResourceClaimName+"-", testNamespace, className, 1, makeOwnerReference(testPodWithResource, true)) generatedTestClaimAllocated = allocateClaim(generatedTestClaim) generatedTestClaimReserved = reserveClaim(generatedTestClaimAllocated, testPodWithResource)