From 43ad146b2cbc4c0a36d40e8c03d14ca10316fbc9 Mon Sep 17 00:00:00 2001 From: Rodolfo Carvalho Date: Thu, 31 Mar 2016 14:18:49 +0200 Subject: [PATCH] Add unique suffix to build post-hook containers This makes it closer to pkg/kubelet/dockertools.BuildDockerName, as documented and as originally intended. We had removed the suffix during code review, and now agreed that it should be there to avoid bugging users with errors because of a container name clash. --- pkg/build/builder/common.go | 6 ++++-- pkg/build/builder/common_test.go | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/build/builder/common.go b/pkg/build/builder/common.go index 9ccd9360c369..6ebc75443321 100644 --- a/pkg/build/builder/common.go +++ b/pkg/build/builder/common.go @@ -111,12 +111,14 @@ const containerNamePrefix = "openshift" // containerName creates names for Docker containers launched by a build. It is // meant to resemble Kubernetes' pkg/kubelet/dockertools.BuildDockerName. func containerName(strategyName, buildName, namespace, containerPurpose string) string { - return fmt.Sprintf("%s_%s-build_%s_%s_%s", + uid := fmt.Sprintf("%08x", rand.Uint32()) + return fmt.Sprintf("%s_%s-build_%s_%s_%s_%s", containerNamePrefix, strategyName, buildName, namespace, - containerPurpose) + containerPurpose, + uid) } // execPostCommitHook uses the client to execute a command based on the diff --git a/pkg/build/builder/common_test.go b/pkg/build/builder/common_test.go index e1d746018743..98b3cfbb7843 100644 --- a/pkg/build/builder/common_test.go +++ b/pkg/build/builder/common_test.go @@ -94,8 +94,9 @@ func TestRandomBuildTagNoDupes(t *testing.T) { } func TestContainerName(t *testing.T) { + rand.Seed(0) got := containerName("test-strategy", "my-build", "ns", "hook") - want := "openshift_test-strategy-build_my-build_ns_hook" + want := "openshift_test-strategy-build_my-build_ns_hook_f1f85ff5" if got != want { t.Errorf("got %v, want %v", got, want) }