Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions hack/testing-olm/test-001-operator-sdk-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,5 @@ deploy_elasticsearch_operator

TEST_OPERATOR_NAMESPACE=${TEST_NAMESPACE} \
TEST_WATCH_NAMESPACE=${TEST_NAMESPACE} \
go test -v ./test/e2e-olm/... -kubeconfig=${KUBECONFIG} -parallel=1 -timeout 1500s 2>&1 | \
go test -v ./test/e2e-olm/... -kubeconfig=${KUBECONFIG} -parallel=1 -timeout 1500s 2>&1 -run "TestKibana|TestElasticsearchCluster" | \
$GO_JUNIT_REPORT | awk '/<properties>/,/<\/properties>/ {next} {print}' > "$JUNIT_REPORT_OUTPUT_DIR/$test_name.xml"

83 changes: 10 additions & 73 deletions hack/testing-olm/test-200-verify-es-metrics-access.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
# allowed to retrieve metrices from elasticsearch
set -euo pipefail

KUBECONFIG=${KUBECONFIG:-$HOME/.kube/config}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to have the KUBECONFIG here? the tests worked correctly before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we need KUBECONFIG here because the new operator sdk has removed its test framework, so we need to set KUBECONFIG for the go test command. Actually, we have done similar change to test-001:

KUBECONFIG=${KUBECONFIG:-$HOME/.kube/config}


repo_dir="$(dirname $0)/../.."
source "${repo_dir}/hack/lib/init.sh"
source "${repo_dir}/hack/testing-olm/utils"

test_name="test-200-verify-es-metrics-access"

