Skip to content

Commit 8b02ce1

Browse files
committed
CSI Backrestore E2E test
1 parent bab30bf commit 8b02ce1

File tree

4 files changed

+273
-35
lines changed

4 files changed

+273
-35
lines changed

tests/e2e/backup_restore_suite_test.go

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,6 @@ var _ = Describe("AWS backup restore tests", func() {
2323

2424
err = createCredentialsSecret(credData, namespace, credSecretRef)
2525
Expect(err).NotTo(HaveOccurred())
26-
27-
err = vel.Build()
28-
Expect(err).NotTo(HaveOccurred())
29-
30-
err = vel.CreateOrUpdate(&vel.CustomResource.Spec)
31-
Expect(err).NotTo(HaveOccurred())
32-
33-
log.Printf("Waiting for velero pod to be running")
34-
Eventually(isVeleroPodRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
35-
36-
if vel.CustomResource.Spec.EnableRestic == nil || *vel.CustomResource.Spec.EnableRestic {
37-
log.Printf("Waiting for restic pods to be running")
38-
Eventually(areResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
39-
}
40-
41-
if vel.CustomResource.Spec.BackupImages == nil || *vel.CustomResource.Spec.BackupImages {
42-
log.Printf("Waiting for registry pods to be running")
43-
Eventually(areRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
44-
}
4526
})
4627

4728
var _ = AfterEach(func() {
@@ -56,6 +37,7 @@ var _ = Describe("AWS backup restore tests", func() {
5637
ApplicationTemplate string
5738
ApplicationNamespace string
5839
Name string
40+
BackupRestoreType string
5941
PreBackupVerify VerificationFunction
6042
PostRestoreVerify VerificationFunction
6143
MaxK8SVersion *k8sVersion
@@ -64,6 +46,32 @@ var _ = Describe("AWS backup restore tests", func() {
6446

6547
DescribeTable("backup and restore applications",
6648
func(brCase BackupRestoreCase, expectedErr error) {
49+
50+
err := vel.Build(brCase.BackupRestoreType)
51+
Expect(err).NotTo(HaveOccurred())
52+
53+
err = vel.CreateOrUpdate(&vel.CustomResource.Spec)
54+
Expect(err).NotTo(HaveOccurred())
55+
56+
log.Printf("Waiting for velero pod to be running")
57+
Eventually(isVeleroPodRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
58+
59+
if brCase.BackupRestoreType == "restic" {
60+
if vel.CustomResource.Spec.EnableRestic == nil || *vel.CustomResource.Spec.EnableRestic {
61+
log.Printf("Waiting for restic pods to be running")
62+
Eventually(areResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
63+
}
64+
}
65+
if brCase.BackupRestoreType == "csi" {
66+
log.Printf("Creating VolumeSnapshot for CSI backuprestore of %s", brCase.Name)
67+
err = installApplication(vel.Client, "./sample-applications/mssql-persistent/volumeSnapshotClass.yaml")
68+
Expect(err).ToNot(HaveOccurred())
69+
}
70+
71+
if vel.CustomResource.Spec.BackupImages == nil || *vel.CustomResource.Spec.BackupImages {
72+
log.Printf("Waiting for registry pods to be running")
73+
Eventually(areRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
74+
}
6775
if notVersionTarget, reason := NotServerVersionTarget(brCase.MinK8SVersion, brCase.MaxK8SVersion); notVersionTarget {
6876
Skip(reason)
6977
}
@@ -74,7 +82,7 @@ var _ = Describe("AWS backup restore tests", func() {
7482

7583
// install app
7684
log.Printf("Installing application for case %s", brCase.Name)
77-
err := installApplication(vel.Client, brCase.ApplicationTemplate)
85+
err = installApplication(vel.Client, brCase.ApplicationTemplate)
7886
Expect(err).ToNot(HaveOccurred())
7987
// wait for pods to be running
8088
Eventually(areApplicationPodsRunning(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*2, time.Second*5).Should(BeTrue())
@@ -131,11 +139,38 @@ var _ = Describe("AWS backup restore tests", func() {
131139
log.Printf("Uninstalling application for case %s", brCase.Name)
132140
err = uninstallApplication(vel.Client, brCase.ApplicationTemplate)
133141
Expect(err).ToNot(HaveOccurred())
142+
143+
if brCase.BackupRestoreType == "csi" {
144+
log.Printf("Deleting VolumeSnapshot for CSI backuprestore of %s", brCase.Name)
145+
err = uninstallApplication(vel.Client, "./sample-applications/mssql-persistent/volumeSnapshotClass.yaml")
146+
Expect(err).ToNot(HaveOccurred())
147+
}
134148
},
149+
Entry("MSSQL application CSI", BackupRestoreCase{
150+
ApplicationTemplate: "./sample-applications/mssql-persistent/mssql-persistent-csi-template.yaml",
151+
ApplicationNamespace: "mssql-persistent",
152+
Name: "mssql-e2e",
153+
BackupRestoreType: "csi",
154+
PreBackupVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
155+
return nil
156+
}),
157+
PostRestoreVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
158+
// This test confirms that SCC restore logic in our plugin is working
159+
exists, err := doesSCCExist(ocClient, "mssql-persistent-scc")
160+
if err != nil {
161+
return err
162+
}
163+
if !exists {
164+
return errors.New("did not find MSSQL scc after restore")
165+
}
166+
return nil
167+
}),
168+
}, nil),
135169
Entry("MSSQL application", BackupRestoreCase{
136170
ApplicationTemplate: "./sample-applications/mssql-persistent/mssql-persistent-template.yaml",
137171
ApplicationNamespace: "mssql-persistent",
138172
Name: "mssql-e2e",
173+
BackupRestoreType: "restic",
139174
PreBackupVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
140175
return nil
141176
}),
@@ -155,6 +190,7 @@ var _ = Describe("AWS backup restore tests", func() {
155190
ApplicationTemplate: "./sample-applications/parks-app/manifest.yaml",
156191
ApplicationNamespace: "parks-app",
157192
Name: "parks-e2e",
193+
BackupRestoreType: "restic",
158194
PreBackupVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
159195
Eventually(isDCReady(ocClient, "parks-app", "restify"), timeoutMultiplier*time.Minute*5, time.Second*10).Should(BeTrue())
160196
return nil
@@ -168,6 +204,7 @@ var _ = Describe("AWS backup restore tests", func() {
168204
ApplicationTemplate: "./sample-applications/parks-app/manifest4.8.yaml",
169205
ApplicationNamespace: "parks-app",
170206
Name: "parks-e2e",
207+
BackupRestoreType: "restic",
171208
PreBackupVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
172209
Eventually(isDCReady(ocClient, "parks-app", "restify"), timeoutMultiplier*time.Minute*5, time.Second*10).Should(BeTrue())
173210
return nil
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
apiVersion: v1
2+
kind: List
3+
items:
4+
- kind: Namespace
5+
apiVersion: v1
6+
metadata:
7+
name: mssql-persistent
8+
labels:
9+
app: mssql
10+
- apiVersion: v1
11+
kind: Secret
12+
metadata:
13+
name: mssql-secret
14+
namespace: mssql-persistent
15+
labels:
16+
app: mssql
17+
stringData:
18+
mssql-password: P@ssw0rd1!
19+
- apiVersion: v1
20+
kind: ServiceAccount
21+
metadata:
22+
name: mssql-persistent-sa
23+
namespace: mssql-persistent
24+
labels:
25+
component: mssql-persistent
26+
- apiVersion: v1
27+
kind: PersistentVolumeClaim
28+
metadata:
29+
name: mssql-pvc
30+
namespace: mssql-persistent
31+
labels:
32+
app: mssql
33+
spec:
34+
accessModes:
35+
- ReadWriteOnce
36+
resources:
37+
requests:
38+
storage: 10Gi
39+
storageClassName: gp2-csi
40+
- kind: SecurityContextConstraints
41+
apiVersion: security.openshift.io/v1
42+
metadata:
43+
name: mssql-persistent-scc
44+
allowPrivilegeEscalation: true
45+
allowPrivilegedContainer: true
46+
runAsUser:
47+
type: RunAsAny
48+
seLinuxContext:
49+
type: RunAsAny
50+
fsGroup:
51+
type: RunAsAny
52+
supplementalGroups:
53+
type: RunAsAny
54+
volumes:
55+
- '*'
56+
users:
57+
- system:admin
58+
- system:serviceaccount:mssql-persistent:mssql-persistent-sa
59+
- apiVersion: apps.openshift.io/v1
60+
kind: DeploymentConfig
61+
metadata:
62+
name: mssql-deployment
63+
namespace: mssql-persistent
64+
labels:
65+
e2e-app: "true"
66+
app: mssql
67+
spec:
68+
replicas: 1
69+
selector:
70+
name: mssql
71+
strategy:
72+
type: Recreate
73+
template:
74+
metadata:
75+
labels:
76+
e2e-app: "true"
77+
name: mssql
78+
app: mssql
79+
spec:
80+
serviceAccountName: mssql-persistent-sa
81+
containers:
82+
- env:
83+
- name: ACCEPT_EULA
84+
value: "Y"
85+
- name: SA_PASSWORD
86+
valueFrom:
87+
secretKeyRef:
88+
key: mssql-password
89+
name: mssql-secret
90+
image: quay.io/ocpmigrate/mssql-server:latest
91+
imagePullPolicy: Always
92+
name: mssql
93+
securityContext:
94+
privileged: true
95+
ports:
96+
- containerPort: 1433
97+
resources:
98+
limits:
99+
memory: "3Gi"
100+
cpu: "0.5"
101+
requests:
102+
memory: "3Gi"
103+
cpu: "0.5"
104+
volumeMounts:
105+
- mountPath: "/var/opt/mssql/data"
106+
name: mssql-vol
107+
volumes:
108+
- name: mssql-vol
109+
persistentVolumeClaim:
110+
claimName: mssql-pvc
111+
- apiVersion: v1
112+
kind: Service
113+
metadata:
114+
name: mssql-service
115+
namespace: mssql-persistent
116+
spec:
117+
selector:
118+
app: mssql
119+
ports:
120+
- protocol: TCP
121+
port: 1433
122+
targetPort: 1433
123+
type: ClusterIP
124+
- apiVersion: apps/v1
125+
kind: Deployment
126+
metadata:
127+
name: mssql-app-deployment
128+
namespace: mssql-persistent
129+
labels:
130+
e2e-app: "true"
131+
spec:
132+
replicas: 1
133+
selector:
134+
matchLabels:
135+
app: mssql-app
136+
template:
137+
metadata:
138+
labels:
139+
e2e-app: "true"
140+
app: mssql-app
141+
spec:
142+
terminationGracePeriodSeconds: 10
143+
serviceAccountName: mssql-persistent-sa
144+
containers:
145+
- name: mssql-app
146+
image: quay.io/ocpmigrate/mssql-sample-app:microsoft
147+
imagePullPolicy: Always
148+
ports:
149+
- containerPort: 5000
150+
securityContext:
151+
privileged: true
152+
env:
153+
- name: ConnString
154+
value: "Server=mssql-service.mssql-persistent.svc.cluster.local;Database=ProductCatalog;User ID=WebLogin; password=SQLPass1234!"
155+
- apiVersion: v1
156+
kind: Service
157+
metadata:
158+
name: mssql-app-service
159+
namespace: mssql-persistent
160+
spec:
161+
selector:
162+
app: mssql-app
163+
ports:
164+
- name: "tcp"
165+
protocol: TCP
166+
port: 5000
167+
targetPort: 5000
168+
- apiVersion: route.openshift.io/v1
169+
kind: Route
170+
metadata:
171+
name: mssql-app-route
172+
namespace: mssql-persistent
173+
spec:
174+
path: "/"
175+
to:
176+
kind: Service
177+
name: mssql-app-service
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: List
3+
items:
4+
- apiVersion: snapshot.storage.k8s.io/v1
5+
kind: VolumeSnapshotClass
6+
metadata:
7+
name: example-snapclass
8+
labels:
9+
velero.io/csi-volumesnapshot-class: 'true'
10+
annotations:
11+
snapshot.storage.kubernetes.io/is-default-class: 'true'
12+
driver: ebs.csi.aws.com
13+
deletionPolicy: Retain
14+

0 commit comments

Comments
 (0)