From 61df80818286587af794fdca5ada071aad48c12d Mon Sep 17 00:00:00 2001 From: Pavol Loffay Date: Mon, 3 Dec 2018 14:40:19 +0100 Subject: [PATCH] Add modeke test to elastic Signed-off-by: Pavol Loffay --- test/e2e/cassandra.go | 30 +++++++----------------------- test/e2e/production_test.go | 30 +++++++++++++++++++++++++++++- test/e2e/utils.go | 28 ++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 24 deletions(-) create mode 100644 test/e2e/utils.go diff --git a/test/e2e/cassandra.go b/test/e2e/cassandra.go index fbb035c6a7..161ffbf15a 100644 --- a/test/e2e/cassandra.go +++ b/test/e2e/cassandra.go @@ -3,9 +3,6 @@ package e2e import ( goctx "context" "fmt" - "github.com/pkg/errors" - "k8s.io/client-go/kubernetes" - "strings" "testing" "github.com/jaegertracing/jaeger-operator/pkg/apis/io/v1alpha1" @@ -43,10 +40,12 @@ func cassandraTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx) }, Spec: v1alpha1.JaegerSpec{ Strategy: "allInOne", - AllInOne: v1alpha1.JaegerAllInOneSpec{}, Storage: v1alpha1.JaegerStorageSpec{ Type: "cassandra", - Options: v1alpha1.NewOptions(map[string]interface{}{"cassandra.servers": "cassandra.default.svc"}), + Options: v1alpha1.NewOptions(map[string]interface{}{"cassandra.servers": "cassandra.default.svc", "cassandra.keyspace": "jaeger_v1_datacenter1"}), + CassandraCreateSchema: v1alpha1.JaegerCassandraCreateSchemaSpec{ + Datacenter: "datacenter1", + }, }, }, } @@ -67,33 +66,18 @@ func cassandraTest(t *testing.T, f *framework.Framework, ctx *framework.TestCtx) return err } - podName, err := GetPodName(namespace, "with-cassandra", f.KubeClient) + jaegerPod, err := GetPod(namespace, "with-cassandra", "with-cassandra", f.KubeClient) if err != nil { return err } - portForw, closeChan, err := CreatePortForward(namespace, podName, []string{"16686:16686", "14268:14268"}, f.KubeConfig) + portForw, closeChan, err := CreatePortForward(namespace, jaegerPod.Name, []string{"16686:16686", "14268:14268"}, f.KubeConfig) if err != nil { return err } - defer close(closeChan) defer portForw.Close() + defer close(closeChan) go func() { portForw.ForwardPorts() }() <- portForw.Ready return SmokeTest("http://localhost:16686/api/traces", "http://localhost:14268/api/traces", "foobar", retryInterval, timeout) } -func GetPodName(namespace, ownerNamePrefix string, kubeclient kubernetes.Interface) (string, error) { - pods, err := kubeclient.CoreV1().Pods(namespace).List(metav1.ListOptions{IncludeUninitialized:true}) - if err != nil { - return "", err - } - for _, pod := range pods.Items { - for _, or := range pod.OwnerReferences { - - if strings.HasPrefix(or.Name, ownerNamePrefix) { - return pod.Name, nil - } - } - } - return "", errors.New(fmt.Sprintf("could not find pod of owner %s", ownerNamePrefix)) -} diff --git a/test/e2e/production_test.go b/test/e2e/production_test.go index 183ba228c7..7f05663700 100644 --- a/test/e2e/production_test.go +++ b/test/e2e/production_test.go @@ -64,5 +64,33 @@ func simpleProd(t *testing.T, f *framework.Framework, ctx *framework.TestCtx) er return err } - return e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "simple-prod-query", 1, retryInterval, timeout) + err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, "simple-prod-query", 1, retryInterval, timeout) + if err != nil { + return err + } + queryPod, err := GetPod(namespace, "simple-prod-query","simple-prod", f.KubeClient) + if err != nil { + return err + } + collectorPod, err := GetPod(namespace, "simple-prod-collector","simple-prod", f.KubeClient) + if err != nil { + return err + } + portForw, closeChan, err := CreatePortForward(namespace, queryPod.Name, []string{"16686:16686"}, f.KubeConfig) + if err != nil { + return err + } + defer portForw.Close() + defer close(closeChan) + go func() { portForw.ForwardPorts() }() + <- portForw.Ready + portForwColl, closeChanColl, err := CreatePortForward(namespace, collectorPod.Name, []string{"14268:14268"}, f.KubeConfig) + if err != nil { + return err + } + defer portForwColl.Close() + defer close(closeChanColl) + go func() { portForwColl.ForwardPorts() }() + <- portForwColl.Ready + return SmokeTest("http://localhost:16686/api/traces", "http://localhost:14268/api/traces", "foobar", retryInterval, timeout) } diff --git a/test/e2e/utils.go b/test/e2e/utils.go new file mode 100644 index 0000000000..1dd44c9a9d --- /dev/null +++ b/test/e2e/utils.go @@ -0,0 +1,28 @@ +package e2e + +import ( + "errors" + "fmt" + "k8s.io/api/core/v1" + "k8s.io/client-go/kubernetes" + "strings" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// GetPod returns pod name +func GetPod(namespace, namePrefix, ownerNamePrefix string, kubeclient kubernetes.Interface) (v1.Pod, error) { + pods, err := kubeclient.CoreV1().Pods(namespace).List(metav1.ListOptions{IncludeUninitialized:true}) + if err != nil { + return v1.Pod{}, err + } + for _, pod := range pods.Items { + if strings.HasPrefix(pod.Name, namePrefix) { + for _, or := range pod.OwnerReferences { + if strings.HasPrefix(or.Name, ownerNamePrefix) { + return pod, nil + } + } + } + } + return v1.Pod{}, errors.New(fmt.Sprintf("could not find pod of owner %s", ownerNamePrefix)) +}