diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index 00a1b30d..e89103e5 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -31,8 +31,11 @@ import ( . "github.com/onsi/gomega" otypes "github.com/onsi/gomega/types" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/watch" clientgoscheme "k8s.io/client-go/kubernetes/scheme" clientgoretry "k8s.io/client-go/util/retry" @@ -55,7 +58,7 @@ import ( // These tests use Ginkgo (BDD-style Go testing framework). Refer to // http://onsi.github.io/ginkgo/ to learn more about Ginkgo. -var k8sClient client.Client +var k8sClient client.WithWatch var ctx context.Context var log = logf.Log @@ -106,7 +109,7 @@ var _ = SynchronizedBeforeSuite(func(ctx context.Context) []byte { err = ytv1.AddToScheme(scheme) Expect(err).NotTo(HaveOccurred()) - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) + k8sClient, err = client.NewWithWatch(cfg, client.Options{Scheme: scheme}) Expect(err).NotTo(HaveOccurred()) Expect(k8sClient).NotTo(BeNil()) }) @@ -338,6 +341,35 @@ func PrintObjectInProgressReport[T client.Object](object T) { })) } +func LogObjectEvents(ctx context.Context, namespace string) { + watcher, err := k8sClient.Watch(ctx, &corev1.EventList{}, &client.ListOptions{ + Namespace: namespace, + }) + Expect(err).ToNot(HaveOccurred()) + + DeferCleanup(watcher.Stop) + + logEvent := func(event *corev1.Event) { + log.Info("Event", + "kind", event.InvolvedObject.Kind, + "name", event.InvolvedObject.Name, + "reason", event.Reason, + "message", event.Message, + ) + } + + go func() { + for ev := range watcher.ResultChan() { + switch ev.Type { + case watch.Added, watch.Modified: + if event, ok := ev.Object.(*corev1.Event); ok { + logEvent(event) + } + } + } + }() +} + func TrackConditions(matcher otypes.GomegaMatcher) otypes.GomegaMatcher { tracker := NewConditionsTracker() return Or(HaveField("Status.Conditions", diff --git a/test/e2e/ytsaurus_controller_test.go b/test/e2e/ytsaurus_controller_test.go index 5d40f7c6..1a0ba289 100644 --- a/test/e2e/ytsaurus_controller_test.go +++ b/test/e2e/ytsaurus_controller_test.go @@ -203,6 +203,8 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func() JustBeforeEach(func(ctx context.Context) { + LogObjectEvents(ctx, namespace) + By("Creating resource objects") for _, object := range objects { By(fmt.Sprintf("Creating %v %v", GetObjectGVK(object), object.GetName()))