Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure resource names do not exceed limit of 63 characters #491

Merged
merged 2 commits into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions pkg/apis/pipeline/v1alpha1/artifact_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"strings"

"github.com/knative/build-pipeline/pkg/names"
corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -81,13 +82,13 @@ func (b *ArtifactBucket) GetCopyFromContainerSpec(name, sourcePath, destinationP
envVars, secretVolumeMount := getSecretEnvVarsAndVolumeMounts("bucket", secretVolumeMountPath, b.Secrets)

return []corev1.Container{{
Name: fmt.Sprintf("artifact-dest-mkdir-%s", name),
Name: names.SimpleNameGenerator.GenerateName(fmt.Sprintf("artifact-dest-mkdir-%s", name)),
Image: *bashNoopImage,
Args: []string{
"-args", strings.Join([]string{"mkdir", "-p", destinationPath}, " "),
},
}, {
Name: fmt.Sprintf("artifact-copy-from-%s", name),
Name: names.SimpleNameGenerator.GenerateName(fmt.Sprintf("artifact-copy-from-%s", name)),
Image: *gsutilImage,
Args: args,
Env: envVars,
Expand All @@ -102,7 +103,7 @@ func (b *ArtifactBucket) GetCopyToContainerSpec(name, sourcePath, destinationPat
envVars, secretVolumeMount := getSecretEnvVarsAndVolumeMounts("bucket", secretVolumeMountPath, b.Secrets)

return []corev1.Container{{
Name: fmt.Sprintf("artifact-copy-to-%s", name),
Name: names.SimpleNameGenerator.GenerateName(fmt.Sprintf("artifact-copy-to-%s", name)),
Image: *gsutilImage,
Args: args,
Env: envVars,
Expand All @@ -116,7 +117,7 @@ func (b *ArtifactBucket) GetSecretsVolumes() []corev1.Volume {
volumes := []corev1.Volume{}
for _, sec := range b.Secrets {
volumes = append(volumes, corev1.Volume{
Name: fmt.Sprintf("bucket-secret-volume-%s", sec.SecretName),
Name: names.SimpleNameGenerator.GenerateName(fmt.Sprintf("bucket-secret-%s", sec.SecretName)),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had one thought, maybe overkill tho: we could make a GenerateNamef, something like:

names.SimpleNameGenerator.GenerateNamef("bucket-secret-%s", sec.SecretName)

Since we're so often passing the output of fmt.Sprintf in here anyway 🤷‍♀️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice idea

VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: sec.SecretName,
Expand Down
12 changes: 8 additions & 4 deletions pkg/apis/pipeline/v1alpha1/artifact_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/knative/build-pipeline/test/names"
corev1 "k8s.io/api/core/v1"
)

func TestBucketGetCopyFromContainerSpec(t *testing.T) {
names.TestingSeed()
bucket := ArtifactBucket{
Location: "gs://fake-bucket",
Secrets: []SecretParam{{
Expand All @@ -33,11 +35,11 @@ func TestBucketGetCopyFromContainerSpec(t *testing.T) {
}},
}
want := []corev1.Container{{
Name: "artifact-dest-mkdir-workspace",
Name: "artifact-dest-mkdir-workspace-9l9zj",
Image: "override-with-bash-noop:latest",
Args: []string{"-args", "mkdir -p /workspace/destination"},
}, {
Name: "artifact-copy-from-workspace",
Name: "artifact-copy-from-workspace-mz4c7",
Image: "override-with-gsutil-image:latest",
Args: []string{"-args", "cp -r gs://fake-bucket/src-path/** /workspace/destination"},
Env: []corev1.EnvVar{{Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: "/var/bucketsecret/secret1/serviceaccount"}},
Expand All @@ -51,6 +53,7 @@ func TestBucketGetCopyFromContainerSpec(t *testing.T) {
}

func TestBucketGetCopyToContainerSpec(t *testing.T) {
names.TestingSeed()
bucket := ArtifactBucket{
Location: "gs://fake-bucket",
Secrets: []SecretParam{{
Expand All @@ -60,7 +63,7 @@ func TestBucketGetCopyToContainerSpec(t *testing.T) {
}},
}
want := []corev1.Container{{
Name: "artifact-copy-to-workspace",
Name: "artifact-copy-to-workspace-9l9zj",
Image: "override-with-gsutil-image:latest",
Args: []string{"-args", "cp -r src-path gs://fake-bucket/workspace/destination"},
Env: []corev1.EnvVar{{Name: "GOOGLE_APPLICATION_CREDENTIALS", Value: "/var/bucketsecret/secret1/serviceaccount"}},
Expand All @@ -74,6 +77,7 @@ func TestBucketGetCopyToContainerSpec(t *testing.T) {
}

func TestGetSecretsVolumes(t *testing.T) {
names.TestingSeed()
bucket := ArtifactBucket{
Location: "gs://fake-bucket",
Secrets: []SecretParam{{
Expand All @@ -83,7 +87,7 @@ func TestGetSecretsVolumes(t *testing.T) {
}},
}
want := []corev1.Volume{{
Name: "bucket-secret-volume-secret1",
Name: "bucket-secret-secret1-9l9zj",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "secret1",
Expand Down
9 changes: 5 additions & 4 deletions pkg/apis/pipeline/v1alpha1/artifact_pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"strings"

"github.com/knative/build-pipeline/pkg/names"
corev1 "k8s.io/api/core/v1"
)

Expand Down Expand Up @@ -48,7 +49,7 @@ func (p *ArtifactPVC) StorageBasePath(pr *PipelineRun) string {
// GetCopyFromContainerSpec returns a container used to download artifacts from temporary storage
func (p *ArtifactPVC) GetCopyFromContainerSpec(name, sourcePath, destinationPath string) []corev1.Container {
return []corev1.Container{{
Name: fmt.Sprintf("source-copy-%s", name),
Name: names.SimpleNameGenerator.GenerateName(fmt.Sprintf("source-copy-%s", name)),
Image: *bashNoopImage,
Args: []string{"-args", strings.Join([]string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), destinationPath}, " ")},
}}
Expand All @@ -57,14 +58,14 @@ func (p *ArtifactPVC) GetCopyFromContainerSpec(name, sourcePath, destinationPath
// GetCopyToContainerSpec returns a container used to upload artifacts for temporary storage
func (p *ArtifactPVC) GetCopyToContainerSpec(name, sourcePath, destinationPath string) []corev1.Container {
return []corev1.Container{{
Name: fmt.Sprintf("source-mkdir-%s", name),
Name: names.SimpleNameGenerator.GenerateName(fmt.Sprintf("source-mkdir-%s", name)),
Image: *bashNoopImage,
Args: []string{
"-args", strings.Join([]string{"mkdir", "-p", destinationPath}, " "),
},
VolumeMounts: []corev1.VolumeMount{getPvcMount(p.Name)},
}, {
Name: fmt.Sprintf("source-copy-%s", name),
Name: names.SimpleNameGenerator.GenerateName(fmt.Sprintf("source-copy-%s", name)),
Image: *bashNoopImage,
Args: []string{
"-args", strings.Join([]string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), destinationPath}, " "),
Expand All @@ -83,7 +84,7 @@ func getPvcMount(name string) corev1.VolumeMount {
// CreateDirContainer returns a container step to create a dir
func CreateDirContainer(name, destinationPath string) corev1.Container {
return corev1.Container{
Name: fmt.Sprintf("create-dir-%s", name),
Name: names.SimpleNameGenerator.GenerateName(fmt.Sprintf("create-dir-%s", name)),
Image: *bashNoopImage,
Args: []string{"-args", strings.Join([]string{"mkdir", "-p", destinationPath}, " ")},
}
Expand Down
Loading