Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests to work on OpenShift #323

Merged
merged 2 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 104 additions & 6 deletions test/e2e/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
goctx "context"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
Expand All @@ -28,6 +29,10 @@ func JaegerAllInOne(t *testing.T) {
t.Fatal(err)
}

if err := allInOneWithIngressTest(t, framework.Global, ctx); err != nil {
t.Fatal(err)
}

if err := allInOneWithUIConfigTest(t, framework.Global, ctx); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -69,6 +74,97 @@ func allInOneTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx)
return e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "my-jaeger", 1, retryInterval, timeout)
}

func allInOneWithIngressTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx) error {
// This does not currently work on OpenShift as it creates a route, and the kubeclient call
// in WaitForIngress doesn't find that. We either need to figure out how to get kubeclient
// to find routes (at the command line "kubectl get route.route.openshift.io" works) or use
// the openshift client to find the route.
if isOpenShift(t, f) {
t.Skipf("Test %s is not currently supported on OpenShift\n", t.Name())
}
namespace, err := ctx.GetNamespace()
if err != nil {
return fmt.Errorf("could not get namespace: %v", err)
}

ingressEnagled := true
// create jaeger custom resource
exampleJaeger := &v1.Jaeger{
TypeMeta: metav1.TypeMeta{
Kind: "Jaeger",
APIVersion: "jaegertracing.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-jaeger-with-ingress",
Namespace: namespace,
},
Spec: v1.JaegerSpec{
Strategy: "allInOne",
AllInOne: v1.JaegerAllInOneSpec{
Options: v1.NewOptions(map[string]interface{}{
"log-level": "debug",
"memory.max-traces": 10000,
}),
},
Ingress: v1.JaegerIngressSpec {
Enabled: &ingressEnagled,
Security:v1.IngressSecurityNoneExplicit,
},
},
}

log.Infof("passing %v", exampleJaeger)
err = f.Client.Create(goctx.TODO(), exampleJaeger, &framework.CleanupOptions{TestContext: ctx, Timeout: timeout, RetryInterval: retryInterval})
if err != nil {
return err
}

ingress, err := WaitForIngress(t, f.KubeClient, namespace, "my-jaeger-with-ingress-query", retryInterval, timeout)
if err != nil {
return err
}

if len(ingress.Status.LoadBalancer.Ingress) != 1 {
return fmt.Errorf("Wrong number of ingresses. Expected 1, was %v", len(ingress.Status.LoadBalancer.Ingress))
}

address := ingress.Status.LoadBalancer.Ingress[0].IP
url := fmt.Sprintf("http://%s/api/services", address)
c := http.Client{Timeout: time.Second}
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
}

// Hit this url once to make Jaeger itself create a trace, then it will show up in services
c.Do(req)

return wait.Poll(retryInterval, timeout, func() (done bool, err error) {
res, err := c.Do(req)
if err != nil {
return false, err
}

body, err := ioutil.ReadAll(res.Body)
if err != nil {
return false, err
}

resp := &services{}
err = json.Unmarshal(body, &resp)
if err != nil {
return false, nil
}

for _, v := range resp.Data {
if v == "jaeger-query" {
return true, nil
}
}
return false, nil
})
}

func allInOneWithUIConfigTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx) error {
cleanupOptions := &framework.CleanupOptions{TestContext: ctx, Timeout: timeout, RetryInterval: retryInterval}
namespace, err := ctx.GetNamespace()
Expand Down Expand Up @@ -113,22 +209,24 @@ func allInOneWithUIConfigTest(t *testing.T, f *framework.Framework, ctx *framewo
return err
}

err = WaitForIngress(t, f.KubeClient, namespace, "all-in-one-with-ui-config-query", retryInterval, timeout)
err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "all-in-one-with-ui-config", 1, retryInterval, timeout)
if err != nil {
return err
}

i, err := f.KubeClient.ExtensionsV1beta1().Ingresses(namespace).Get("all-in-one-with-ui-config-query", metav1.GetOptions{})
queryPod, err := GetPod(namespace, "all-in-one-with-ui-config", "jaegertracing/all-in-one", f.KubeClient)
if err != nil {
return err
}

if len(i.Status.LoadBalancer.Ingress) != 1 {
return fmt.Errorf("Wrong number of ingresses. Expected 1, was %v", len(i.Status.LoadBalancer.Ingress))
portForward, closeChan, err := CreatePortForward(namespace, queryPod.Name, []string{"16686"}, f.KubeConfig)
if err != nil {
return err
}
defer portForward.Close()
defer close(closeChan)

address := i.Status.LoadBalancer.Ingress[0].IP
url := fmt.Sprintf("http://%s%s/search", address, basePath)
url := fmt.Sprintf("http://localhost:16686/%s/search", basePath)
c := http.Client{Timeout: time.Second}

req, err := http.NewRequest(http.MethodGet, url, nil)
Expand Down
155 changes: 85 additions & 70 deletions test/e2e/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,17 @@ func DaemonSet(t *testing.T) {
}

func daemonsetTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx) error {
// TODO restore this after fix of https://github.com/jaegertracing/jaeger-operator/issues/322
if isOpenShift(t, f) {
t.Skipf("Test %s is not currently supported on OpenShift because of issue 322\n", t.Name())
}
cleanupOptions := &framework.CleanupOptions{TestContext: ctx, Timeout: timeout, RetryInterval: retryInterval}
namespace, err := ctx.GetNamespace()
if err != nil {
return fmt.Errorf("could not get namespace: %v", err)
}

j := &v1.Jaeger{
TypeMeta: metav1.TypeMeta{
Kind: "Jaeger",
APIVersion: "jaegertracing.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "agent-as-daemonset",
Namespace: namespace,
},
Spec: v1.JaegerSpec{
Strategy: "allInOne",
AllInOne: v1.JaegerAllInOneSpec{},
Agent: v1.JaegerAgentSpec{
Strategy: "DaemonSet",
Options: v1.NewOptions(map[string]interface{}{
"log-level": "debug",
}),
},
},
}
j := jaegerAgentAsDaemonsetDefinition(namespace, "agent-as-daemonset")

log.Infof("passing %v", j)
err = f.Client.Create(goctx.TODO(), j, cleanupOptions)
Expand All @@ -71,6 +56,63 @@ func daemonsetTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx)
}

