diff --git a/pkg/docker/docker.go b/pkg/docker/docker.go index fada549d0..f42105f4d 100644 --- a/pkg/docker/docker.go +++ b/pkg/docker/docker.go @@ -74,6 +74,8 @@ const containerNamePrefix = "s2i" // containerName creates names for Docker containers launched by S2I. It is // meant to resemble Kubernetes' pkg/kubelet/dockertools.BuildDockerName. func containerName(image string) string { + //Initialize seed + rand.Seed(time.Now().UnixNano()) uid := fmt.Sprintf("%08x", rand.Uint32()) // Replace invalid characters for container name with underscores. image = strings.Map(func(r rune) rune { diff --git a/pkg/docker/docker_test.go b/pkg/docker/docker_test.go index 758983c75..a81c8e813 100644 --- a/pkg/docker/docker_test.go +++ b/pkg/docker/docker_test.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io/ioutil" - "math/rand" "os" "path/filepath" "reflect" @@ -22,11 +21,10 @@ import ( ) func TestContainerName(t *testing.T) { - rand.Seed(0) got := containerName("sub.domain.com:5000/repo:tag@sha256:ffffff") - want := "s2i_sub_domain_com_5000_repo_tag_sha256_ffffff_f1f85ff5" - if got != want { - t.Errorf("got %v, want %v", got, want) + want := "s2i_sub_domain_com_5000_repo_tag_sha256_ffffff" + if !strings.Contains(got, want) { + t.Errorf("want %v is not substring of got %v", want, got) } }