Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh committed Dec 12, 2024
1 parent b21f5d8 commit 850cb27
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 49 deletions.
48 changes: 28 additions & 20 deletions cmd/installer/cli/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ func Test_isReplicatedBackupRestorable(t *testing.T) {
snapshots.InstanceBackupNameLabel: "app-slug-abcd",
},
Annotations: appendCommonAnnotations(map[string]string{
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupTypeAnnotation: snapshots.InstanceBackupTypeInfra,
snapshots.InstanceBackupCountAnnotation: "2",
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupVersionAnnotation: snapshots.InstanceBackupVersionCurrent,
snapshots.InstanceBackupTypeAnnotation: snapshots.InstanceBackupTypeInfra,
snapshots.InstanceBackupCountAnnotation: "2",
}),
CreationTimestamp: metav1.Time{Time: time.Date(2022, 1, 3, 0, 0, 0, 0, time.UTC)},
},
Expand All @@ -65,9 +66,10 @@ func Test_isReplicatedBackupRestorable(t *testing.T) {
snapshots.InstanceBackupNameLabel: "app-slug-abcd",
},
Annotations: appendCommonAnnotations(map[string]string{
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupTypeAnnotation: snapshots.InstanceBackupTypeApp,
snapshots.InstanceBackupCountAnnotation: "2",
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupVersionAnnotation: snapshots.InstanceBackupVersionCurrent,
snapshots.InstanceBackupTypeAnnotation: snapshots.InstanceBackupTypeApp,
snapshots.InstanceBackupCountAnnotation: "2",
}),
CreationTimestamp: metav1.Time{Time: time.Date(2022, 1, 4, 0, 0, 0, 0, time.UTC)},
},
Expand All @@ -84,7 +86,8 @@ func Test_isReplicatedBackupRestorable(t *testing.T) {
Name: "instance-efgh",
Namespace: "velero",
Annotations: appendCommonAnnotations(map[string]string{
snapshots.BackupIsECAnnotation: "true",
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupAnnotation: "true",
// legacy backups do not have the InstanceBackupTypeAnnotation
}),
CreationTimestamp: metav1.Time{Time: time.Date(2022, 1, 2, 0, 0, 0, 0, time.UTC)},
Expand Down Expand Up @@ -213,9 +216,10 @@ func Test_waitForBackups(t *testing.T) {
snapshots.InstanceBackupNameLabel: "app-slug-abcd",
},
Annotations: appendCommonAnnotations(map[string]string{
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupTypeAnnotation: snapshots.InstanceBackupTypeInfra,
snapshots.InstanceBackupCountAnnotation: "2",
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupVersionAnnotation: snapshots.InstanceBackupVersionCurrent,
snapshots.InstanceBackupTypeAnnotation: snapshots.InstanceBackupTypeInfra,
snapshots.InstanceBackupCountAnnotation: "2",
}),
CreationTimestamp: metav1.Time{Time: time.Date(2022, 1, 3, 0, 0, 0, 0, time.Local)},
},
Expand All @@ -235,9 +239,10 @@ func Test_waitForBackups(t *testing.T) {
snapshots.InstanceBackupNameLabel: "app-slug-abcd",
},
Annotations: appendCommonAnnotations(map[string]string{
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupTypeAnnotation: snapshots.InstanceBackupTypeApp,
snapshots.InstanceBackupCountAnnotation: "2",
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupVersionAnnotation: snapshots.InstanceBackupVersionCurrent,
snapshots.InstanceBackupTypeAnnotation: snapshots.InstanceBackupTypeApp,
snapshots.InstanceBackupCountAnnotation: "2",
}),
CreationTimestamp: metav1.Time{Time: time.Date(2022, 1, 4, 0, 0, 0, 0, time.Local)},
},
Expand All @@ -254,7 +259,8 @@ func Test_waitForBackups(t *testing.T) {
Name: "instance-efgh",
Namespace: "velero",
Annotations: appendCommonAnnotations(map[string]string{
snapshots.BackupIsECAnnotation: "true",
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupAnnotation: "true",
// legacy backups do not have the InstanceBackupTypeAnnotation
}),
CreationTimestamp: metav1.Time{Time: time.Date(2022, 1, 2, 0, 0, 0, 0, time.Local)},
Expand Down Expand Up @@ -378,8 +384,9 @@ func Test_ensureImprovedDrMetadata(t *testing.T) {
"some-other-label": "some-other-value",
},
Annotations: map[string]string{
snapshots.BackupIsECAnnotation: "true",
"some-other-annotation": "some-other-value",
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupAnnotation: "true",
"some-other-annotation": "some-other-value",
},
},
},
Expand Down Expand Up @@ -428,10 +435,11 @@ func Test_ensureImprovedDrMetadata(t *testing.T) {
"some-other-label": "some-other-value",
},
Annotations: map[string]string{
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupTypeAnnotation: snapshots.InstanceBackupTypeApp,
snapshots.InstanceBackupCountAnnotation: "2",
"some-other-annotation": "some-other-value",
snapshots.BackupIsECAnnotation: "true",
snapshots.InstanceBackupVersionAnnotation: snapshots.InstanceBackupVersionCurrent,
snapshots.InstanceBackupTypeAnnotation: snapshots.InstanceBackupTypeApp,
snapshots.InstanceBackupCountAnnotation: "2",
"some-other-annotation": "some-other-value",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion e2e/scripts/check-post-restore-newdr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ main() {
echo "restore hook init container not found"
exit 1
fi
echo "found restore hook"
echo "found restore hook init container"
}

main "$@"
36 changes: 36 additions & 0 deletions pkg/snapshots/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ const (
// BackupIsECAnnotation is the annotation used to store if the backup is from an EC install.
BackupIsECAnnotation = "kots.io/embedded-cluster"

// InstanceBackupAnnotation is the annotation used to indicate that a backup is a legacy
// instance backup.
InstanceBackupAnnotation = "kots.io/instance"

// InstanceBackupVersionAnnotation is the annotation used to store the version of the backup
// for an instance (DR) backup.
InstanceBackupVersionAnnotation = "replicated.com/disaster-recovery-version"
// InstanceBackupVersion1 indicates that the backup is of version 1.
InstanceBackupVersion1 = "1"
// InstanceBackupVersionCurrent is the current backup version. When future breaking changes are
// introduced, we can increment this number on backup creation.
InstanceBackupVersionCurrent = InstanceBackupVersion1

// InstanceBackupNameLabel is the label used to store the name of the backup for an instance
// backup. This property is used to group backups together.
InstanceBackupNameLabel = "replicated.com/backup-name"
Expand Down Expand Up @@ -198,6 +211,26 @@ func (b ReplicatedBackup) GetAnnotation(key string) (string, bool) {
return "", false
}

// IsInstanceBackup returns true if the backup is an instance backup.
func IsInstanceBackup(veleroBackup velerov1.Backup) bool {
if GetInstanceBackupVersion(veleroBackup) != "" {
return true
}
if val, ok := veleroBackup.GetAnnotations()[InstanceBackupAnnotation]; ok {
return val == "true"
}
return false
}

// GetInstanceBackupVersion returns the version of the backup from the velero backup object
// annotation.
func GetInstanceBackupVersion(veleroBackup velerov1.Backup) string {
if val, ok := veleroBackup.GetAnnotations()[InstanceBackupVersionAnnotation]; ok {
return val
}
return ""
}

// GetInstanceBackupType returns the type of the backup from the velero backup object annotation.
// This can be either "infra", "app", or "legacy".
func GetInstanceBackupType(backup velerov1.Backup) string {
Expand Down Expand Up @@ -235,6 +268,9 @@ func groupBackupsByName(backups []velerov1.Backup) []ReplicatedBackup {
if backup.Annotations[BackupIsECAnnotation] != "true" {
continue
}
if !IsInstanceBackup(backup) {
continue
}
found := false
backupName := getBackupName(backup)
for i := range groupedBackups {
Expand Down
Loading

0 comments on commit 850cb27

Please sign in to comment.