Skip to content

Commit 8b5fffb

Browse files
Vladimir Fidunincndoit18
authored andcommitted
Limit backup job name to 63 chars, fix #836
1 parent d5d4981 commit 8b5fffb

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

pkg/internal/mysqlbackup/mysqlbackup.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ func (b *MysqlBackup) composeBackupURL(base string) string {
7979

8080
// GetNameForJob returns the name of the job
8181
func (b *MysqlBackup) GetNameForJob() string {
82-
return fmt.Sprintf("%s-backup", b.Name)
82+
prefix := b.Name
83+
if len(prefix) >= 56 {
84+
prefix = fmt.Sprintf("%s-%d", prefix[:44], hash(prefix))
85+
}
86+
return fmt.Sprintf("%s-backup", prefix)
8387
}
8488

8589
// GetNameForDeletionJob returns the name for the hard deletion job.

pkg/internal/mysqlbackup/mysqlbackup_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
8-
http://wwb.apache.org/licenses/LICENSE-2.0
8+
http://wwb.apache.org/licenses/LICENSE-2.0
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
@@ -55,4 +55,22 @@ var _ = Describe("MySQL backup unit tests", func() {
5555
Expect(backup.GetNameForDeletionJob()).To(Equal("not-too-long-backup-name-for-testing-cleanup-job-test-cleanup"))
5656
Expect(len(backup.GetNameForDeletionJob())).To(BeNumerically("<=", 63))
5757
})
58+
59+
It("should generate the correct backup job name", func() {
60+
backup := New(&api.MysqlBackup{
61+
ObjectMeta: metav1.ObjectMeta{
62+
Name: "backup-name",
63+
},
64+
})
65+
66+
Expect(backup.GetNameForJob()).To(Equal("backup-name-backup"))
67+
68+
backup.Name = "super-long-backup-name-for-testing-backup-job-name-generator"
69+
Expect(backup.GetNameForJob()).To(Equal("super-long-backup-name-for-testing-backup-jo-4133418200-backup"))
70+
Expect(len(backup.GetNameForJob())).To(BeNumerically("<=", 63))
71+
72+
backup.Name = "not-too-long-backup-name-for-testing-backup-job-test"
73+
Expect(backup.GetNameForJob()).To(Equal("not-too-long-backup-name-for-testing-backup-job-test-backup"))
74+
Expect(len(backup.GetNameForJob())).To(BeNumerically("<=", 63))
75+
})
5876
})

0 commit comments

Comments
 (0)