diff --git a/pkg/cronjob/es_rollover.go b/pkg/cronjob/es_rollover.go index 19d506958..093cd3cb1 100644 --- a/pkg/cronjob/es_rollover.go +++ b/pkg/cronjob/es_rollover.go @@ -213,6 +213,13 @@ func EsScriptEnvVars(opts v1.Options) []corev1.EnvVar { envs = append(envs, corev1.EnvVar{Name: x.envVar, Value: val}) } } + + if val, ok := options["skip-dependencies"]; ok { + envs = append(envs, corev1.EnvVar{Name: "SKIP_DEPENDENCIES", Value: val}) + } else if !ok && viper.GetString("platform") == v1.FlagPlatformOpenShift { + envs = append(envs, corev1.EnvVar{Name: "SKIP_DEPENDENCIES", Value: "true"}) + } + return envs } diff --git a/pkg/cronjob/es_rollover_test.go b/pkg/cronjob/es_rollover_test.go index 8281c39cb..541ff689c 100644 --- a/pkg/cronjob/es_rollover_test.go +++ b/pkg/cronjob/es_rollover_test.go @@ -47,6 +47,32 @@ func TestRollover(t *testing.T) { assert.Equal(t, []string{"rollover", "foo"}, cjob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Args) assert.Equal(t, []corev1.EnvVar{{Name: "INDEX_PREFIX", Value: "shortone"}, {Name: "CONDITIONS", Value: "weheee"}}, cjob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Env) assert.Equal(t, historyLimits, *cjob.Spec.SuccessfulJobsHistoryLimit) + + // Test openshift settings + viper.Set("platform", v1.FlagPlatformOpenShift) + defer viper.Set("platform", v1.FlagPlatformKubernetes) + cjob = rollover(j).(*batchv1.CronJob) + assert.Equal(t, + []corev1.EnvVar{ + {Name: "INDEX_PREFIX", Value: "shortone"}, + {Name: "SKIP_DEPENDENCIES", Value: "true"}, + {Name: "CONDITIONS", Value: "weheee"}, + }, cjob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Env, + ) + + j.Spec.Storage.Options = v1.NewOptions(map[string]interface{}{ + "es.server-urls": "foo,bar", + "es.index-prefix": "shortone", + "skip-dependencies": "skip", + }) + cjob = rollover(j).(*batchv1.CronJob) + assert.Equal(t, + []corev1.EnvVar{ + {Name: "INDEX_PREFIX", Value: "shortone"}, + {Name: "SKIP_DEPENDENCIES", Value: "skip"}, + {Name: "CONDITIONS", Value: "weheee"}, + }, cjob.Spec.JobTemplate.Spec.Template.Spec.Containers[0].Env, + ) } func TestLookback(t *testing.T) { diff --git a/tests/cmd-utils/assert-jaeger-http-code.sh b/tests/cmd-utils/assert-jaeger-http-code.sh index 542950900..b1b646e1d 100755 --- a/tests/cmd-utils/assert-jaeger-http-code.sh +++ b/tests/cmd-utils/assert-jaeger-http-code.sh @@ -18,8 +18,16 @@ 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) + echo "Running in OpenShift" + + if [ "$INSECURE" = "true" ]; then + echo "Not using any secret" + elif [ ! -z "$JAEGER_USERNAME" ]; then + echo "Using Jaeger basic authentication" + else + echo "User not provided. Getting the token..." + SECRET=$($ROOT_DIR/tests/cmd-utils/get-token.sh $NAMESPACE $JAEGER_NAME) + fi fi @@ -30,9 +38,15 @@ export INSECURE_FLAG until [ "$n" -ge $MAX_RETRIES ]; do n=$((n+1)) - echo "Try number $n/$MAX_RETRIES" + echo "Try number $n/$MAX_RETRIES the $URL" - HTTP_RESPONSE=$(curl -H "Authorization: Bearer ${SECRET}" -X GET $URL $INSECURE_FLAG -s -o /dev/null -w %{http_code}) + HTTP_RESPONSE=$(curl \ + ${SECRET:+-H "Authorization: Bearer ${SECRET}"} \ + ${JAEGER_USERNAME:+-u $JAEGER_USERNAME:$JAEGER_PASSWORD} \ + -X GET $URL \ + $INSECURE_FLAG -s \ + -o /dev/null \ + -w %{http_code}) CMD_EXIT_CODE=$? if [ $CMD_EXIT_CODE != 0 ]; then @@ -41,7 +55,7 @@ until [ "$n" -ge $MAX_RETRIES ]; do continue fi - if [[ $HTTP_RESPONSE = $EXPECTED_CODE ]]; then + if [[ "$HTTP_RESPONSE" = "$EXPECTED_CODE" ]]; then echo "curl response asserted properly" exit 0 fi diff --git a/tests/e2e/elasticsearch/es-streaming-autoprovisioned/00-install.yaml b/tests/e2e/elasticsearch/es-streaming-autoprovisioned/00-install.yaml new file mode 100644 index 000000000..d28d19b45 --- /dev/null +++ b/tests/e2e/elasticsearch/es-streaming-autoprovisioned/00-install.yaml @@ -0,0 +1,19 @@ +apiVersion: jaegertracing.io/v1 +kind: Jaeger +metadata: + name: auto-provisioned +spec: + strategy: streaming + storage: + type: elasticsearch + elasticsearch: + nodeCount: 1 + resources: + requests: + cpu: 100m + memory: 1Gi + limits: + memory: 1Gi + ingress: + enabled: true + security: "none" diff --git a/tests/e2e/elasticsearch/es-streaming-autoprovisioned/03-assert.yaml b/tests/e2e/elasticsearch/es-streaming-autoprovisioned/03-assert.yaml new file mode 100644 index 000000000..5bbe76331 --- /dev/null +++ b/tests/e2e/elasticsearch/es-streaming-autoprovisioned/03-assert.yaml @@ -0,0 +1,29 @@ +# Assert the Jaeger collector is up and running +apiVersion: apps/v1 +kind: Deployment +metadata: + name: auto-provisioned-ingester +spec: + replicas: 1 +status: + readyReplicas: 1 +--- +# Assert the Jaeger query is up and running +apiVersion: apps/v1 +kind: Deployment +metadata: + name: auto-provisioned-query +spec: + replicas: 1 +status: + readyReplicas: 1 +--- +# Assert the Jaeger collector is up and running +apiVersion: apps/v1 +kind: Deployment +metadata: + name: auto-provisioned-collector +spec: + replicas: 1 +status: + readyReplicas: 1 diff --git a/tests/e2e/elasticsearch/es-streaming-autoprovisioned/README.md b/tests/e2e/elasticsearch/es-streaming-autoprovisioned/README.md new file mode 100644 index 000000000..550bd6fef --- /dev/null +++ b/tests/e2e/elasticsearch/es-streaming-autoprovisioned/README.md @@ -0,0 +1,5 @@ +# Elasticsearch - ES autoprovisioned + Kafka autoprovisioned +## What is this test case testing? + +Test a Jaeger instance with an Elasticsearch instance autoprovisioned using +`streaming` as deployment strategy. The Kafka cluster is autoprovisioned too. diff --git a/tests/e2e/elasticsearch/render.sh b/tests/e2e/elasticsearch/render.sh index 63390a222..7434fe5a7 100755 --- a/tests/e2e/elasticsearch/render.sh +++ b/tests/e2e/elasticsearch/render.sh @@ -126,3 +126,18 @@ else export CRONJOB_NAME="my-jaeger-spark-dependencies" $GOMPLATE -f $TEMPLATES_DIR/wait-for-cronjob-execution.yaml.template -o ./02-wait-spark-job.yaml fi + + +if [ "$IS_OPENSHIFT" != true ]; then + skip_test "es-streaming-autoprovisioned" "This test is only supported in OpenShift" +else + start_test "es-streaming-autoprovisioned" + + export CLUSTER_NAME="auto-provisioned" + export REPLICAS=1 + $GOMPLATE -f $TEMPLATES_DIR/assert-zookeeper-cluster.yaml.template -o ./00-assert.yaml + $GOMPLATE -f $TEMPLATES_DIR/assert-kafka-cluster.yaml.template -o ./01-assert.yaml + $GOMPLATE -f $TEMPLATES_DIR/assert-entity-operator.yaml.template -o ./02-assert.yaml + + render_smoke_test "auto-provisioned" "allInOne" "03" +fi diff --git a/tests/e2e/examples/examples-openshift-with-htpasswd/00-install.yaml.template b/tests/e2e/examples/examples-openshift-with-htpasswd/00-install.yaml.template new file mode 100644 index 000000000..2298dadb9 --- /dev/null +++ b/tests/e2e/examples/examples-openshift-with-htpasswd/00-install.yaml.template @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Secret +metadata: + name: htpasswd +data: + htpasswd: {{ .Env.SECRET }} diff --git a/tests/e2e/examples/render.sh b/tests/e2e/examples/render.sh index 6c87af0d2..0edd3c8de 100755 --- a/tests/e2e/examples/render.sh +++ b/tests/e2e/examples/render.sh @@ -75,3 +75,38 @@ export example_name="with-sampling" render_install_cassandra "00" render_install_example "$example_name" "01" render_smoke_test_example "$example_name" "02" + + +############################################################################### +# OpenShift examples ########################################################## +############################################################################### + +if [ $IS_OPENSHIFT = true ]; then + start_test "examples-openshift-with-htpasswd" + export JAEGER_NAME="with-htpasswd" + export JAEGER_USERNAME="awesomeuser" + export JAEGER_PASSWORD="awesomepassword" + # This variable stores the output from `htpasswd -nbs $JAEGER_USERNAME $JAEGER_PASSWORD` + # but, to avoid the installation of the `htpasswd` command, we store the generated + # output here + export JAEGER_USER_PASSWORD_HASH="awesomeuser:{SHA}uUdqPVUyqNBmERU0Qxj3KFaZnjw=" + # Create the secret + SECRET=$(echo $JAEGER_USER_PASSWORD_HASH | base64) $GOMPLATE -f ./00-install.yaml.template -o ./00-install.yaml + # Install the Jaeger instance + $GOMPLATE -f $EXAMPLES_DIR/openshift/with-htpasswd.yaml -o ./01-install.yaml + $GOMPLATE -f $TEMPLATES_DIR/allinone-jaeger-assert.yaml.template -o ./01-assert.yaml + + export GET_URL_COMMAND="kubectl get routes -o=jsonpath='{.items[0].status.ingress[0].host}' -n \$NAMESPACE" + export URL="https://\$($GET_URL_COMMAND)/search" + + # Sometimes, the Ingress/OpenShift route is there but not 100% ready so, when + # kubectl tries to get the hostname, it returns an empty string + $GOMPLATE -f $TEMPLATES_DIR/ensure-ingress-host.sh.template -o ./ensure-ingress-host.sh + chmod +x ./ensure-ingress-host.sh + + INSECURE=true JAEGER_USERNAME= JAEGER_PASSWORD= EXPECTED_CODE="403" $GOMPLATE -f $TEMPLATES_DIR/assert-http-code.yaml.template -o ./02-check-unsecured.yaml + JAEGER_USERNAME="wronguser" JAEGER_PASSWORD="wrongpassword" EXPECTED_CODE="403" $GOMPLATE -f $TEMPLATES_DIR/assert-http-code.yaml.template -o ./03-check-unauthorized.yaml + EXPECTED_CODE="200" $GOMPLATE -f $TEMPLATES_DIR/assert-http-code.yaml.template -o ./04-check-authorized.yaml +else + skip_test "examples-openshift-with-htpasswd" "This test is only supported in OpenShift" +fi diff --git a/tests/e2e/render-utils.sh b/tests/e2e/render-utils.sh index b06a1ce3a..3816cba53 100644 --- a/tests/e2e/render-utils.sh +++ b/tests/e2e/render-utils.sh @@ -22,6 +22,9 @@ source $ROOT_DIR/hack/common.sh # render_smoke_test "my-jaeger" "production" "01" # Generates the `01-smoke-test.yaml` and `01-assert.yaml` files. A smoke test # will be run against the Jaeger instance called `my-jaeger`. +# Accepted values for : +# * allInOne: all in one deployment. +# * production: production using Elasticsearch. function render_smoke_test() { if [ "$#" -ne 3 ]; then error "Wrong number of parameters used for render_smoke_test. Usage: render_smoke_test " @@ -152,6 +155,7 @@ function render_check_indices() { $GOMPLATE -f $TEMPLATES_DIR/assert-check-indices.yaml.template -o ./$test_step-assert.yaml unset JOB_NUMBER + unset MOUNT_SECRET } diff --git a/tests/templates/allinone-jaeger-assert.yaml.template b/tests/templates/allinone-jaeger-assert.yaml.template index 08fbfb1b7..6b6bc0bd6 100644 --- a/tests/templates/allinone-jaeger-assert.yaml.template +++ b/tests/templates/allinone-jaeger-assert.yaml.template @@ -4,5 +4,5 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ .Env.JAEGER_NAME }} -spec: - replicas: 1 \ No newline at end of file +status: + readyReplicas: 1 diff --git a/tests/templates/assert-http-code.yaml.template b/tests/templates/assert-http-code.yaml.template index 808ebdb3d..0f3ecb526 100644 --- a/tests/templates/assert-http-code.yaml.template +++ b/tests/templates/assert-http-code.yaml.template @@ -2,4 +2,4 @@ apiVersion: kuttl.dev/v1beta1 kind: TestStep commands: - command: "./ensure-ingress-host.sh" - - script: "{{ .Env.ASSERT_HTTP_CODE_PROGRAM }} {{ .Env.URL }} {{ .Env.EXPECTED_CODE }} {{ .Env.IS_OPENSHIFT }} $NAMESPACE {{ .Env.JAEGER_NAME }}" + - script: "{{if getenv "INSECURE"}}INSECURE=true{{end}} {{if getenv "JAEGER_USERNAME"}}JAEGER_USERNAME={{ .Env.JAEGER_USERNAME }} JAEGER_PASSWORD={{ .Env.JAEGER_PASSWORD }} {{end}} {{ .Env.ASSERT_HTTP_CODE_PROGRAM }} {{ .Env.URL }} {{ .Env.EXPECTED_CODE }} {{ .Env.IS_OPENSHIFT }} $NAMESPACE {{ .Env.JAEGER_NAME }}" diff --git a/tests/templates/assert-jaeger-deployment.yaml.template b/tests/templates/assert-jaeger-deployment.yaml.template index ba186a5ff..d3caa8c0c 100644 --- a/tests/templates/assert-jaeger-deployment.yaml.template +++ b/tests/templates/assert-jaeger-deployment.yaml.template @@ -2,5 +2,5 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ .Env.JAEGER_NAME }} -spec: - replicas: 1 +status: + readyReplicas:: 1