From 1fd716dd2aba17c35ce8d0721f6641c37d385b3c Mon Sep 17 00:00:00 2001 From: WangLe1321 Date: Wed, 5 Jul 2023 18:40:15 +0800 Subject: [PATCH] br: fix comments Signed-off-by: WangLe1321 --- pkg/apis/pingcap/v1alpha1/helpers.go | 19 ++++++++++++------- pkg/backup/backup/backup_manager.go | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/apis/pingcap/v1alpha1/helpers.go b/pkg/apis/pingcap/v1alpha1/helpers.go index 270e3a889c..fa343edbfb 100644 --- a/pkg/apis/pingcap/v1alpha1/helpers.go +++ b/pkg/apis/pingcap/v1alpha1/helpers.go @@ -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" @@ -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. @@ -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] } diff --git a/pkg/backup/backup/backup_manager.go b/pkg/backup/backup/backup_manager.go index 63108d5965..e949d4e418 100644 --- a/pkg/backup/backup/backup_manager.go +++ b/pkg/backup/backup/backup_manager.go @@ -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 } @@ -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",