-
Notifications
You must be signed in to change notification settings - Fork 348
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 := getJaegerDefinition(namespace, "agent-as-daemonset") | ||
|
||
log.Infof("passing %v", j) | ||
err = f.Client.Create(goctx.TODO(), j, cleanupOptions) | ||
|
@@ -71,6 +56,65 @@ 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 | ||
}) | ||
} | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove two extra lines |
||
|
||
func getVertxDeployment(namespace string, selector map[string]string) *appsv1.Deployment { | ||
dep := &appsv1.Deployment{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "apps/v1", | ||
|
@@ -130,56 +174,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 getJaegerDefinition(namespace string, name string) *v1.Jaeger { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think this needs to be renamed to indicate it is returning a AgentAsDaemonSet definition. |
||
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package e2e | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing the ingress should be independent of the agent, whether deployed daemonset or sidecar. Might be better to have variants of the |
||
|
||
import ( | ||
goctx "context" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
framework "github.com/operator-framework/operator-sdk/pkg/test" | ||
"github.com/operator-framework/operator-sdk/pkg/test/e2eutil" | ||
log "github.com/sirupsen/logrus" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
) | ||
|
||
// DaemonSet runs a test with the agent as DaemonSet, but uses ingress to access it rather than portforwarding | ||
func DaemonSetWithIngress(t *testing.T) { | ||
ctx := prepare(t) | ||
defer ctx.Cleanup() | ||
|
||
if err := daemonsetTestWithIngress(t, framework.Global, ctx); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func daemonsetTestWithIngress(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 it. | ||
if isOpenShift(t, f) { | ||
t.Skipf("Test %s is not currently supported on OpenShift\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 := getJaegerDefinition(namespace, "agent-as-daemonset") | ||
|
||
log.Infof("passing %v", j) | ||
err = f.Client.Create(goctx.TODO(), j, cleanupOptions) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = WaitForDaemonSet(t, f.KubeClient, namespace, "agent-as-daemonset-agent-daemonset", retryInterval, timeout) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
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 { | ||
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} | ||
|
||
req, err := http.NewRequest(http.MethodGet, url, nil) | ||
if err != nil { | ||
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 | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove extra line