Skip to content

Commit

Permalink
br: fix comments
Browse files Browse the repository at this point in the history
Signed-off-by: WangLe1321 <[email protected]>
  • Loading branch information
WangLe1321 committed Jul 5, 2023
1 parent 1f0bbd6 commit 1fd716d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 12 additions & 7 deletions pkg/apis/pingcap/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
package v1alpha1

import (
// crypto/md5 is weak cryptographic primitive, but we don't use md5 to encrypt here, so make gosec ignore it
// #nosec
"crypto/md5"
// "crypto/md5"
"fmt"
"hash/fnv"

Expand All @@ -24,9 +25,11 @@ import (
)

const (
// LabelLengthLimit is max character number of label name
// See https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#rfc-1035-label-names
labelLengthLimit = 63
hashSize = 8
LabelLengthLimit = 63
// HashSize is hash length
HashSize = 8
)

// HashContents hashes the contents using FNV hashing. The returned hash will be a safe encoded string to avoid bad words.
Expand Down Expand Up @@ -115,14 +118,16 @@ func GetStorageVolumeNameForTiFlash(index int) StorageVolumeName {
}

// GenValidName guarantees generated name containing at most 63 characters
// md5 is weak cryptographic primitive, but we don't use md5 to encrypt here, so make gosec ignore it
// #nosec
func GenValidName(name string) string {
if len(name) <= labelLengthLimit {
if len(name) <= LabelLengthLimit {
return name
}

prefixLimit := labelLengthLimit - hashSize - 1
hash := fmt.Sprintf("%x", md5.Sum([]byte(name)))[:hashSize]
prefixLimit := LabelLengthLimit - HashSize - 1
/*hash := fmt.Sprintf("%x", md5.Sum([]byte(name)))[:HashSize]
return fmt.Sprintf("%s-%s", name[:prefixLimit], hash)
return fmt.Sprintf("%s-%s", name[:prefixLimit], hash[:0])*/
return name[:prefixLimit]
}
3 changes: 2 additions & 1 deletion pkg/backup/backup/backup_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (bm *backupManager) syncBackupJob(backup *v1alpha1.Backup) error {

if backup.Spec.Mode == v1alpha1.BackupModeVolumeSnapshot {
if v1alpha1.IsBackupFailed(backup) || v1alpha1.IsVolumeBackupFailed(backup) {
// if volume backup failed, we should delete initialize job to prevent GC and pd schedule blocked
// if volume backup failed, we should delete initialize job to resume GC and pd schedule
if err := bm.deleteVolumeBackupInitializeJob(backup); err != nil {
return err
}
Expand Down Expand Up @@ -1000,6 +1000,7 @@ func (bm *backupManager) deleteVolumeBackupInitializeJob(backup *v1alpha1.Backup
backupInitializeJob, err := bm.deps.JobLister.Jobs(ns).Get(backupInitializeJobName)
if err != nil {
if errors.IsNotFound(err) {
klog.Infof("backup %s/%s doesn't find initializing job %s, ignore it", ns, name, backupInitializeJobName)
return nil
}
return fmt.Errorf("backup %s/%s get initializing job %s failed, err: %v",
Expand Down

0 comments on commit 1fd716d

Please sign in to comment.