Skip to content

Commit

Permalink
fix: invalid job name (#6481)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei authored Jan 18, 2024
1 parent b4ba41c commit 8ec8720
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion controllers/apps/operations/datascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func buildDataScriptJobs(reqCtx intctrlutil.RequestCtx, cli client.Client, clust
randomStr, _ := password.Generate(4, 0, 0, true, false)
jobName := fmt.Sprintf("%s-%s-%s-%s", cluster.Name, "script", ops.Name, randomStr)
if len(jobName) > 63 {
jobName = jobName[:63]
jobName = strings.TrimSuffix(jobName[:63], "-")
}

job := &batchv1.Job{
Expand Down
2 changes: 1 addition & 1 deletion controllers/dataprotection/backuprepo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,7 @@ func randomNameForDerivedObject(repo *dpv1alpha1.BackupRepo, prefix string) stri

func cutName(name string) string {
if len(name) > 63 {
return name[:63]
return strings.TrimSuffix(name[:63], "-")
}
return name
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dataprotection/backup/deleter.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func BuildDeleteBackupFilesJobKey(backup *dpv1alpha1.Backup, isPreDelete bool) c
}
jobName := fmt.Sprintf("%s-%s%s%s", backup.UID[:8], preDeletePrefix, deleteBackupFilesJobNamePrefix, backup.Name)
if len(jobName) > 63 {
jobName = jobName[:63]
jobName = strings.TrimSuffix(jobName[:63], "-")
}
return client.ObjectKey{Namespace: backup.Namespace, Name: jobName}
}
4 changes: 2 additions & 2 deletions pkg/dataprotection/backup/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func GenerateBackupJobName(backup *dpv1alpha1.Backup, prefix string) string {
name := fmt.Sprintf("%s-%s-%s", prefix, backup.Name, backup.UID[:8])
// job name cannot exceed 63 characters for label name limit.
if len(name) > 63 {
return name[:63]
return strings.TrimSuffix(name[:63], "-")
}
return name
}
Expand All @@ -158,7 +158,7 @@ func GenerateBackupJobName(backup *dpv1alpha1.Backup, prefix string) string {
func GenerateCRNameByBackupSchedule(backupSchedule *dpv1alpha1.BackupSchedule, method string) string {
name := fmt.Sprintf("%s-%s", generateUniqueNameWithBackupSchedule(backupSchedule), backupSchedule.Namespace)
if len(name) > 30 {
name = strings.TrimRight(name[:30], "-")
name = strings.TrimSuffix(name[:30], "-")
}
return fmt.Sprintf("%s-%s", name, method)
}
Expand Down

0 comments on commit 8ec8720

Please sign in to comment.