Skip to content

Commit

Permalink
Merge pull request #956 from magicsong/seed
Browse files Browse the repository at this point in the history
add seed to container name
  • Loading branch information
adambkaplan authored Mar 14, 2019
2 parents 1b34d86 + a999b00 commit 2ba8a34
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pkg/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions pkg/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io/ioutil"
"math/rand"
"os"
"path/filepath"
"reflect"
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 2ba8a34

Please sign in to comment.