Don't truncate and replace with 'a', update docs
This commit is contained in:
parent
3e68f1c505
commit
c3a00993d0
|
@ -16,17 +16,13 @@ func isalphanumeric(b byte) bool {
|
|||
}
|
||||
|
||||
// Clean up image name by replacing invalid characters with "-"
|
||||
// truncate up to 63 length, convert to a lower case
|
||||
// and converting upper cases to lower cases
|
||||
func templateCleanImageName(s string) string {
|
||||
if reImageFamily.MatchString(s) {
|
||||
return s
|
||||
}
|
||||
b := []byte(strings.ToLower(s))
|
||||
l := 63
|
||||
if len(b) < 63 {
|
||||
l = len(b)
|
||||
}
|
||||
newb := make([]byte, l)
|
||||
newb := make([]byte, len(b))
|
||||
for i := range newb {
|
||||
if isalphanumeric(b[i]) {
|
||||
newb[i] = b[i]
|
||||
|
@ -34,12 +30,6 @@ func templateCleanImageName(s string) string {
|
|||
newb[i] = '-'
|
||||
}
|
||||
}
|
||||
if !('a' <= newb[0] && newb[0] <= 'z') {
|
||||
newb[0] = 'a'
|
||||
}
|
||||
if newb[l-1] == '-' {
|
||||
newb[l-1] = 'a'
|
||||
}
|
||||
return string(newb)
|
||||
}
|
||||
|
||||
|
|
|
@ -19,18 +19,6 @@ func Test_templateCleanImageName(t *testing.T) {
|
|||
origName: "abcde-012345v1.0.0",
|
||||
expected: "abcde-012345v1-0-0",
|
||||
},
|
||||
{
|
||||
origName: "a123456789012345678901234567890123456789012345678901234567890123456789",
|
||||
expected: "a12345678901234567890123456789012345678901234567890123456789012",
|
||||
},
|
||||
{
|
||||
origName: "01234567890123456789012345678901234567890123456789012345678901.",
|
||||
expected: "a1234567890123456789012345678901234567890123456789012345678901a",
|
||||
},
|
||||
{
|
||||
origName: "01234567890123456789012345678901234567890123456789012345678901-",
|
||||
expected: "a1234567890123456789012345678901234567890123456789012345678901a",
|
||||
},
|
||||
}
|
||||
|
||||
for _, v := range vals {
|
||||
|
|
|
@ -53,9 +53,12 @@ Here is a full list of the available functions for reference.
|
|||
#### Specific to Google Compute builders:
|
||||
|
||||
- `clean_image_name` - GCE image names can only contain certain characters and
|
||||
the maximum length is 63. This function will replace illegal characters with a "-" character
|
||||
and truncate a name which exceeds maximum length.
|
||||
Example usage since ":" is not a legal image name is: `{{isotime | clean_image_name}}`.
|
||||
the maximum length is 63. This function will convert upper cases to lower cases
|
||||
and replace illegal characters with a "-" character.
|
||||
Example usage since ":" is not a legal image name is: `"a-{{isotime | clean_image_name}}"` -> `a-2017-10-18t02-06-30z`.
|
||||
|
||||
Note that image name must be a match of regex `(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)`
|
||||
but this function won't truncate and replace with valid character such as 'a' except '-'.
|
||||
|
||||
## Template variables
|
||||
|
||||
|
|
Loading…
Reference in New Issue