From e8635a07d39f21c12c62f3bf541585523ca2eb69 Mon Sep 17 00:00:00 2001 From: Andreas Bergmeier Date: Mon, 15 Jul 2024 13:14:48 +0200 Subject: [PATCH] Switch GKE Pods to execute on TB --- CHANGELOG.md | 3 +++ pkg/gke/test/pods.go | 16 ++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8ae22f..2742d58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## v0.0.61 Switch GKE Pods to execute on TB +- Interacting with GKE Pod functions new needs testing.TB object. + ## v0.0.60 Allow TraceExporterOption - Enable passing options to `DiscoverServices` via `WithTraceExporterOption` diff --git a/pkg/gke/test/pods.go b/pkg/gke/test/pods.go index ae5744f..593ac32 100644 --- a/pkg/gke/test/pods.go +++ b/pkg/gke/test/pods.go @@ -2,9 +2,9 @@ package test import ( "context" - "fmt" "os" "sync" + "testing" "github.com/otto-de/sherlock-microservice/pkg/gke" core "k8s.io/api/core/v1" @@ -25,16 +25,16 @@ type PodRun struct { // NewPodRun is starting a remote Pod and streams its output locally. // Output gets written using provided streams. -func NewPodRunWithStreams(clientset *kubernetes.Clientset, ctx context.Context, pod *core.Pod, streams genericclioptions.IOStreams) *PodRun { +func NewPodRunWithStreams(tb testing.TB, clientset *kubernetes.Clientset, ctx context.Context, pod *core.Pod, streams genericclioptions.IOStreams) *PodRun { pods := clientset.CoreV1().Pods(pod.Namespace) - fmt.Fprintln(streams.Out, "Creating Test Pod") + tb.Log("Creating Test Pod\n") pod, err := pods.Create(ctx, pod, metav1.CreateOptions{}) if err != nil { panic(err) } - fmt.Fprintf(streams.Out, "Created Test Pod `%s`\n", pod.Name) + tb.Logf("Created Test Pod `%s`\n", pod.Name) pr := &PodRun{ ctx: ctx, @@ -56,19 +56,19 @@ func NewPodRunWithStreams(clientset *kubernetes.Clientset, ctx context.Context, // NewPodRun is starting a remote Pod and streams its output locally. // Output gets written to Stdout and Stderr. -func NewPodRun(clientset *kubernetes.Clientset, ctx context.Context, pod *core.Pod) *PodRun { +func NewPodRun(tb testing.TB, clientset *kubernetes.Clientset, ctx context.Context, pod *core.Pod) *PodRun { streams := genericclioptions.IOStreams{ In: nil, Out: os.Stdout, ErrOut: os.Stderr, } - return NewPodRunWithStreams(clientset, ctx, pod, streams) + return NewPodRunWithStreams(tb, clientset, ctx, pod, streams) } // Close waits until there is no more output to stream. Then deletes the Pod. -func (pr *PodRun) Close() error { +func (pr *PodRun) Close(tb testing.TB) error { pr.logStreaming.Wait() - fmt.Fprintf(pr.streams.Out, "Deleting Test Pod `%s`\n", pr.Pod.Name) + tb.Logf("Deleting Test Pod `%s`\n", pr.Pod.Name) return pr.pods.Delete(pr.ctx, pr.Pod.Name, metav1.DeleteOptions{}) }