Skip to content

Commit

Permalink
apply random name suffix to new build_gcs_resource
Browse files Browse the repository at this point in the history
  • Loading branch information
nader-ziada committed Feb 12, 2019
1 parent 0a09a8e commit 452ac56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
6 changes: 4 additions & 2 deletions pkg/apis/pipeline/v1alpha1/build_gcs_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"strings"

"github.com/knative/build-pipeline/pkg/names"

corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -138,7 +140,7 @@ func (s *BuildGCSResource) GetDownloadContainerSpec() ([]corev1.Container, error

return []corev1.Container{
CreateDirContainer(s.Name, s.DestinationDir), {
Name: fmt.Sprintf("storage-fetch-%s", s.Name),
Name: names.SimpleNameGenerator.GenerateName(fmt.Sprintf("storage-fetch-%s", s.Name)),
Image: *buildGCSFetcherImage,
Args: args,
}}, nil
Expand All @@ -156,7 +158,7 @@ func (s *BuildGCSResource) GetUploadContainerSpec() ([]corev1.Container, error)
args := []string{"--location", s.Location, "--dir", s.DestinationDir}

return []corev1.Container{{
Name: fmt.Sprintf("storage-upload-%s", s.Name),
Name: names.SimpleNameGenerator.GenerateName(fmt.Sprintf("storage-upload-%s", s.Name)),
Image: *buildGCSUploaderImage,
Args: args,
}}, nil
Expand Down
21 changes: 13 additions & 8 deletions pkg/apis/pipeline/v1alpha1/build_gcs_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/knative/build-pipeline/test/names"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -220,13 +221,16 @@ func Test_BuildGCSGetDownloadContainerSpec(t *testing.T) {
DestinationDir: "/workspace",
ArtifactType: "Archive",
},
wantContainers: []corev1.Container{
CreateDirContainer("gcs-valid", "/workspace"), {
Name: "storage-fetch-gcs-valid",
Image: "gcr.io/cloud-builders/gcs-fetcher:latest",
Args: []string{"--type", "Archive", "--location", "gs://some-bucket",
"--dest_dir", "/workspace"},
}},
wantContainers: []corev1.Container{{
Name: "create-dir-gcs-valid-9l9zj",
Image: "override-with-bash-noop:latest",
Args: []string{"-args", "mkdir -p /workspace"},
}, {
Name: "storage-fetch-gcs-valid-mz4c7",
Image: "gcr.io/cloud-builders/gcs-fetcher:latest",
Args: []string{"--type", "Archive", "--location", "gs://some-bucket",
"--dest_dir", "/workspace"},
}},
}, {
name: "invalid no destination directory set",
resource: &BuildGCSResource{
Expand All @@ -238,6 +242,7 @@ func Test_BuildGCSGetDownloadContainerSpec(t *testing.T) {
}}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
names.TestingSeed()
gotContainers, err := tc.resource.GetDownloadContainerSpec()
if tc.wantErr && err == nil {
t.Fatalf("Expected error to be %t but got %v:", tc.wantErr, err)
Expand All @@ -264,7 +269,7 @@ func Test_BuildGCSGetUploadContainerSpec(t *testing.T) {
ArtifactType: "Manifest",
},
wantContainers: []corev1.Container{{
Name: "storage-upload-gcs-valid",
Name: "storage-upload-gcs-valid-9l9zj",
Image: "gcr.io/cloud-builders/gcs-uploader:latest",
Args: []string{"--location", "gs://some-bucket/manifest.json", "--dir", "/workspace"},
}},
Expand Down

0 comments on commit 452ac56

Please sign in to comment.