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

fix(volume): Generate volume name compliant with DNS Label names #975

Merged
merged 2 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
| 🎁
| Add mock test client for dynamic client
| https://github.com/knative/client/pull/972[#972]

| 🐛
| Fix client side volume name generation
| https://github.com/knative/client/pull/975[#975]
|===

## v0.16.0 (2020-07-14)
Expand Down
4 changes: 2 additions & 2 deletions pkg/serving/config_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,13 @@ func GenerateVolumeName(path string) string {
builder := &strings.Builder{}
for idx, r := range path {
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the code to guard against volume names matching the DNS label name restrictions 1, 3, and 4. That is the bullet points, from spec:

Some resource types require their names to follow the DNS label standard as defined in RFC 1123. This means the name must:

1. contain at most 63 characters
2. contain only lowercase alphanumeric characters or '-'
3. start with an alphanumeric character
4. end with an alphanumeric character

There is clearly code to take care of bullet 2 but not the others.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated util to generate volume name to adhere to the requirements

switch {
case unicode.IsLower(r) || unicode.IsDigit(r) || r == '-' || r == '.':
case unicode.IsLower(r) || unicode.IsDigit(r) || r == '-':
builder.WriteRune(r)
case unicode.IsUpper(r):
builder.WriteRune(unicode.ToLower(r))
case r == '/':
navidshaikh marked this conversation as resolved.
Show resolved Hide resolved
if idx != 0 {
builder.WriteRune('.')
builder.WriteRune('-')
}
default:
builder.WriteRune('-')
Expand Down
6 changes: 4 additions & 2 deletions pkg/serving/config_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,13 +670,15 @@ func TestGenerateVolumeName(t *testing.T) {
"/Ab12~`!@#$%^&*()-=_+[]{}|/\\<>,./?:;\"'xZ/",
"",
"/",
"/path.mypath/",
}

expected := []string{
"ab12---------------------.----..-----xz",
"ab12---------------------.----..-----xz.",
"ab12---------------------------------xz",
"ab12---------------------------------xz-",
"",
"",
"path-mypath-",
}

for i := range actual {
Expand Down