Skip to content

Commit

Permalink
Move 'velero.io/exclude-from-backup' label string to const (#5053)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
niulechuan authored Jul 4, 2022
1 parent ff556c8 commit fb89747
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/5053-niulechuan
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move 'velero.io/exclude-from-backup' label string to const
9 changes: 7 additions & 2 deletions pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit fb89747

Please sign in to comment.