Skip to content

Commit

Permalink
Limit backup job name to 63 chars, fix #836
Browse files Browse the repository at this point in the history
  • Loading branch information
w33dw0r7d committed Aug 11, 2022
1 parent f0f34ba commit 678260c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/internal/mysqlbackup/mysqlbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ func (b *MysqlBackup) composeBackupURL(base string) string {

// GetNameForJob returns the name of the job
func (b *MysqlBackup) GetNameForJob() string {
return fmt.Sprintf("%s-backup", b.Name)
prefix := b.Name
if len(prefix) >= 56 {
prefix = fmt.Sprintf("%s-%d", prefix[:44], hash(prefix))
}
return fmt.Sprintf("%s-backup", prefix)
}

// GetNameForDeletionJob returns the name for the hard deletion job.
Expand Down
18 changes: 18 additions & 0 deletions pkg/internal/mysqlbackup/mysqlbackup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,22 @@ var _ = Describe("MySQL backup unit tests", func() {
Expect(backup.GetNameForDeletionJob()).To(Equal("not-too-long-backup-name-for-testing-cleanup-job-test-cleanup"))
Expect(len(backup.GetNameForDeletionJob())).To(BeNumerically("<=", 63))
})

It("should generate the correct backup job name", func() {
backup := New(&api.MysqlBackup{
ObjectMeta: metav1.ObjectMeta{
Name: "backup-name",
},
})

Expect(backup.GetNameForJob()).To(Equal("backup-name-backup"))

backup.Name = "super-long-backup-name-for-testing-backup-job-name-generator"
Expect(backup.GetNameForJob()).To(Equal("super-long-backup-name-for-testing-backup-jo-4133418200-backup"))
Expect(len(backup.GetNameForJob())).To(BeNumerically("<=", 63))

backup.Name = "not-too-long-backup-name-for-testing-backup-job-test"
Expect(backup.GetNameForJob()).To(Equal("not-too-long-backup-name-for-testing-backup-job-test-backup"))
Expect(len(backup.GetNameForJob())).To(BeNumerically("<=", 63))
})
})

0 comments on commit 678260c

Please sign in to comment.