test_artifact_dir=$ARTIFACT_DIR/$(basename ${BASH_SOURCE[0]})
if [ ! -d $test_artifact_dir ] ; then
mkdir -p $test_artifact_dir
Expand Down Expand Up @@ -41,6 +45,7 @@ cleanup(){
oc delete clusterrole ${CLUSTERROLE} >> $test_artifact_dir/cleanup.log 2>&1 ||:
oc delete clusterrolebinding ${CLUSTERROLE} >> $test_artifact_dir/cleanup.log 2>&1 ||:
oc delete clusterrolebinding view-${CLUSTERROLE} >> $test_artifact_dir/cleanup.log 2>&1 ||:
oc delete clusterrolebinding view-${CLUSTERROLE}-unauth >> $test_artifact_dir/cleanup.log 2>&1 ||:
fi

set -e
Expand All @@ -59,78 +64,10 @@ if [ "${DO_SETUP:-true}" == "true" ] ; then

export ELASTICSEARCH_OPERATOR_NAMESPACE=${TEST_NAMESPACE}
deploy_elasticsearch_operator

os::cmd::expect_success "${repo_dir}/hack/cert_generation.sh /tmp/example-secrets ${TEST_NAMESPACE} elasticsearch"
os::cmd::expect_success "${repo_dir}/hack/deploy-example-secrets.sh ${TEST_NAMESPACE}"
os::cmd::expect_success "oc -n ${TEST_NAMESPACE} create -f ${repo_dir}/hack/cr.yaml"

os::log::info "---------------------------------------------------------------"
os::log::info "Waiting for elasticsearch-operator to deploy the cluster..."
os::log::info "---------------------------------------------------------------"
os::cmd::try_until_success "oc -n ${TEST_NAMESPACE} get deployment -l component=elasticsearch -o jsonpath='{.items[0].metadata.name}'" $((2 * $minute))
os::cmd::expect_success "oc wait -n ${TEST_NAMESPACE} --timeout=240s --for=condition=available deployment -l component=elasticsearch"

fi

os::log::info "------------------------------------------"
os::log::info "Creating serviceaccounts to verify metrics"
os::log::info "------------------------------------------"
oc -n ${TEST_NAMESPACE} create serviceaccount ${UNAUTHORIZED_SA}
oc -n ${TEST_NAMESPACE} create serviceaccount ${AUTHORIZED_SA}

os::log::info "-------------------------------------------------------------"
os::log::info "Creating RBAC for authorised serviceaccount to verify metrics"
os::log::info "-------------------------------------------------------------"
result=$(oc get clusterrole ${CLUSTERROLE} --ignore-not-found ||:)
if [ "$result" == "" ] ; then
echo "{\"apiVersion\":\"rbac.authorization.k8s.io/v1\", \"kind\":\"ClusterRole\",\"metadata\":{\"name\":\"${CLUSTERROLE}\"},\"rules\":[{\"nonResourceURLs\":[\"/metrics\"],\"verbs\":[\"get\"]}]}" | oc create -f -
fi
result=$(oc get clusterrolebinding ${CLUSTERROLE} --ignore-not-found ||:)
if [ "$result" == "" ] ; then
os::log::info Binding ${AUTHORIZED_SA} to be cable of reading metrics
oc create clusterrolebinding --clusterrole=${CLUSTERROLE} ${CLUSTERROLE} --serviceaccount=${TEST_NAMESPACE}:${AUTHORIZED_SA}
fi
result=$(oc get clusterrolebinding view-${CLUSTERROLE} --ignore-not-found ||:)
if [ "$result" == "" ] ; then
os::log::info Binding ${AUTHORIZED_SA} to be cable of getting namespaces
oc create clusterrolebinding --clusterrole=basic-user view-${CLUSTERROLE} --serviceaccount=${TEST_NAMESPACE}:${AUTHORIZED_SA}
fi

os::log::info "---------------------------------------------------------------"
os::log::info "Creating RBAC for unauthorised serviceaccount to verify metrics"
os::log::info "---------------------------------------------------------------"
result=$(oc get clusterrolebinding view-${CLUSTERROLE}-unauth --ignore-not-found ||:)
if [ "$result" == "" ] ; then
os::log::info Binding ${UNAUTHORIZED_SA} to be cable of getting namespaces
oc create clusterrolebinding --clusterrole=basic-user view-${CLUSTERROLE}-unauth --serviceaccount=${TEST_NAMESPACE}:${UNAUTHORIZED_SA}
fi

es_pod=$(oc -n ${TEST_NAMESPACE} get pod -l component=elasticsearch -o jsonpath={.items[0].metadata.name})

os::log::info "---------------------------------------------------------------"
os::log::info "Waiting until elasticsearch cluster initialization is completed"
os::log::info "---------------------------------------------------------------"
os::cmd::expect_success "oc -n ${TEST_NAMESPACE} wait --for=condition=Ready pod/${es_pod} --timeout=120s"

push_test_script_to_es(){
es_pod=$1
token=$2
service_ip=elasticsearch-metrics.${TEST_NAMESPACE}.svc
echo "curl -ks -o /tmp/metrics.txt https://${service_ip}:60001/_prometheus/metrics -H Authorization:'Bearer ${token}' -w '%{response_code}\n'" > /tmp/test
os::cmd::expect_success "oc -n ${TEST_NAMESPACE} cp /tmp/test ${es_pod}:/tmp/test -c elasticsearch"
os::cmd::expect_success "oc -n ${TEST_NAMESPACE} exec ${es_pod} -c elasticsearch -- chmod 777 /tmp/test"
}

os::log::info "---------------------------------------------------------------------------"
os::log::info "Checking ${AUTHORIZED_SA} ability to read metrics through metrics service"
os::log::info "---------------------------------------------------------------------------"
token=$(oc -n ${TEST_NAMESPACE} serviceaccounts get-token $AUTHORIZED_SA)
push_test_script_to_es $es_pod $token
os::cmd::expect_success_and_text "oc -n ${TEST_NAMESPACE} exec ${es_pod} -c elasticsearch -- bash -c /tmp/test" '200'

os::log::info "---------------------------------------------------------------------------"
os::log::info "Checking ${UNAUTHORIZED_SA} ability to read metrics through metrics service"
os::log::info "---------------------------------------------------------------------------"
token=$(oc -n ${TEST_NAMESPACE} serviceaccounts get-token $UNAUTHORIZED_SA)
push_test_script_to_es $es_pod $token
os::cmd::expect_success_and_text "oc -n ${TEST_NAMESPACE} exec ${es_pod} -c elasticsearch -- bash -c /tmp/test" '403'
CLUSTERROLE=${CLUSTERROLE} AUTHORIZED_SA=${AUTHORIZED_SA} UNAUTHORIZED_SA=${UNAUTHORIZED_SA} \
TEST_OPERATOR_NAMESPACE=${TEST_NAMESPACE} \
TEST_WATCH_NAMESPACE=${TEST_NAMESPACE} \
go test -v ./test/e2e-olm/... -kubeconfig=${KUBECONFIG} -parallel=1 -timeout 1500s -run TestElasticsearchOperatorMetrics | \
$GO_JUNIT_REPORT | awk '/<properties>/,/<\/properties>/ {next} {print}' > "$JUNIT_REPORT_OUTPUT_DIR/$test_name.xml"
40 changes: 5 additions & 35 deletions hack/testing-olm/test-657-im-block-autocreate-for-write-suffix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ repo_dir="$(dirname $0)/../.."
source "${repo_dir}/hack/lib/init.sh"
source "${repo_dir}/hack/testing-olm/utils"

test_name="test-657-im-block-autocreate-for-write-suffix"

test_artifact_dir=$ARTIFACT_DIR/$(basename ${BASH_SOURCE[0]})
if [ ! -d $test_artifact_dir ] ; then
mkdir -p $test_artifact_dir
Expand Down Expand Up @@ -53,40 +55,8 @@ if [ "${DO_SETUP:-true}" == "true" ] ; then

export ELASTICSEARCH_OPERATOR_NAMESPACE=${TEST_NAMESPACE}
deploy_elasticsearch_operator
#deploy elasticsearch cluster
os::cmd::expect_success "${repo_dir}/hack/cert_generation.sh /tmp/example-secrets ${TEST_NAMESPACE} elasticsearch"
os::cmd::expect_success "${repo_dir}/hack/deploy-example-secrets.sh ${TEST_NAMESPACE}"
os::cmd::expect_success "oc -n ${TEST_NAMESPACE} create -f ${repo_dir}/hack/cr.yaml"

os::log::info "---------------------------------------------------------------"
os::log::info "Waiting for elasticsearch-operator to deploy the cluster..."
os::log::info "---------------------------------------------------------------"
os::cmd::try_until_success "oc -n ${TEST_NAMESPACE} get deployment -l component=elasticsearch -o jsonpath='{.items[0].metadata.name}'" $((2 * $minute))

fi
#wait for pod
os::log::info "---------------------------------------------------------------"
os::log::info "Waiting for elasticsearch deployment to be ready..."
os::log::info "---------------------------------------------------------------"
wait_for_deployment_to_be_ready ${TEST_NAMESPACE} $(oc -n ${TEST_NAMESPACE} get deployment -l component=elasticsearch -o jsonpath={.items[0].metadata.name}) $((2 * $minute))

pod=$(oc -n $TEST_NAMESPACE get pod -l component=elasticsearch -o jsonpath={.items[0].metadata.name})
os::log::info "---------------------------------------------------------------"
os::log::info Attempt to autocreate an index without a '-write' suffix...
os::log::info "---------------------------------------------------------------"
os::cmd::expect_success_and_text "oc -n $TEST_NAMESPACE exec $pod -c elasticsearch -- es_util --query=foo/_doc/1 -d '{\"key\":\"value\"}' -XPUT -w %{http_code}" ".*201"

os::log::info "---------------------------------------------------------------"
os::log::info Attempt to autocreate an index with a '-write' suffix...
os::log::info "---------------------------------------------------------------"
os::cmd::expect_success_and_text "oc -n $TEST_NAMESPACE exec $pod -c elasticsearch -- es_util --query=foo-write/_doc/1 -d '{\"key\":\"value\"}' -XPUT -w %{http_code}" ".*404"

os::log::info "---------------------------------------------------------------"
os::log::info Explicitly creating an index with a '-write' suffix...
os::log::info "---------------------------------------------------------------"
os::cmd::expect_success_and_text "oc -n $TEST_NAMESPACE exec $pod -c elasticsearch -- es_util --query=foo-write -XPUT -w %{http_code}" ".*200"

os::log::info "---------------------------------------------------------------"
os::log::info Verifying can write to index with a '-write' suffix...
os::log::info "---------------------------------------------------------------"
os::cmd::expect_success_and_text "oc -n $TEST_NAMESPACE exec $pod -c elasticsearch -- es_util --query=foo-write/_doc/1 -d '{\"key\":\"value\"}' -XPUT -w %{http_code}" ".*201"
TEST_WATCH_NAMESPACE=${TEST_NAMESPACE} TEST_OPERATOR_NAMESPACE=${TEST_NAMESPACE} \
go test -v ./test/e2e-olm/... -kubeconfig=${KUBECONFIG} -parallel=1 -timeout 1500s -run TestElasticsearchWrite | \
$GO_JUNIT_REPORT | awk '/<properties>/,/<\/properties>/ {next} {print}' > "$JUNIT_REPORT_OUTPUT_DIR/$test_name.xml"
Loading