From 7b5155554b2ff08f938ff3808bace6ad720a66fb Mon Sep 17 00:00:00 2001 From: Ethan Mosbaugh Date: Tue, 10 Dec 2024 15:44:15 -0600 Subject: [PATCH] feat(snapshots): support for orLabelSelectors (#5039) --- pkg/kotsadmsnapshot/backup.go | 3 +++ pkg/kotsadmsnapshot/backup_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/pkg/kotsadmsnapshot/backup.go b/pkg/kotsadmsnapshot/backup.go index 1c3bdfe8ca..477f834960 100644 --- a/pkg/kotsadmsnapshot/backup.go +++ b/pkg/kotsadmsnapshot/backup.go @@ -626,6 +626,9 @@ func mergeAppBackupSpec(backup *velerov1.Backup, appMeta appInstanceBackupMetada // excluded namespaces backup.Spec.ExcludedNamespaces = append(backup.Spec.ExcludedNamespaces, kotskindsBackup.Spec.ExcludedNamespaces...) + // or label selectors + backup.Spec.OrLabelSelectors = append(backup.Spec.OrLabelSelectors, kotskindsBackup.Spec.OrLabelSelectors...) + // annotations if len(kotskindsBackup.ObjectMeta.Annotations) > 0 { if backup.Annotations == nil { diff --git a/pkg/kotsadmsnapshot/backup_test.go b/pkg/kotsadmsnapshot/backup_test.go index 319cf61b0e..fec84bdc8e 100644 --- a/pkg/kotsadmsnapshot/backup_test.go +++ b/pkg/kotsadmsnapshot/backup_test.go @@ -1259,6 +1259,13 @@ func Test_mergeAppBackupSpec(t *testing.T) { Spec: velerov1.BackupSpec{ IncludedNamespaces: []string{"include-namespace-1", "include-namespace-2", "template-isairgap-{{repl IsAirgap }}"}, ExcludedNamespaces: []string{"exclude-namespace-1", "exclude-namespace-2"}, + OrLabelSelectors: []*metav1.LabelSelector{ + { + MatchLabels: map[string]string{ + "app": "app-1", + }, + }, + }, OrderedResources: map[string]string{ "resource-1": "true", "resource-2": "false", @@ -1299,6 +1306,13 @@ func Test_mergeAppBackupSpec(t *testing.T) { StorageLocation: "default", IncludedNamespaces: []string{"kotsadm", "another-namespace-1", "another-namespace-2", "include-namespace-1", "include-namespace-2", "template-isairgap-true"}, ExcludedNamespaces: []string{"exclude-namespace-1", "exclude-namespace-2"}, + OrLabelSelectors: []*metav1.LabelSelector{ + { + MatchLabels: map[string]string{ + "app": "app-1", + }, + }, + }, OrderedResources: map[string]string{ "resource-1": "true", "resource-2": "false", @@ -1431,6 +1445,13 @@ func Test_mergeAppBackupSpec(t *testing.T) { Spec: velerov1.BackupSpec{ IncludedNamespaces: []string{"include-namespace-1", "include-namespace-2", "template-isairgap-{{repl IsAirgap }}"}, ExcludedNamespaces: []string{"exclude-namespace-1", "exclude-namespace-2"}, + OrLabelSelectors: []*metav1.LabelSelector{ + { + MatchLabels: map[string]string{ + "app": "app-1", + }, + }, + }, OrderedResources: map[string]string{ "resource-1": "true", "resource-2": "false", @@ -1471,6 +1492,13 @@ func Test_mergeAppBackupSpec(t *testing.T) { StorageLocation: "default", IncludedNamespaces: []string{"kotsadm", "another-namespace-1", "another-namespace-2", "include-namespace-1", "include-namespace-2", "template-isairgap-true"}, ExcludedNamespaces: []string{"exclude-namespace-1", "exclude-namespace-2"}, + OrLabelSelectors: []*metav1.LabelSelector{ + { + MatchLabels: map[string]string{ + "app": "app-1", + }, + }, + }, OrderedResources: map[string]string{ "resource-1": "true", "resource-2": "false",