Skip to content

Commit ea7ccc4

Browse files
fix: simplify E2E code (#1447)
Signed-off-by: Mateus Oliveira <[email protected]>
1 parent 9e8b4f1 commit ea7ccc4

7 files changed

+42
-98
lines changed

Diff for: tests/e2e/backup_restore_suite_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func tearDownBackupAndRestore(brCase BackupRestoreCase, installTime time.Time, r
299299
}
300300
gomega.Expect(err).ToNot(gomega.HaveOccurred())
301301

302-
err = dpaCR.Delete(runTimeClientForSuiteRun)
302+
err = dpaCR.Delete()
303303
gomega.Expect(err).ToNot(gomega.HaveOccurred())
304304
gomega.Eventually(lib.IsNamespaceDeleted(kubernetesClientForSuiteRun, brCase.Namespace), timeoutMultiplier*time.Minute*5, time.Second*5).Should(gomega.BeTrue())
305305
}

Diff for: tests/e2e/dpa_deployment_suite_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ var _ = ginkgov2.Describe("Configuration testing for DPA Custom Resource", func(
104104
gomega.Expect(err).NotTo(gomega.HaveOccurred())
105105
log.Printf("Waiting for velero pod to be running")
106106
gomega.Eventually(lib.AreVeleroPodsRunning(kubernetesClientForSuiteRun, namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(gomega.BeTrue())
107-
dpa, err := dpaCR.Get(runTimeClientForSuiteRun)
107+
dpa, err := dpaCR.Get()
108108
gomega.Expect(err).NotTo(gomega.HaveOccurred())
109109
if len(dpa.Spec.BackupLocations) > 0 {
110110
log.Printf("Checking for bsl spec")
@@ -778,7 +778,7 @@ var _ = ginkgov2.Describe("Configuration testing for DPA Custom Resource", func(
778778
log.Printf("Waiting for velero pod with restic to be running")
779779
gomega.Eventually(lib.AreVeleroPodsRunning(kubernetesClientForSuiteRun, namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(gomega.BeTrue())
780780
log.Printf("Deleting dpa with restic")
781-
err = dpaCR.Delete(runTimeClientForSuiteRun)
781+
err = dpaCR.Delete()
782782
if installCase.WantError {
783783
gomega.Expect(err).To(gomega.HaveOccurred())
784784
} else {
@@ -801,7 +801,7 @@ var _ = ginkgov2.Describe("Configuration testing for DPA Custom Resource", func(
801801
log.Printf("Waiting for velero pod with kopia to be running")
802802
gomega.Eventually(lib.AreVeleroPodsRunning(kubernetesClientForSuiteRun, namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(gomega.BeTrue())
803803
log.Printf("Deleting dpa with kopia")
804-
err = dpaCR.Delete(runTimeClientForSuiteRun)
804+
err = dpaCR.Delete()
805805
if installCase.WantError {
806806
gomega.Expect(err).To(gomega.HaveOccurred())
807807
} else {

Diff for: tests/e2e/e2e_suite_test.go

+23-2
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@ import (
99
"testing"
1010
"time"
1111

12+
volumesnapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
1213
snapshotv1client "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
1314
ginkgov2 "github.com/onsi/ginkgo/v2"
1415
"github.com/onsi/gomega"
16+
openshiftappsv1 "github.com/openshift/api/apps/v1"
17+
openshiftbuildv1 "github.com/openshift/api/build/v1"
18+
openshiftsecurityv1 "github.com/openshift/api/security/v1"
19+
openshifttemplatev1 "github.com/openshift/api/template/v1"
20+
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
21+
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
22+
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
1523
veleroclientset "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned"
24+
corev1 "k8s.io/api/core/v1"
1625
"k8s.io/client-go/dynamic"
1726
"k8s.io/client-go/kubernetes"
1827
"k8s.io/client-go/rest"
1928
"sigs.k8s.io/controller-runtime/pkg/client"
2029
"sigs.k8s.io/controller-runtime/pkg/client/config"
2130

31+
oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1"
2232
"github.com/openshift/oadp-operator/tests/e2e/lib"
2333
)
2434

@@ -130,6 +140,17 @@ var _ = ginkgov2.BeforeSuite(func() {
130140
runTimeClientForSuiteRun, err = client.New(kubeConfig, client.Options{})
131141
gomega.Expect(err).NotTo(gomega.HaveOccurred())
132142

143+
oadpv1alpha1.AddToScheme(runTimeClientForSuiteRun.Scheme())
144+
velerov1.AddToScheme(runTimeClientForSuiteRun.Scheme())
145+
openshiftappsv1.AddToScheme(runTimeClientForSuiteRun.Scheme())
146+
openshiftbuildv1.AddToScheme(runTimeClientForSuiteRun.Scheme())
147+
openshiftsecurityv1.AddToScheme(runTimeClientForSuiteRun.Scheme())
148+
openshifttemplatev1.AddToScheme(runTimeClientForSuiteRun.Scheme())
149+
corev1.AddToScheme(runTimeClientForSuiteRun.Scheme())
150+
volumesnapshotv1.AddToScheme(runTimeClientForSuiteRun.Scheme())
151+
operatorsv1alpha1.AddToScheme(runTimeClientForSuiteRun.Scheme())
152+
operatorsv1.AddToScheme(runTimeClientForSuiteRun.Scheme())
153+
133154
veleroClientForSuiteRun, err = veleroclientset.NewForConfig(kubeConfig)
134155
gomega.Expect(err).NotTo(gomega.HaveOccurred())
135156

@@ -173,7 +194,7 @@ var _ = ginkgov2.AfterSuite(func() {
173194
gomega.Expect(err).ToNot(gomega.HaveOccurred())
174195
err = lib.DeleteSecret(kubernetesClientForSuiteRun, namespace, "bsl-cloud-credentials-"+provider+"-with-carriage-return")
175196
gomega.Expect(err).ToNot(gomega.HaveOccurred())
176-
err = dpaCR.Delete(runTimeClientForSuiteRun)
197+
err = dpaCR.Delete()
177198
gomega.Expect(err).ToNot(gomega.HaveOccurred())
178-
gomega.Eventually(dpaCR.IsDeleted(runTimeClientForSuiteRun), timeoutMultiplier*time.Minute*2, time.Second*5).Should(gomega.BeTrue())
199+
gomega.Eventually(dpaCR.IsDeleted(), timeoutMultiplier*time.Minute*2, time.Second*5).Should(gomega.BeTrue())
179200
})

Diff for: tests/e2e/lib/dpa_helpers.go

+11-45
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/google/go-cmp/cmp"
14-
volumesnapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
1514
ginkgov2 "github.com/onsi/ginkgo/v2"
16-
appsv1 "github.com/openshift/api/apps/v1"
17-
buildv1 "github.com/openshift/api/build/v1"
18-
security "github.com/openshift/api/security/v1"
19-
templatev1 "github.com/openshift/api/template/v1"
20-
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
21-
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
2215
velero "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
2316
corev1 "k8s.io/api/core/v1"
2417
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -172,12 +165,8 @@ func (v *DpaCustomResource) ProviderStorageClassName(e2eRoot string) (string, er
172165
return *pvcList.Items[0].Spec.StorageClassName, nil
173166
}
174167

175-
func (v *DpaCustomResource) Create(c client.Client) error {
176-
err := v.SetClient(c)
177-
if err != nil {
178-
return err
179-
}
180-
err = v.Client.Create(context.Background(), v.CustomResource)
168+
func (v *DpaCustomResource) Create() error {
169+
err := v.Client.Create(context.Background(), v.CustomResource)
181170
if apierrors.IsAlreadyExists(err) {
182171
return errors.New("found unexpected existing Velero CR")
183172
} else if err != nil {
@@ -186,13 +175,9 @@ func (v *DpaCustomResource) Create(c client.Client) error {
186175
return nil
187176
}
188177

189-
func (v *DpaCustomResource) Get(c client.Client) (*oadpv1alpha1.DataProtectionApplication, error) {
190-
err := v.SetClient(c)
191-
if err != nil {
192-
return nil, err
193-
}
178+
func (v *DpaCustomResource) Get() (*oadpv1alpha1.DataProtectionApplication, error) {
194179
vel := oadpv1alpha1.DataProtectionApplication{}
195-
err = v.Client.Get(context.Background(), client.ObjectKey{
180+
err := v.Client.Get(context.Background(), client.ObjectKey{
196181
Namespace: v.Namespace,
197182
Name: v.Name,
198183
}, &vel)
@@ -203,7 +188,7 @@ func (v *DpaCustomResource) Get(c client.Client) (*oadpv1alpha1.DataProtectionAp
203188
}
204189

205190
func (v *DpaCustomResource) GetNoErr(c client.Client) *oadpv1alpha1.DataProtectionApplication {
206-
Dpa, _ := v.Get(c)
191+
Dpa, _ := v.Get()
207192
return Dpa
208193
}
209194

@@ -216,7 +201,7 @@ func (v *DpaCustomResource) CreateOrUpdateWithRetries(c client.Client, spec *oad
216201
cr *oadpv1alpha1.DataProtectionApplication
217202
)
218203
for i := 0; i < retries; i++ {
219-
if cr, err = v.Get(c); apierrors.IsNotFound(err) {
204+
if cr, err = v.Get(); apierrors.IsNotFound(err) {
220205
v.CustomResource = &oadpv1alpha1.DataProtectionApplication{
221206
TypeMeta: metav1.TypeMeta{
222207
Kind: "DataProtectionApplication",
@@ -228,7 +213,7 @@ func (v *DpaCustomResource) CreateOrUpdateWithRetries(c client.Client, spec *oad
228213
},
229214
Spec: *spec.DeepCopy(),
230215
}
231-
return v.Create(c)
216+
return v.Create()
232217
} else if err != nil {
233218
return err
234219
}
@@ -249,30 +234,15 @@ func (v *DpaCustomResource) CreateOrUpdateWithRetries(c client.Client, spec *oad
249234
return err
250235
}
251236

252-
func (v *DpaCustomResource) Delete(c client.Client) error {
253-
err := v.SetClient(c)
254-
if err != nil {
255-
return err
256-
}
257-
err = v.Client.Delete(context.Background(), v.CustomResource)
237+
func (v *DpaCustomResource) Delete() error {
238+
err := v.Client.Delete(context.Background(), v.CustomResource)
258239
if apierrors.IsNotFound(err) {
259240
return nil
260241
}
261242
return err
262243
}
263244

264245
func (v *DpaCustomResource) SetClient(c client.Client) error {
265-
oadpv1alpha1.AddToScheme(c.Scheme())
266-
velero.AddToScheme(c.Scheme())
267-
appsv1.AddToScheme(c.Scheme())
268-
corev1.AddToScheme(c.Scheme())
269-
templatev1.AddToScheme(c.Scheme())
270-
security.AddToScheme(c.Scheme())
271-
volumesnapshotv1.AddToScheme(c.Scheme())
272-
buildv1.AddToScheme(c.Scheme())
273-
operatorsv1alpha1.AddToScheme(c.Scheme())
274-
operatorsv1.AddToScheme(c.Scheme())
275-
276246
v.Client = c
277247
return nil
278248
}
@@ -347,15 +317,11 @@ func GetVeleroContainerFailureLogs(c *kubernetes.Clientset, namespace string) []
347317
return failureArr
348318
}
349319

350-
func (v *DpaCustomResource) IsDeleted(c client.Client) wait.ConditionFunc {
320+
func (v *DpaCustomResource) IsDeleted() wait.ConditionFunc {
351321
return func() (bool, error) {
352-
err := v.SetClient(c)
353-
if err != nil {
354-
return false, err
355-
}
356322
// Check for velero CR in cluster
357323
vel := oadpv1alpha1.DataProtectionApplication{}
358-
err = v.Client.Get(context.Background(), client.ObjectKey{
324+
err := v.Client.Get(context.Background(), client.ObjectKey{
359325
Namespace: v.Namespace,
360326
Name: v.Name,
361327
}, &vel)

Diff for: tests/e2e/lib/plugins_helpers.go

-38
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,15 @@ package lib
22

33
import (
44
"context"
5-
"log"
65

76
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
87
"k8s.io/apimachinery/pkg/util/wait"
98
"k8s.io/client-go/kubernetes"
10-
"sigs.k8s.io/controller-runtime/pkg/client"
119

1210
oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1"
1311
"github.com/openshift/oadp-operator/pkg/credentials"
1412
)
1513

16-
func (d *DpaCustomResource) RemoveVeleroPlugin(c client.Client, string, instanceName string, pluginValues []oadpv1alpha1.DefaultPlugin, removedPlugin string) error {
17-
err := d.SetClient(c)
18-
if err != nil {
19-
return err
20-
}
21-
dpa := &oadpv1alpha1.DataProtectionApplication{}
22-
err = d.Client.Get(context.Background(), client.ObjectKey{
23-
Namespace: d.Namespace,
24-
Name: d.Name,
25-
}, dpa)
26-
if err != nil {
27-
return err
28-
}
29-
// remove plugin from default_plugins
30-
dpa.Spec.Configuration.Velero.DefaultPlugins = pluginValues
31-
32-
err = d.Client.Update(context.Background(), dpa)
33-
if err != nil {
34-
return err
35-
}
36-
log.Printf("%s plugin has been removed\n", removedPlugin)
37-
return nil
38-
}
39-
4014
func DoesPluginExist(c *kubernetes.Clientset, namespace string, plugin oadpv1alpha1.DefaultPlugin) wait.ConditionFunc {
4115
return func() (bool, error) {
4216
veleroDeployment, err := c.AppsV1().Deployments(namespace).Get(context.Background(), "velero", metav1.GetOptions{})
@@ -72,15 +46,3 @@ func DoesCustomPluginExist(c *kubernetes.Clientset, namespace string, plugin oad
7246
return false, err
7347
}
7448
}
75-
76-
func DoesVeleroDeploymentExist(c *kubernetes.Clientset, namespace string, deploymentName string) wait.ConditionFunc {
77-
log.Printf("Waiting for velero deployment to be created...")
78-
return func() (bool, error) {
79-
// Check for deployment
80-
_, err := c.AppsV1().Deployments(namespace).Get(context.Background(), deploymentName, metav1.GetOptions{})
81-
if err != nil {
82-
return false, err
83-
}
84-
return true, nil
85-
}
86-
}

Diff for: tests/e2e/lib/subscription_helpers.go

-5
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ func getOperatorSubscription(c client.Client, namespace, label string) (*Subscri
3838
}
3939

4040
func (d *DpaCustomResource) GetOperatorSubscription(c client.Client, stream StreamSource) (*Subscription, error) {
41-
err := d.SetClient(c)
42-
if err != nil {
43-
return nil, err
44-
}
45-
4641
label := ""
4742
if stream == UPSTREAM {
4843
label = "operators.coreos.com/oadp-operator." + d.Namespace

Diff for: tests/e2e/subscription_suite_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ var _ = ginkgov2.Describe("Subscription Config Suite Test", func() {
2424
}
2525

2626
var _ = ginkgov2.AfterEach(func() {
27-
err := dpaCR.Delete(runTimeClientForSuiteRun)
27+
err := dpaCR.Delete()
2828
gomega.Expect(err).ToNot(gomega.HaveOccurred())
29-
gomega.Eventually(dpaCR.IsDeleted(runTimeClientForSuiteRun), timeoutMultiplier*time.Minute*2, time.Second*5).Should(gomega.BeTrue())
29+
gomega.Eventually(dpaCR.IsDeleted(), timeoutMultiplier*time.Minute*2, time.Second*5).Should(gomega.BeTrue())
3030
})
3131

3232
ginkgov2.DescribeTable("Proxy test table",
@@ -100,7 +100,7 @@ var _ = ginkgov2.Describe("Subscription Config Suite Test", func() {
100100
gomega.Expect(err).NotTo(gomega.HaveOccurred())
101101

102102
log.Printf("Getting velero object")
103-
velero, err := dpaCR.Get(runTimeClientForSuiteRun)
103+
velero, err := dpaCR.Get()
104104
gomega.Expect(err).NotTo(gomega.HaveOccurred())
105105
log.Printf("Waiting for velero pod to be running")
106106
gomega.Eventually(lib.AreVeleroPodsRunning(kubernetesClientForSuiteRun, namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(gomega.BeTrue())
@@ -134,7 +134,7 @@ var _ = ginkgov2.Describe("Subscription Config Suite Test", func() {
134134
}
135135
}
136136
log.Printf("Deleting test Velero")
137-
err = dpaCR.Delete(runTimeClientForSuiteRun)
137+
err = dpaCR.Delete()
138138
gomega.Expect(err).ToNot(gomega.HaveOccurred())
139139
}
140140

0 commit comments

Comments
 (0)