Skip to content

Commit

Permalink
Container names must end with an alphanumeric character
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Mar 5, 2019
1 parent 7c289d8 commit bcc3e55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pkg/names/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package names

import (
"fmt"

utilrand "k8s.io/apimachinery/pkg/util/rand"
"regexp"
)

// NameGenerator generates names for objects. Some backends may have more information
Expand Down Expand Up @@ -61,5 +61,10 @@ func (simpleNameGenerator) RestrictLength(base string) string {
if len(base) > maxNameLength {
base = base[:maxNameLength]
}
var isLetter = regexp.MustCompile(`^[a-zA-Z]+$`).MatchString

for !isLetter(base[len(base)-1:]) {
base = base[:len(base)-1]
}
return base
}
4 changes: 2 additions & 2 deletions pkg/reconciler/v1alpha1/taskrun/resources/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func TestMakePod(t *testing.T) {
desc: "very-long-step-name",
b: v1alpha1.BuildSpec{
Steps: []corev1.Container{{
Name: "a-sixty-three-character-step-name-to-trigger-max-length-checkxx",
Name: "a-very-long-character-step-name-to-trigger-max-len----and-invalid-characters",
Image: "image",
}},
},
Expand All @@ -196,7 +196,7 @@ func TestMakePod(t *testing.T) {
VolumeMounts: implicitVolumeMounts,
WorkingDir: workspaceDir,
}, {
Name: "build-step-a-sixty-three-character-step-name-to-trigger-max-len",
Name: "build-step-a-very-long-character-step-name-to-trigger-max-len",
Image: "image",
Env: implicitEnvVars,
VolumeMounts: implicitVolumeMounts,
Expand Down

0 comments on commit bcc3e55

Please sign in to comment.