Skip to content

Commit

Permalink
[dash0] improve local k8s deployment
Browse files Browse the repository at this point in the history
- git pull dash0-configuration repo automatically
- wait for frontend and frontendproxy pods before starting port
  forwarding (will fail otherwise)
  • Loading branch information
basti1302 committed Feb 27, 2024
1 parent 73e80f9 commit a9421e5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
12 changes: 9 additions & 3 deletions kubernetes/local/deploy-two-namespaces.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ set -euo pipefail

cd -P -- "$(dirname -- "$0")"

source manage-kubectx
source utils

git_pull_dash0_configuration

trap switch_back_to_original_context EXIT
switch_to_local_context

./teardown.sh no-context-switch

sleep 5

yq --from-file ns1.yq ../../../dash0-configuration/demo/environments/aws/demo-eu-west-1-demo.yaml > ns1-values.yaml
yq --from-file ns2.yq ../../../dash0-configuration/demo/environments/aws/demo-eu-west-1-demo.yaml > ns2-values.yaml
yq --from-file ns1.yq $dash0_configuration_dir/demo/environments/aws/demo-eu-west-1-demo.yaml > ns1-values.yaml
yq --from-file ns2.yq $dash0_configuration_dir/demo/environments/aws/demo-eu-west-1-demo.yaml > ns2-values.yaml

helm install --namespace otel-demo-ns1 --create-namespace opentelemetry-demo-postgresql oci://registry-1.docker.io/bitnamicharts/postgresql --values postgres-values.yaml
helm install --namespace otel-demo-ns1 --create-namespace opentelemetry-demo-ns1 open-telemetry/opentelemetry-demo --values ns1-values.yaml
Expand All @@ -26,5 +29,8 @@ kubectl cp ../../src/ffspostgres/init-scripts/20-ffs_data.sql --namespace otel-d
kubectl exec --namespace otel-demo-ns1 opentelemetry-demo-postgresql-0 -- psql postgresql://ffs:ffs@localhost/ffs -a -f /tmp/10-ffs_schema.sql
kubectl exec --namespace otel-demo-ns1 opentelemetry-demo-postgresql-0 -- psql postgresql://ffs:ffs@localhost/ffs -a -f /tmp/20-ffs_data.sql

echo waiting for the frontend and frontendproxy pod to become ready
kubectl wait --namespace otel-demo-ns-1 --for=condition=ready pod -l app.kubernetes.io/component=frontendproxy --timeout 10s
kubectl wait --namespace otel-demo-ns-1 --for=condition=ready pod -l app.kubernetes.io/component=frontend --timeout 20s
kubectl port-forward --namespace otel-demo-ns1 service/opentelemetry-demo-ns1-frontendproxy 8080:8080

10 changes: 8 additions & 2 deletions kubernetes/local/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ set -euo pipefail

cd -P -- "$(dirname -- "$0")"

source manage-kubectx
source utils

git_pull_dash0_configuration

trap switch_back_to_original_context EXIT
switch_to_local_context

./teardown.sh no-context-switch

sleep 5

yq --from-file dash0-one-ns.yq ../../../dash0-configuration/demo/environments/aws/demo-eu-west-1-demo.yaml > dash0-values.yaml
yq --from-file dash0-one-ns.yq $dash0_configuration_dir/demo/environments/aws/demo-eu-west-1-demo.yaml > dash0-values.yaml

helm install --namespace otel-demo-ns --create-namespace opentelemetry-demo-postgresql oci://registry-1.docker.io/bitnamicharts/postgresql --values postgres-values.yaml
helm install \
Expand All @@ -28,5 +31,8 @@ kubectl cp ../../src/ffspostgres/init-scripts/20-ffs_data.sql --namespace otel-d
kubectl exec --namespace otel-demo-ns opentelemetry-demo-postgresql-0 -- psql postgresql://ffs:ffs@localhost/ffs -a -f /tmp/10-ffs_schema.sql
kubectl exec --namespace otel-demo-ns opentelemetry-demo-postgresql-0 -- psql postgresql://ffs:ffs@localhost/ffs -a -f /tmp/20-ffs_data.sql

echo waiting for the frontend and frontendproxy pod to become ready
kubectl wait --namespace otel-demo-ns --for=condition=ready pod -l app.kubernetes.io/component=frontendproxy --timeout 10s
kubectl wait --namespace otel-demo-ns --for=condition=ready pod -l app.kubernetes.io/component=frontend --timeout 20s
kubectl port-forward --namespace otel-demo-ns service/opentelemetry-demo-frontendproxy 8080:8080

3 changes: 2 additions & 1 deletion kubernetes/local/teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ set -euo pipefail

cd -P -- "$(dirname -- "$0")"

source utils

if [[ ${1:-} != "no-context-switch" ]]; then
# If called directly from the shell (and not from deploy.sh etc.), we need to
# make sure that we work in the local Kubernetes context.
source manage-kubectx
trap switch_back_to_original_context EXIT
switch_to_local_context
fi
Expand Down
14 changes: 14 additions & 0 deletions kubernetes/local/manage-kubectx → kubernetes/local/utils
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
dash0_configuration_dir=../../../dash0-configuration

# Switches to the local Kubernetes context (docker-desktop by default) and sets
# the variable original_context to the previously active context name.
function switch_to_local_context {
Expand All @@ -20,3 +22,15 @@ function switch_back_to_original_context {
echo "switching back to Kubernetes context $original_context"
kubectx $original_context
}

function git_pull_dash0_configuration {
if [[ ! -e $dash0_configuration_dir ]]; then
echo Error: expected $dash0_configuration_dir to exist, but it does not.
exit 1
fi
echo executing git pull in $dash0_configuration_dir
pushd $dash0_configuration_dir > /dev/null
git pull
popd > /dev/null
}

0 comments on commit a9421e5

Please sign in to comment.