selector := map[string]string{"app": "vertx-create-span"}
dep := getVertxDeployment(namespace, selector)
err = f.Client.Create(goctx.TODO(), dep, cleanupOptions)
if err != nil {
return err
}

err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "vertx-create-span", 1, retryInterval, 3 * timeout)
if err != nil {
fmt.Println("Failed waiting for vertx deployment")
return err
}

queryPod, err := GetPod(namespace, "agent-as-daemonset", "jaegertracing/all-in-one", f.KubeClient)
if err != nil {
fmt.Println("Failed waiting for pod agent-as-daemonset")
return err
}

portForw, closeChan, err := CreatePortForward(namespace, queryPod.Name, []string{"16686"}, f.KubeConfig)
if err != nil {
fmt.Println("Failed waiting for port forward")
return err
}
defer portForw.Close()
defer close(closeChan)

url := "http://localhost:16686/api/traces?service=order"
c := http.Client{Timeout: time.Second}

req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
fmt.Println("Failed waiting for get on " + url)
return err
}

return wait.Poll(retryInterval, timeout, func() (done bool, err error) {
res, err := c.Do(req)
if err != nil {
return false, err
}

body, err := ioutil.ReadAll(res.Body)
if err != nil {
return false, err
}

resp := &resp{}
err = json.Unmarshal(body, &resp)
if err != nil {
return false, err
}

return len(resp.Data) > 0, nil
})
}

func getVertxDeployment(namespace string, selector map[string]string) *appsv1.Deployment {
dep := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Expand Down Expand Up @@ -130,56 +172,29 @@ func daemonsetTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx)
},
},
}
err = f.Client.Create(goctx.TODO(), dep, cleanupOptions)
if err != nil {
return err
}

err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "vertx-create-span", 1, retryInterval, timeout)
if err != nil {
return err
}

err = WaitForIngress(t, f.KubeClient, namespace, "agent-as-daemonset-query", retryInterval, timeout)
if err != nil {
return err
}

i, err := f.KubeClient.ExtensionsV1beta1().Ingresses(namespace).Get("agent-as-daemonset-query", metav1.GetOptions{})
if err != nil {
return err
}

if len(i.Status.LoadBalancer.Ingress) != 1 {
return fmt.Errorf("Wrong number of ingresses. Expected 1, was %v", len(i.Status.LoadBalancer.Ingress))
}

address := i.Status.LoadBalancer.Ingress[0].IP
url := fmt.Sprintf("http://%s/api/traces?service=order", address)
c := http.Client{Timeout: time.Second}
return dep
}

req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
func jaegerAgentAsDaemonsetDefinition(namespace string, name string) *v1.Jaeger {
j := &v1.Jaeger{
TypeMeta: metav1.TypeMeta{
Kind: "Jaeger",
APIVersion: "jaegertracing.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
Spec: v1.JaegerSpec{
Strategy: "allInOne",
AllInOne: v1.JaegerAllInOneSpec{},
Agent: v1.JaegerAgentSpec{
Strategy: "DaemonSet",
Options: v1.NewOptions(map[string]interface{}{
"log-level": "debug",
}),
},
},
}

return wait.Poll(retryInterval, timeout, func() (done bool, err error) {
res, err := c.Do(req)
if err != nil {
return false, err
}

body, err := ioutil.ReadAll(res.Body)
if err != nil {
return false, err
}

resp := &resp{}
err = json.Unmarshal(body, &resp)
if err != nil {
return false, err
}

return len(resp.Data) > 0, nil
})
return j
}
13 changes: 5 additions & 8 deletions test/e2e/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,19 @@ func sidecarTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx) e
return err
}

err = WaitForIngress(t, f.KubeClient, namespace, "agent-as-sidecar-query", retryInterval, timeout)
queryPod, err := GetPod(namespace, "agent-as-sidecar", "jaegertracing/all-in-one", f.KubeClient)
if err != nil {
return err
}

i, err := f.KubeClient.ExtensionsV1beta1().Ingresses(namespace).Get("agent-as-sidecar-query", metav1.GetOptions{})
portForward, closeChan, err := CreatePortForward(namespace, queryPod.Name, []string{"16686"}, f.KubeConfig)
if err != nil {
return err
}
defer portForward.Close()
defer close(closeChan)

if len(i.Status.LoadBalancer.Ingress) != 1 {
return fmt.Errorf("Wrong number of ingresses. Expected 1, was %v", len(i.Status.LoadBalancer.Ingress))
}

address := i.Status.LoadBalancer.Ingress[0].IP
url := fmt.Sprintf("http://%s/api/traces?service=order", address)
url := "http://localhost:16686/api/traces?service=order"
c := http.Client{Timeout: time.Second}

req, err := http.NewRequest(http.MethodGet, url, nil)
Expand Down
Loading