Skip to content

Commit

Permalink
Merge branch 'main' into Issue-1894
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvp8510 authored May 31, 2022
2 parents 54d89f0 + e17fa17 commit 39b7fde
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 10 deletions.
7 changes: 7 additions & 0 deletions pkg/cronjob/es_rollover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
26 changes: 26 additions & 0 deletions pkg/cronjob/es_rollover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 19 additions & 5 deletions tests/cmd-utils/assert-jaeger-http-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions tests/e2e/elasticsearch/render.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Secret
metadata:
name: htpasswd
data:
htpasswd: {{ .Env.SECRET }}
35 changes: 35 additions & 0 deletions tests/e2e/examples/render.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions tests/e2e/render-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <deploy_mode>:
# * 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 <jaeger_instance_name> <deployment_strategy> <test_step>"
Expand Down Expand Up @@ -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
}


Expand Down
4 changes: 2 additions & 2 deletions tests/templates/allinone-jaeger-assert.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Env.JAEGER_NAME }}
spec:
replicas: 1
status:
readyReplicas: 1
2 changes: 1 addition & 1 deletion tests/templates/assert-http-code.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
4 changes: 2 additions & 2 deletions tests/templates/assert-jaeger-deployment.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Env.JAEGER_NAME }}
spec:
replicas: 1
status:
readyReplicas:: 1

0 comments on commit 39b7fde

Please sign in to comment.