Move 'velero.io/exclude-from-backup' label string to const (#5053)

* move 'velero.io/exclude-from-backup' label name to const

Signed-off-by: Niu Lechuan <lechuan.niu@daocloud.io>

* add changelog file (in changelogs/unreleased) of this PR

Signed-off-by: Niu Lechuan <lechuan.niu@daocloud.io>
This commit is contained in:
niulechuan
2022-07-04 14:31:20 +08:00
committed by GitHub
parent ff556c848b
commit fb897471c0
2 changed files with 8 additions and 2 deletions
+1
View File
@@ -0,0 +1 @@
Move 'velero.io/exclude-from-backup' label string to const
+7 -2
View File
@@ -61,6 +61,11 @@ type itemBackupper struct {
snapshotLocationVolumeSnapshotters map[string]velero.VolumeSnapshotter
}
const (
// veleroExcludeFromBackupLabel labeled item should be exclude by velero in backup job.
veleroExcludeFromBackupLabel = "velero.io/exclude-from-backup"
)
// backupItem backs up an individual item to tarWriter. The item may be excluded based on the
// namespaces IncludesExcludes list.
// In addition to the error return, backupItem also returns a bool indicating whether the item
@@ -78,8 +83,8 @@ func (ib *itemBackupper) backupItem(logger logrus.FieldLogger, obj runtime.Unstr
log = log.WithField("resource", groupResource.String())
log = log.WithField("namespace", namespace)
if metadata.GetLabels()["velero.io/exclude-from-backup"] == "true" {
log.Info("Excluding item because it has label velero.io/exclude-from-backup=true")
if metadata.GetLabels()[veleroExcludeFromBackupLabel] == "true" {
log.Infof("Excluding item because it has label %s=true", veleroExcludeFromBackupLabel)
return false, nil
}