Skip to content

Commit

Permalink
test: log all object events in e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
koct9i committed Nov 14, 2024
1 parent 95036fa commit 966edf8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
37 changes: 35 additions & 2 deletions test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"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 @@ -43,6 +44,8 @@ import (
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

corev1 "k8s.io/api/core/v1"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

Expand All @@ -53,7 +56,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 @@ -104,7 +107,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 All @@ -126,6 +129,36 @@ var _ = BeforeEach(func() {
})
})

func LogObjectEvents(ctx context.Context, namespace string) func() {
watcher, err := k8sClient.Watch(ctx, &corev1.EventList{}, &client.ListOptions{
Namespace: namespace,
})
Expect(err).ToNot(HaveOccurred())

logEvent := func(event *corev1.Event) {
log.Info("Event",
"type", event.Type,
"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)
}
}
}
}()

return watcher.Stop
}

func NewYtsaurusStatusTracker() func(*ytv1.Ytsaurus) bool {
prevStatus := ytv1.YtsaurusStatus{}
conditions := map[string]metav1.Condition{}
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/ytsaurus_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ var _ = Describe("Basic e2e test for Ytsaurus controller", Label("e2e"), func()
Name: ytsaurus.Name,
Namespace: namespace,
}

By("Logging all events in namespace")
DeferCleanup(LogObjectEvents(ctx, namespace))
})

JustBeforeEach(func(ctx context.Context) {
Expand Down

0 comments on commit 966edf8

Please sign in to comment.