Skip to content

Commit

Permalink
Add UI access tests (jaegertracing#1876)
Browse files Browse the repository at this point in the history
* Small fixes for outside-cluster test

Signed-off-by: Israel Blancas <[email protected]>

* Fix missing make deps

Signed-off-by: Israel Blancas <[email protected]>

* Templatize Service Account creation

Signed-off-by: Israel Blancas <[email protected]>

* Removing superfluous message

Signed-off-by: Israel Blancas <[email protected]>

* Add retries

Signed-off-by: Israel Blancas <[email protected]>

* Recover old test

Signed-off-by: Israel Blancas <[email protected]>

* Move the uidefinition test to the new suite

Signed-off-by: Israel Blancas <[email protected]>

* Add new checks for the ui-allinone

Signed-off-by: Israel Blancas <[email protected]>

* Create new tool to get the tokens

Signed-off-by: Israel Blancas <[email protected]>

* Fix the test for OpenShift

Signed-off-by: Israel Blancas <[email protected]>

* Create a common script for variables

Signed-off-by: Israel Blancas <[email protected]>

* Create a common script for variables

Signed-off-by: Israel Blancas <[email protected]>

* Clean test

Signed-off-by: Israel Blancas <[email protected]>

* Refactor get token for OpenShift

Signed-off-by: Israel Blancas <[email protected]>

* Add production test

Signed-off-by: Israel Blancas <[email protected]>

* Fix CI

Signed-off-by: Israel Blancas <[email protected]>

* Fix outside-cluster

Signed-off-by: Israel Blancas <[email protected]>

* Fix missing variable

Signed-off-by: Israel Blancas <[email protected]>

* Fix base checks

Signed-off-by: Israel Blancas <[email protected]>

* Fix securty make target

Signed-off-by: Israel Blancas <[email protected]>

* Fix CI

Signed-off-by: Israel Blancas <[email protected]>

* Fix test for Kubernetes

Signed-off-by: Israel Blancas <[email protected]>

* Apply changes requested in CR

Signed-off-by: Israel Blancas <[email protected]>
  • Loading branch information
Israel Blancas authored May 11, 2022
1 parent 9200b02 commit c0759fb
Show file tree
Hide file tree
Showing 49 changed files with 426 additions and 373 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: All in One E2E tests
name: UI E2E tests

on:
push:
Expand All @@ -22,13 +22,13 @@ jobs:
kube-version:
- "1.19"
- "1.23"
name: Run all in one E2E tests
name: UI E2E tests
steps:
- name: "Check out code into the Go module directory"
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: ./hack/actions/e2e
with:
testsuite_name: allinone
testsuite_name: ui
kube_version: ${{ matrix.kube-version }}
3 changes: 1 addition & 2 deletions Dockerfile.asserts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ COPY tests tests
ENV CGO_ENABLED=0

# Build
RUN go build -o ./uiconfig -a ./tests/assert-jobs/uiconfig/main.go

RUN go build -o ./reporter -a ./tests/assert-jobs/reporter/main.go
RUN go build -o ./query -a ./tests/assert-jobs/query/main.go
RUN go build -o ./index -a ./tests/assert-jobs/index/main.go
Expand All @@ -26,7 +26,6 @@ RUN go build -o ./index -a ./tests/assert-jobs/index/main.go
# minimal container image
FROM curlimages/curl:7.81.0
WORKDIR /
COPY --from=builder /workspace/uiconfig .
COPY --from=builder /workspace/reporter .
COPY --from=builder /workspace/query .
COPY --from=builder /workspace/index .
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ cert-manager: cmctl
cmctl check api --wait=5m

undeploy-cert-manager:
kubectl delete -f https://github.com/jetstack/cert-manager/releases/download/v${CERTMANAGER_VERSION}/cert-manager.yaml
kubectl delete --ignore-not-found=true -f https://github.com/jetstack/cert-manager/releases/download/v${CERTMANAGER_VERSION}/cert-manager.yaml

cmctl:
ifeq (, $(shell which cmctl))
Expand Down Expand Up @@ -316,7 +316,7 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in
$(KUSTOMIZE) build config/default | kubectl apply -f -

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: operatorhub
Expand Down
10 changes: 10 additions & 0 deletions hack/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Folders
export TEST_DIR=$ROOT_DIR/tests
export TEMPLATES_DIR=$TEST_DIR/templates
export EXAMPLES_DIR=$ROOT_DIR/examples

# Tools
export GOMPLATE=$ROOT_DIR/bin/gomplate
export YQ=$ROOT_DIR/bin/yq
2 changes: 0 additions & 2 deletions hack/install/install-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ function download() {

check_tool "$tool_path" "$version" "--version"

echo "Installing $program"

retry "curl -sLo $tool_path $url"
chmod +x $tool_path
export PATH=$PATH:$BIN
Expand Down
18 changes: 17 additions & 1 deletion tests/assert-jobs/reporter/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"crypto/tls"
"encoding/json"
"flag"
"fmt"
Expand Down Expand Up @@ -167,9 +168,17 @@ func generateSpansHistory(serviceName, operationName string, days, services int)

// Block the execution until the Jaeger REST API is available (or timeout)
func waitUntilRestAPIAvailable(jaegerEndpoint string) error {
transport := &http.Transport{}
transport := &http.Transport{
// #nosec
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
}
client := http.Client{Transport: transport}

maxRetries := 5
retries := 0

err := wait.Poll(time.Second*5, time.Minute*5, func() (done bool, err error) {
req, err := http.NewRequest(http.MethodGet, jaegerEndpoint, nil)
if err != nil {
Expand All @@ -183,7 +192,14 @@ func waitUntilRestAPIAvailable(jaegerEndpoint string) error {
if resp != nil && resp.StatusCode == 405 {
return true, nil
}

if err != nil {
logrus.Warningln("Something failed while reaching", jaegerEndpoint, ":", err)

if retries < maxRetries {
retries++
return false, nil
}
return false, err
}

Expand Down
47 changes: 0 additions & 47 deletions tests/assert-jobs/uiconfig/main.go

This file was deleted.

53 changes: 53 additions & 0 deletions tests/cmd-utils/assert-jaeger-http-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

if [ "$#" -ne 5 ]; then
echo "$0 <url> <expected HTTP code> <is OpenShift?> <namespace> <Jaeger name>"
exit 1
fi

export URL=$1
export EXPECTED_CODE=$2
export IS_OPENSHIFT=$3
export NAMESPACE=$4
export JAEGER_NAME=$5

export ROOT_DIR=$(realpath $(dirname ${BASH_SOURCE[0]})/../../)
source $ROOT_DIR/hack/common.sh

echo "Checking an expected HTTP response"
n=0

if [ $IS_OPENSHIFT = true ]; then
echo "Running in OpenShift. Getting the token..."
SECRET=$($ROOT_DIR/tests/cmd-utils/get-token.sh $NAMESPACE $JAEGER_NAME)
fi


export SLEEP_TIME=10
export MAX_RETRIES=30
export INSECURE_FLAG


until [ "$n" -ge $MAX_RETRIES ]; do
n=$((n+1))
echo "Try number $n/$MAX_RETRIES"

HTTP_RESPONSE=$(curl -H "Authorization: Bearer ${SECRET}" -X GET $URL $INSECURE_FLAG -s -o /dev/null -w %{http_code})
CMD_EXIT_CODE=$?

if [ $CMD_EXIT_CODE != 0 ]; then
echo "Something failed while trying to contact the server. Trying insecure mode"
INSECURE_FLAG="-k"
continue
fi

if [[ $HTTP_RESPONSE = $EXPECTED_CODE ]]; then
echo "curl response asserted properly"
exit 0
fi

echo "HTTP response is $HTTP_RESPONSE. $EXPECTED_CODE expected. Waiting $SLEEP_TIME s"
sleep $SLEEP_TIME
done

exit 1
39 changes: 39 additions & 0 deletions tests/cmd-utils/get-token.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

if [ "$#" -lt 2 ]; then
echo "$0 <namespace> <Jaeger name> <output file (optional)>"
exit 1
fi

export NAMESPACE=$1
export JAEGER_NAME=$2
export OUTPUT_FILE=$3

set -e

export ROOT_DIR=$(realpath $(dirname ${BASH_SOURCE[0]})/../../)
source $ROOT_DIR/hack/common.sh

# Ensure the tools are installed
$ROOT_DIR/hack/install/install-gomplate.sh > /dev/null
$ROOT_DIR/hack/install/install-yq.sh > /dev/null


if [ -z "$SERVICE_ACCOUNT_NAME" ]; then
export SERVICE_ACCOUNT_NAME="automation-sa"
fi

$GOMPLATE -f $TEMPLATES_DIR/openshift/configure-jaeger-sa.yaml.template -o /tmp/jaeger-sa.yaml
kubectl apply -f /tmp/jaeger-sa.yaml -n $NAMESPACE > /dev/null

# This takes some time
sleep 5

SECRET_NAME=$(kubectl get sa $SERVICE_ACCOUNT_NAME -o yaml -n $NAMESPACE | $YQ eval '.secrets[] | select( .name == "*-token-*")'.name)
SECRET=$(kubectl get secret $SECRET_NAME -n $NAMESPACE -o jsonpath='{.data.token}' | base64 -d)

if [ ! -z $OUTPUT_FILE ]; then
echo -n $SECRET > $OUTPUT_FILE
else
echo $SECRET
fi
55 changes: 55 additions & 0 deletions tests/cmd-utils/uiconfig/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package main

import (
"log"
"net/http"
"strings"

"github.com/sirupsen/logrus"
"github.com/spf13/viper"

"github.com/jaegertracing/jaeger-operator/tests/assert-jobs/utils"
)

const (
envExpectedContent = "EXPECTED_CONTENT"
envQueryHostName = "QUERY_HOSTNAME"
envAssertPresent = "ASSERT_PRESENT"
)

func main() {
viper.AutomaticEnv()

params := utils.NewParameters()
params.Parse()

expectedContent := viper.GetString(envExpectedContent)
hostName := viper.GetString(envQueryHostName)
assertPresent := viper.GetBool(envAssertPresent)

if expectedContent == "" {
logrus.Fatalln("EXPECTED_CONTENT env variable could not be empty")
}

logrus.Info("Querying ", hostName, "...")

err := utils.TestGetHTTP(hostName, params, func(_ *http.Response, body []byte) (done bool, err error) {
found := strings.Contains(string(body), expectedContent)

if assertPresent && found {
logrus.Infoln("Content found and asserted!")
return true, nil
} else if !assertPresent && !found {
logrus.Infoln("Content not found and asserted it was not found!")
return true, nil
}
logrus.Warningln("Found: ", found, ". Assert: ", assertPresent)
return false, nil
})

if err != nil {
log.Fatalln(err)
}

logrus.Info("Success!")
}
5 changes: 0 additions & 5 deletions tests/e2e/allinone/Makefile

This file was deleted.

7 changes: 0 additions & 7 deletions tests/e2e/allinone/allinone-ingress/00-assert.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions tests/e2e/allinone/allinone-ingress/00-install.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions tests/e2e/allinone/allinone-ingress/README.md

This file was deleted.

10 changes: 0 additions & 10 deletions tests/e2e/allinone/allinone-smoke/00-install.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions tests/e2e/allinone/allinone-smoke/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions tests/e2e/allinone/allinone-uidefinition/00-assert.yaml

This file was deleted.

18 changes: 0 additions & 18 deletions tests/e2e/allinone/allinone-uidefinition/00-install.yaml

This file was deleted.

Loading

0 comments on commit c0759fb

Please sign in to comment.