Skip to content

Commit

Permalink
Switch GKE Pods to execute on TB
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBergmeier6176 committed Jul 15, 2024
1 parent c266ee6 commit e8635a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`

Expand Down
16 changes: 8 additions & 8 deletions pkg/gke/test/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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{})
}

0 comments on commit e8635a0

Please sign in to comment.