Skip to content

Commit

Permalink
fix: modify newPvcName function to accept names up to 253 chars long
Browse files Browse the repository at this point in the history
Signed-off-by: Clément Nussbaumer <clement.nussbaumer@postfinance.ch>
  • Loading branch information
clementnuss committed Mar 21, 2024
1 parent 6bc5f4e commit 45c822c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,12 @@ const nameSuffix = "-pvcmigrate"
// TODO: refactor to k8sutil package
func newPvcName(originalName string) string {
candidate := originalName + nameSuffix
if len(candidate) <= 63 {
if len(candidate) <= 253 {
return candidate
}

// remove characters from the middle of the string to reduce the total length to 63 characters
newCandidate := candidate[0:31] + candidate[len(candidate)-32:]
newCandidate := candidate[0:100] + candidate[len(candidate)-153:]
return newCandidate
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/migrate/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3230,16 +3230,16 @@ func Test_newPvcName(t *testing.T) {
want: "abc-pvcmigrate",
},
{
originalName: "very very very long name test with a suffix that might be the only unique part of it 0",
want: "very very very long name test wy unique part of it 0-pvcmigrate",
originalName: "very very very 253longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong name test with a suffix that might be the only unique part of it 0",
want: "very very very 253longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongloonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong name test with a suffix that might be the only unique part of it 0-pvcmigrate",
},
{
originalName: "0 very very very long name test with a prefix that might be the only unique part of it",
want: "0 very very very long name testnly unique part of it-pvcmigrate",
originalName: "0 very very very 253longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong name test with a prefix that might be the only unique part of it",
want: "0 very very very 253longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglongglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong name test with a prefix that might be the only unique part of it-pvcmigrate",
},
{
originalName: "63 character (after suffix) name is untouched paddin",
want: "63 character (after suffix) name is untouched paddin-pvcmigrate",
originalName: "253 character (after suffix) 253longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong name is untouched paddin",
want: "253 character (after suffix) 253longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong name is untouched paddin-pvcmigrate",
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 45c822c

Please sign in to comment.