Skip to content

Commit

Permalink
chore(test-resources): remove sleeps, wait for conditions instead
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
basti1302 committed Sep 17, 2024
1 parent 1799e97 commit 1351a8e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
16 changes: 8 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ image built from local sources) as the default setting.

The e2e tests might sometimes not be the best tool to troubleshoot the operator, simply because they remove everything
they deploy in their `AfterAll`/`AfterEach` hooks. The scripts in `test-resources/bin` can be used for these cases:
* `test-resources/bin/test-roundtrip-01-aum-operator-cr.sh`: Deploys an application under monitoring (this is
* `test-resources/bin/test-scenario-01-aum-operator-cr.sh`: Deploys an application under monitoring (this is
abbreviated to "aum" in the name of the script) to the namespace `test-namespace`, then it deploys the operator to
the namespace `dash-operator-system`, and finally it deploys the Dash0 monitoring resource to `test-namespace`. This is a
test scenario for instrumenting _existing_ workloads via the controller's reconcile loop.
* `test-resources/bin/test-roundtrip-02-operator-cr-aum.sh`: Deploys the operator to `dash0-system`, then the
* `test-resources/bin/test-scenario-02-operator-cr-aum.sh`: Deploys the operator to `dash0-system`, then the
Dash0 monitoring resource to namespace `test-namespace`, and finally an application under monitoring to the namespace
`test-namespace`. This is a test scenario for instrumenting _new_ workloads at deploy time via the admission webhook.
* `test-resources/bin/test-cleanup.sh`: This script removes all resources created by the other scripts. **You should
always this script after running any of the other scripts, when you are done with your tests, otherwise the e2e
tests will fail the next time you start them.** Note that all above the scripts call this script at the beginning, so
there is no need to clean up between individual invocations of the test scripts.
always run this script after running any of the scenario scripts, when you are done with your tests, otherwise the
e2e tests will fail the next time you start them.** Note that all scenario scripts call the cleanup at the beginning,
so there is no need to clean up between individual invocations of the scenario scripts.
* All scripts will, by default, use the target namespace `test-namespace` and the workload type `deployment`. They all
accept two command line parameters to override these defaults. For example, use
`test-resources/bin/test-roundtrip-01-aum-operator-cr.sh another-namespace replicaset` to run the scenario with
`test-resources/bin/test-scenario-01-aum-operator-cr.sh another-namespace replicaset` to run the scenario with
the target namespace `another-namespace` and a replica set workload.
* Additional parameterization can be achieved via environment variables, for example:
* To run the scenario with the images that have been built from the main branch and pushed to ghcr.io most
Expand All @@ -157,7 +157,7 @@ they deploy in their `AfterAll`/`AfterEach` hooks. The scripts in `test-resource
FILELOG_OFFSET_SYNCH_IMG_REPOSITORY=ghcr.io/dash0hq/filelog-offset-synch \
FILELOG_OFFSET_SYNCH_IMG_TAG=main-dev \
FILELOG_OFFSET_SYNCH_IMG_PULL_POLICY="" \
test-resources/bin/test-roundtrip-01-aum-operator-cr.sh
test-resources/bin/test-scenario-01-aum-operator-cr.sh
```
* To run the scenario with the helm chart from the official remote repository and the default images referenced in
that chart (the Helm repository must have been installed beforehand):
Expand All @@ -179,7 +179,7 @@ they deploy in their `AfterAll`/`AfterEach` hooks. The scripts in `test-resource
FILELOG_OFFSET_SYNCH_IMG_REPOSITORY="" \
FILELOG_OFFSET_SYNCH_IMG_TAG="" \
FILELOG_OFFSET_SYNCH_IMG_PULL_POLICY="" \
test-resources/bin/test-roundtrip-01-aum-operator-cr.sh
test-resources/bin/test-scenario-01-aum-operator-cr.sh
```
Note: Unsetting parameters like `CONTROLLER_IMG_REPOSITORY` explicitly (by setting them to an empty string) will
lead to the scenario not setting those values when deploying via helm, so that the default value from the chart
Expand Down
2 changes: 1 addition & 1 deletion internal/dash0/webhooks/instrumentation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (h *InstrumentationWebhookHandler) Handle(ctx context.Context, request admi
}); err != nil {
if apierrors.IsNotFound(err) {
msg := fmt.Sprintf(
"There is no Dash0 monitoring resource in the namespace %s, the workload will not be instrumented.",
"There is no Dash0 monitoring resource in the namespace %s, the workload will not be instrumented by the webhook.",
targetNamespace,
)
if request.Operation == admissionv1.Update {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@ deploy_via_helm
echo
echo

sleep 5

echo "STEP 7: deploy the Dash0 operator configuration resource to cluster"
install_operator_configuration_resource
echo
echo

sleep 10

echo "STEP 8: deploy the Dash0 monitoring resource to namespace ${target_namespace}"
install_monitoring_resource

Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,16 @@ deploy_via_helm
echo
echo

sleep 5

echo "STEP 6: deploy the Dash0 operator configuration resource to cluster"
install_operator_configuration_resource
echo
echo

sleep 10

echo "STEP 7: deploy the Dash0 monitoring resource to namespace ${target_namespace}"
install_monitoring_resource
echo
echo

sleep 5

echo "STEP 8: deploy application under monitoring"
test-resources/node.js/express/deploy.sh ${target_namespace} ${kind}

28 changes: 28 additions & 0 deletions test-resources/bin/util
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ deploy_via_helm() {
echo Helm install command:
echo "$helm_install_command"
$helm_install_command

wait_for_operator_manager_and_webhook
}


wait_for_operator_manager_and_webhook() {
echo "waiting for the operator deployment to become available..."
kubectl wait deployment.apps/dash0-operator-controller --for condition=Available --namespace dash0-system --timeout 30s

echo "waiting for the operator's webhook endpoint to become available..."
for ((i=0; i<=100; i++)); do
endpoints_output=$(kubectl get endpoints --namespace dash0-system dash0-operator-webhook-service)
expected_endpoint_regex='dash0-operator-webhook-service[[:blank:]]+[[:digit:]\.]+:9443'
if [[ "$endpoints_output" =~ $expected_endpoint_regex ]]; then
break;
fi
sleep 0.3
done
}

has_been_set_to_empty_string() {
Expand All @@ -123,8 +141,18 @@ has_been_set_to_empty_string() {

install_operator_configuration_resource() {
kubectl apply -f test-resources/customresources/dash0operatorconfiguration/dash0operatorconfiguration.secret.yaml

echo "waiting for the operator configuration resource to become available"
kubectl wait dash0operatorconfigurations.operator.dash0.com/dash0-operator-configuration-resource --for condition=Available

# Deploying the operator configuration resource might result in a restart of the operator manager deployment pod,
# hence we check again that both are up and running.
wait_for_operator_manager_and_webhook
}

install_monitoring_resource() {
kubectl apply -n ${target_namespace} -f test-resources/customresources/dash0monitoring/dash0monitoring.yaml

echo "waiting for the monitoring resource to become available"
kubectl wait --namespace ${target_namespace} dash0monitorings.operator.dash0.com/dash0-monitoring-resource --for condition=Available
}

0 comments on commit 1351a8e

Please sign in to comment.