Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions tests/e2e/backup_restore_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type BackupRestoreCase struct {
PostRestoreVerify VerificationFunction
SkipVerifyLogs bool // TODO remove
BackupTimeout time.Duration
LabelSelector map[string]string
}

type ApplicationBackupRestoreCase struct {
Expand Down Expand Up @@ -110,7 +111,7 @@ func runApplicationBackupAndRestore(brCase ApplicationBackupRestoreCase, updateL
log.Printf("Installing application for case %s", brCase.Name)
err := lib.InstallApplication(dpaCR.Client, brCase.ApplicationTemplate)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
if brCase.BackupRestoreType == lib.CSI || brCase.BackupRestoreType == lib.CSIDataMover {
if brCase.BackupRestoreType == lib.CSI || brCase.BackupRestoreType == lib.CSIDataMover || brCase.BackupRestoreType == lib.CSILabel {
log.Printf("Creating pvc for case %s", brCase.Name)
var pvcName string
var pvcPath string
Expand Down Expand Up @@ -163,7 +164,10 @@ func runApplicationBackupAndRestore(brCase ApplicationBackupRestoreCase, updateL
}

func runBackup(brCase BackupRestoreCase, backupName string) bool {
nsRequiresResticDCWorkaround, err := lib.NamespaceRequiresResticDCWorkaround(dpaCR.Client, brCase.Namespace)
var nsRequiresResticDCWorkaround bool
var err error

nsRequiresResticDCWorkaround, err = lib.NamespaceRequiresResticDCWorkaround(dpaCR.Client, brCase.Namespace)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

if strings.Contains(brCase.Name, "twovol") {
Expand All @@ -175,8 +179,22 @@ func runBackup(brCase BackupRestoreCase, backupName string) bool {

// create backup
log.Printf("Creating backup %s for case %s", backupName, brCase.Name)
err = lib.CreateBackupForNamespaces(dpaCR.Client, namespace, backupName, []string{brCase.Namespace}, brCase.BackupRestoreType == lib.RESTIC || brCase.BackupRestoreType == lib.KOPIA, brCase.BackupRestoreType == lib.CSIDataMover)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
if brCase.BackupRestoreType != lib.CSILabel {
err = lib.CreateBackupForNamespaces(dpaCR.Client, namespace, backupName, []string{brCase.Namespace}, brCase.BackupRestoreType == lib.RESTIC || brCase.BackupRestoreType == lib.KOPIA, brCase.BackupRestoreType == lib.CSIDataMover)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}

if brCase.BackupRestoreType == lib.CSILabel {
// Extract the first key-value pair from LabelSelector
var labelKey, labelValue string
for k, v := range brCase.LabelSelector {
labelKey = k
labelValue = v
break // Take the first key-value pair
}
err = lib.CreateBackupForLabels(dpaCR.Client, namespace, backupName, labelKey, labelValue, brCase.BackupRestoreType == lib.RESTIC || brCase.BackupRestoreType == lib.KOPIA, brCase.BackupRestoreType == lib.CSIDataMover)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}

// wait for backup to not be running
gomega.Eventually(lib.IsBackupDone(dpaCR.Client, namespace, backupName), brCase.BackupTimeout, time.Second*10).Should(gomega.BeTrue())
Expand Down Expand Up @@ -321,6 +339,18 @@ var _ = ginkgo.Describe("Backup and restore tests", ginkgo.Ordered, func() {
}
runApplicationBackupAndRestore(brCase, updateLastBRcase, updateLastInstallTime)
},
ginkgo.Entry("MySQL-label application CSI", ginkgo.FlakeAttempts(flakeAttempts), ApplicationBackupRestoreCase{
ApplicationTemplate: "./sample-applications/mysql-persistent/mysql-persistent-csi.yaml",
BackupRestoreCase: BackupRestoreCase{
Namespace: "mysql-persistent",
LabelSelector: map[string]string{"app": "todolist"},
Name: "mysql-csi-label-e2e",
BackupRestoreType: lib.CSILabel,
PreBackupVerify: todoListReady(true, false, "mysql"),
PostRestoreVerify: todoListReady(false, false, "mysql"),
BackupTimeout: 20 * time.Minute,
},
}, nil),
ginkgo.Entry("MySQL application CSI", ginkgo.FlakeAttempts(flakeAttempts), ApplicationBackupRestoreCase{
ApplicationTemplate: "./sample-applications/mysql-persistent/mysql-persistent-csi.yaml",
BackupRestoreCase: BackupRestoreCase{
Expand Down
20 changes: 20 additions & 0 deletions tests/e2e/lib/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ func CreateCustomBackupForNamespaces(ocClient client.Client, veleroNamespace, ba
return ocClient.Create(context.Background(), &backup)
}

func CreateBackupForLabels(ocClient client.Client, veleroNamespace, backupName string, labelKey, labelValue string, defaultVolumesToFsBackup bool, snapshotMoveData bool) error {
backup := velero.Backup{
ObjectMeta: metav1.ObjectMeta{
Name: backupName,
Namespace: veleroNamespace,
},
Spec: velero.BackupSpec{
IncludedNamespaces: []string{},
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{
labelKey: labelValue,
},
},
DefaultVolumesToFsBackup: &defaultVolumesToFsBackup,
SnapshotMoveData: &snapshotMoveData,
},
}
return ocClient.Create(context.Background(), &backup)
}

func GetBackup(c client.Client, namespace string, name string) (*velero.Backup, error) {
backup := velero.Backup{}
err := c.Get(context.Background(), client.ObjectKey{
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/lib/dpa_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
RESTIC BackupRestoreType = "restic"
KOPIA BackupRestoreType = "kopia"
NativeSnapshots BackupRestoreType = "native-snapshots"
CSILabel BackupRestoreType = "csi-label"
)

type DpaCustomResource struct {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: velero.io/v1
kind: Backup
metadata:
name: mysql-persistent-labels
namespace: openshift-adp
spec:
labelSelector:
matchLabels:
app: todolist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the label should be unique across different tests and deployments?

This may have consequences if running in parallel:
https://github.com/openshift/oadp-operator/blob/oadp-dev/tests/e2e/sample-applications/mongo-persistent/mongo-persistent-csi.yaml#L42

Secondly how about also using multiple label selectors implemented by (note this is OR operator):
vmware-tanzu/velero#4650

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so mysql specific todolist label?

storageLocation: dpa-sample-1
ttl: 720h0m0s
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ items:
metadata:
name: mysql-persistent
labels:
app: mysql
app: todolist
- apiVersion: v1
kind: ServiceAccount
metadata:
name: mysql-persistent-sa
namespace: mysql-persistent
labels:
component: mysql-persistent
app: todolist
- kind: SecurityContextConstraints
apiVersion: security.openshift.io/v1
metadata:
name: mysql-persistent-scc
labels:
app: todolist
allowPrivilegeEscalation: true
allowPrivilegedContainer: true
runAsUser:
Expand All @@ -41,15 +44,15 @@ items:
name: mysql
namespace: mysql-persistent
labels:
app: mysql
app: todolist
service: mysql
spec:
ports:
- protocol: TCP
name: mysql
port: 3306
selector:
app: mysql
app: todolist
- apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -59,17 +62,18 @@ items:
namespace: mysql-persistent
labels:
e2e-app: "true"
app: todolist
spec:
selector:
matchLabels:
app: mysql
app: todolist
strategy:
type: Recreate
template:
metadata:
labels:
e2e-app: "true"
app: mysql
app: todolist
curl-tool: "true"
spec:
securityContext:
Expand Down Expand Up @@ -192,6 +196,10 @@ items:
metadata:
name: todolist-route
namespace: mysql-persistent
labels:
app: todolist
service: todolist
e2e-app: "true"
spec:
path: "/"
to:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: velero.io/v1
kind: Restore
metadata:
name: mysql-persistent-labels
namespace: openshift-adp
spec:
backupName: mysql-persistent-labels
restorePVs: true