Skip to content

Commit d832554

Browse files
committed
e2e
1 parent 1c6e8f6 commit d832554

File tree

3 files changed

+72
-36
lines changed

3 files changed

+72
-36
lines changed

tests/e2e/dpa_deployment_suite_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"k8s.io/apimachinery/pkg/api/resource"
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010

11+
"github.com/google/go-cmp/cmp"
1112
. "github.com/onsi/ginkgo/v2"
1213
. "github.com/onsi/gomega"
1314
oadpv1alpha1 "github.com/openshift/oadp-operator/api/v1alpha1"
@@ -558,6 +559,11 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() {
558559
Eventually(dpaCR.GetNoErr().Status.Conditions[0].Message, timeoutMultiplier*time.Minute*3, time.Second*5).Should(Equal(expectedErr.Error()))
559560
return
560561
}
562+
// Capture logs right after DPA is reconciled for diffing after one minute.
563+
Eventually(dpaCR.GetNoErr().Status.Conditions[0].Type, timeoutMultiplier*time.Minute*3, time.Second*5).Should(Equal("Reconciled"))
564+
timeReconciled := time.Now()
565+
adpLogsAtReconciled, err := GetOpenShiftADPLogs(dpaCR.Namespace)
566+
Expect(err).NotTo(HaveOccurred())
561567
log.Printf("Waiting for velero pod to be running")
562568
Eventually(AreVeleroPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
563569
dpa, err := dpaCR.Get()
@@ -629,6 +635,15 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() {
629635
log.Printf("Waiting for registry pods to be running")
630636
Eventually(AreRegistryDeploymentsAvailable(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
631637
}
638+
// wait at least 1 minute after reconciled
639+
Eventually(func() bool {
640+
//has it been at least 1 minute since reconciled?
641+
return time.Now().After(timeReconciled.Add(time.Minute))
642+
}, timeoutMultiplier*time.Minute*1, time.Second*5).Should(BeTrue())
643+
adpLogsAfterOneMinute, err := GetOpenShiftADPLogs(dpaCR.Namespace)
644+
Expect(err).NotTo(HaveOccurred())
645+
// We expect adp logs to be the same after 1 minute
646+
Expect(cmp.Diff(adpLogsAtReconciled, adpLogsAfterOneMinute)).To(Equal(""))
632647

633648
}, genericTests,
634649
)

tests/e2e/lib/dpa_helpers.go

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package lib
22

33
import (
4-
"bytes"
54
"context"
65
"encoding/json"
76
"errors"
87
"fmt"
9-
"io"
108
"log"
119
"reflect"
1210
"strings"
@@ -249,38 +247,13 @@ func AreVeleroPodsRunning(namespace string) wait.ConditionFunc {
249247
}
250248
}
251249

250+
func GetOpenShiftADPLogs(namespace string) (string, error) {
251+
return GetPodWithPrefixContainerLogs(namespace, "openshift-adp-controller-manager-", "manager")
252+
}
253+
252254
// Returns logs from velero container on velero pod
253-
func getVeleroContainerLogs(namespace string) (string, error) {
254-
podList, err := GetVeleroPods(namespace)
255-
if err != nil {
256-
return "", err
257-
}
258-
clientset, err := setUpClient()
259-
if err != nil {
260-
return "", err
261-
}
262-
var logs string
263-
for _, podInfo := range (*podList).Items {
264-
if !strings.HasPrefix(podInfo.ObjectMeta.Name, "velero-") {
265-
continue
266-
}
267-
podLogOpts := corev1.PodLogOptions{
268-
Container: "velero",
269-
}
270-
req := clientset.CoreV1().Pods(podInfo.Namespace).GetLogs(podInfo.Name, &podLogOpts)
271-
podLogs, err := req.Stream(context.TODO())
272-
if err != nil {
273-
return "", err
274-
}
275-
defer podLogs.Close()
276-
buf := new(bytes.Buffer)
277-
_, err = io.Copy(buf, podLogs)
278-
if err != nil {
279-
return "", err
280-
}
281-
logs = buf.String()
282-
}
283-
return logs, nil
255+
func GetVeleroContainerLogs(namespace string) (string, error) {
256+
return GetPodWithPrefixContainerLogs(namespace, "velero-", "velero")
284257
}
285258

286259
func GetVeleroContainerFailureLogs(namespace string) []string {
@@ -318,7 +291,7 @@ func (v *DpaCustomResource) IsDeleted() wait.ConditionFunc {
318291
}
319292
}
320293

321-
//check if bsl matches the spec
294+
// check if bsl matches the spec
322295
func DoesBSLExist(namespace string, bsl velero.BackupStorageLocationSpec, spec *oadpv1alpha1.DataProtectionApplicationSpec) wait.ConditionFunc {
323296
return func() (bool, error) {
324297
if len(spec.BackupLocations) == 0 {
@@ -335,7 +308,7 @@ func DoesBSLExist(namespace string, bsl velero.BackupStorageLocationSpec, spec *
335308
}
336309
}
337310

338-
//check if vsl matches the spec
311+
// check if vsl matches the spec
339312
func DoesVSLExist(namespace string, vslspec velero.VolumeSnapshotLocationSpec, spec *oadpv1alpha1.DataProtectionApplicationSpec) wait.ConditionFunc {
340313
return func() (bool, error) {
341314

@@ -352,7 +325,7 @@ func DoesVSLExist(namespace string, vslspec velero.VolumeSnapshotLocationSpec, s
352325
}
353326
}
354327

355-
//check velero tolerations
328+
// check velero tolerations
356329
func VerifyVeleroTolerations(namespace string, t []corev1.Toleration) wait.ConditionFunc {
357330
return func() (bool, error) {
358331
clientset, err := setUpClient()

tests/e2e/lib/kube_helpers.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package lib
22

33
import (
4+
"bytes"
45
"context"
6+
"fmt"
7+
"io"
58
"log"
9+
"strings"
610

711
corev1 "k8s.io/api/core/v1"
812
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -208,3 +212,47 @@ func isCredentialsSecretDeleted(namespace string, credSecretRef string) wait.Con
208212
return false, err
209213
}
210214
}
215+
216+
func GetPodWithPrefixContainerLogs(namespace string, podPrefix string, container string) (string, error) {
217+
clientset, err := setUpClient()
218+
if err != nil {
219+
return "", err
220+
}
221+
podList, err := clientset.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{})
222+
if err != nil {
223+
return "", err
224+
}
225+
for _, pod := range podList.Items {
226+
if strings.HasPrefix(pod.Name, podPrefix) {
227+
logs, err := GetPodContainerLogs(namespace, pod.Name, container)
228+
if err != nil {
229+
return "", err
230+
}
231+
return logs, nil
232+
}
233+
}
234+
return "", fmt.Errorf("No pod found with prefix %s", podPrefix)
235+
}
236+
237+
func GetPodContainerLogs(namespace, podname, container string) (string, error) {
238+
clientset, err := setUpClient()
239+
if err != nil {
240+
return "", err
241+
}
242+
req := clientset.CoreV1().Pods(namespace).GetLogs(podname, &corev1.PodLogOptions{
243+
Container: container,
244+
})
245+
podLogs, err := req.Stream(context.Background())
246+
if err != nil {
247+
return "", err
248+
}
249+
defer podLogs.Close()
250+
251+
buf := new(bytes.Buffer)
252+
_, err = io.Copy(buf, podLogs)
253+
if err != nil {
254+
return "", err
255+
}
256+
str := buf.String()
257+
return str, nil
258+
}

0 commit comments

Comments
 (0)