Skip to content

Commit

Permalink
Add unique suffix to build post-hook containers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rhcarvalho committed Mar 31, 2016
1 parent 7af1063 commit 43ad146
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions pkg/build/builder/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg/build/builder/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 43ad146

Please sign in to comment.