Refactor cleanupStaleVeleroLabels to use constants for label keys

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
This commit is contained in:
Tiger Kaovilai
2025-12-19 20:16:44 +07:00
parent 2d8a87fec4
commit 65eaceee0b

View File

@@ -103,27 +103,26 @@ func (a *PVCAction) cleanupStaleVeleroLabels(pvc *corev1api.PersistentVolumeClai
// Clean stale Velero labels from main metadata
if pvc.Labels != nil {
for k, v := range pvc.Labels {
if strings.HasPrefix(k, "velero.io/") || strings.HasPrefix(k, "backup.velero.io/") {
// Only remove labels that are clearly stale from previous operations
shouldRemove := false
// Always remove restore-name labels as these are from previous restores
if k == "velero.io/restore-name" {
if k == v1.RestoreNameLabel {
shouldRemove = true
}
if k == "backup.velero.io/must-include-additional-items" {
if k == v1.MustIncludeAdditionalItemAnnotation {
shouldRemove = true
}
// Remove backup-name labels that don't match current backup
if k == "velero.io/backup-name" && v != backup.Name {
if k == v1.BackupNameLabel && v != backup.Name {
shouldRemove = true
}
// Remove volume-snapshot-name labels from previous CSI backups
// Note: If this backup creates new CSI snapshots, the CSI action will add them back
if k == "velero.io/volume-snapshot-name" {
if k == v1.VolumeSnapshotLabel {
shouldRemove = true
}
@@ -134,4 +133,3 @@ func (a *PVCAction) cleanupStaleVeleroLabels(pvc *corev1api.PersistentVolumeClai
}
}
}
}