Skip to content

Commit

Permalink
test/e2e: log all object events
Browse files Browse the repository at this point in the history
  • Loading branch information
koct9i committed Nov 13, 2024
1 parent d60ea9a commit 820b723
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
36 changes: 34 additions & 2 deletions test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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())
})
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/ytsaurus_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down

0 comments on commit 820b723

Please sign in to comment.