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 b29c401 commit 9adde1f
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 11 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
4 changes: 3 additions & 1 deletion pkg/reconciler/v1alpha1/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ func TestReconcileWithTimeout(t *testing.T) {
}

func TestReconcilePropagateLabels(t *testing.T) {
names.TestingSeed()

ps := []*v1alpha1.Pipeline{tb.Pipeline("test-pipeline", "foo", tb.PipelineSpec(
tb.PipelineTask("hello-world-1", "hello-world"),
))}
Expand Down Expand Up @@ -632,7 +634,7 @@ func TestReconcilePropagateLabels(t *testing.T) {
if actual == nil {
t.Errorf("Expected a TaskRun to be created, but it wasn't.")
}
expectedTaskRun := tb.TaskRun("test-pipeline-run-with-labels-hello-world-1", "foo",
expectedTaskRun := tb.TaskRun("test-pipeline-run-with-labels-hello-world-1-9l9zj", "foo",
tb.TaskRunOwnerReference("PipelineRun", "test-pipeline-run-with-labels",
tb.OwnerReferenceAPIVersion("pipeline.knative.dev/v1alpha1"),
tb.Controller, tb.BlockOwnerDeletion,
Expand Down
4 changes: 4 additions & 0 deletions test/artifact_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1"
tb "github.com/knative/build-pipeline/test/builder"
"github.com/knative/build-pipeline/test/names"
knativetest "github.com/knative/pkg/test"
"github.com/knative/pkg/test/logging"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -54,6 +55,9 @@ func TestStorageBucketPipelineRun(t *testing.T) {
knativetest.CleanupOnInterrupt(func() { tearDown(t, logger, c, namespace) }, logger)
defer tearDown(t, logger, c, namespace)

// to use fixed seed for testing name after the namespace is created
names.TestingSeed()

bucketName := fmt.Sprintf("build-pipeline-test-%s-%d", namespace, time.Now().Unix())

logger.Infof("Creating Secret %s", bucketSecretName)
Expand Down
4 changes: 4 additions & 0 deletions test/cluster_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1"
tb "github.com/knative/build-pipeline/test/builder"
"github.com/knative/build-pipeline/test/names"
knativetest "github.com/knative/pkg/test"
"github.com/knative/pkg/test/logging"
corev1 "k8s.io/api/core/v1"
Expand All @@ -40,6 +41,9 @@ func TestClusterResource(t *testing.T) {
knativetest.CleanupOnInterrupt(func() { tearDown(t, logger, c, namespace) }, logger)
defer tearDown(t, logger, c, namespace)

// to use fixed seed for testing name after the namespace is created
names.TestingSeed()

logger.Infof("Creating secret %s", secretName)
if _, err := c.KubeClient.Kube.CoreV1().Secrets(namespace).Create(getClusterResourceTaskSecret(namespace, secretName)); err != nil {
t.Fatalf("Failed to create Secret `%s`: %s", secretName, err)
Expand Down
4 changes: 4 additions & 0 deletions test/helm_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/knative/build-pipeline/pkg/names"
tb "github.com/knative/build-pipeline/test/builder"
testnames "github.com/knative/build-pipeline/test/names"
knativetest "github.com/knative/pkg/test"
"github.com/knative/pkg/test/logging"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -61,6 +62,9 @@ func TestHelmDeployPipelineRun(t *testing.T) {
knativetest.CleanupOnInterrupt(func() { tearDown(t, logger, c, namespace) }, logger)
defer tearDown(t, logger, c, namespace)

// to use fixed seed for testing name after the namespace is created
testnames.TestingSeed()

logger.Infof("Creating Git PipelineResource %s", sourceResourceName)
if _, err := c.PipelineResourceClient.Create(getGoHelloworldGitResource(namespace)); err != nil {
t.Fatalf("Failed to create Pipeline Resource `%s`: %s", sourceResourceName, err)
Expand Down
4 changes: 4 additions & 0 deletions test/kaniko_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (

"github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1"
tb "github.com/knative/build-pipeline/test/builder"
"github.com/knative/build-pipeline/test/names"
)

const (
Expand Down Expand Up @@ -136,6 +137,9 @@ func TestKanikoTaskRun(t *testing.T) {
knativetest.CleanupOnInterrupt(func() { tearDown(t, logger, c, namespace) }, logger)
defer tearDown(t, logger, c, namespace)

// to use fixed seed for testing name after the namespace is created
names.TestingSeed()

hasSecretConfig, err := createSecret(c.KubeClient, namespace)
if err != nil {
t.Fatalf("Expected to create kaniko creds: %v", err)
Expand Down
4 changes: 4 additions & 0 deletions test/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/knative/build-pipeline/pkg/apis/pipeline"
tb "github.com/knative/build-pipeline/test/builder"
"github.com/knative/build-pipeline/test/names"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
knativetest "github.com/knative/pkg/test"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -134,6 +135,9 @@ func TestPipelineRun(t *testing.T) {
knativetest.CleanupOnInterrupt(func() { tearDown(t, logger, c, namespace) }, logger)
defer tearDown(t, logger, c, namespace)

// to use fixed seed for testing name after the namespace is created
names.TestingSeed()

logger.Infof("Setting up test resources for %q test in namespace %s", td.name, namespace)
td.testSetup(t, c, namespace, i)

Expand Down
4 changes: 4 additions & 0 deletions test/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/knative/build-pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/knative/build-pipeline/pkg/reconciler/v1alpha1/pipelinerun/resources"
tb "github.com/knative/build-pipeline/test/builder"
"github.com/knative/build-pipeline/test/names"
duckv1alpha1 "github.com/knative/pkg/apis/duck/v1alpha1"
knativetest "github.com/knative/pkg/test"
"github.com/knative/pkg/test/logging"
Expand All @@ -41,6 +42,9 @@ func TestPipelineRunTimeout(t *testing.T) {
knativetest.CleanupOnInterrupt(func() { tearDown(t, logger, c, namespace) }, logger)
defer tearDown(t, logger, c, namespace)

// to use fixed seed for testing name after the namespace is created
names.TestingSeed()

logger.Infof("Creating Task in namespace %s", namespace)
task := tb.Task("banana", namespace, tb.TaskSpec(
tb.Step("foo", "busybox", tb.Command("/bin/sh"), tb.Args("-c", "sleep 10"))))
Expand Down

0 comments on commit 9adde1f

Please sign in to comment.