Skip to content

Commit

Permalink
Add cluster peering
Browse files Browse the repository at this point in the history
  • Loading branch information
Ganeshrockz committed Dec 6, 2023
1 parent 46aec30 commit 6773d6b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 4 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/nightly-ecs-examples-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
name:
- Consul ECS on Fargate
- Consul ECS on EC2
- Mesh gateways
- Cluster peering
include:
- name: Consul ECS on Fargate
region: us-east-1
Expand All @@ -26,10 +28,15 @@ jobs:
working-directory: ./examples/dev-server-ec2
variables: '{\"lb_ingress_ip\": \"eval curl -s ifconfig.me\", \"name\": \"ecs-rtya\"}'

- name: Mesh gateways on Consul ECS
- name: Mesh gateways
region: us-west-1
working-directory: ./examples/mesh-gateways
variables: '{\"lb_ingress_ip\": \"eval curl -s ifconfig.me\", \"name\": \"ecs-oprb\"}'

- name: Cluster peering
region: us-west-2
working-directory: ./examples/cluster-peering
variables: '{\"lb_ingress_ip\": \"eval curl -s ifconfig.me\", \"name\": \"ecs-oerc\"}'
fail-fast: false
uses: ./.github/workflows/reusable-ecs-example-validator.yml
with:
Expand Down
16 changes: 16 additions & 0 deletions examples/cluster-peering/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,20 @@ output "dc1_server_bootstrap_token" {
output "dc2_server_bootstrap_token" {
value = module.dc2.dev_consul_server.bootstrap_token_id
sensitive = true
}

output "client_app_consul_service_name" {
value = local.example_client_app_name
}

output "server_app_consul_service_name" {
value = local.example_server_app_name
}

output "dc1_mesh_gateway_name" {
value = local.mgw_name_1
}

output "dc2_mesh_gateway_name" {
value = local.mgw_name_2
}
81 changes: 81 additions & 0 deletions examples/cluster-peering/validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

# Script that validates if the setup works E2E on ECS.

waitfor() {
echo -n "waiting for ${2} to be registered in Consul"
local count=0
while [[ $count -le 30 ]]; do
echo -n "."
response=$(curl -sS -X GET "${1}/v1/catalog/services")
if [ $? -ne 0 ]; then
echo "Error: curl command failed"
((count++))
continue
fi
echo $response | grep -q "${2}" && return
sleep 10
((count++))
done
echo ""
echo "timeout waiting for ${2}"
exit 1
}

# get Terraform outputs and initialize required variables.
echo "loading Terraform outputs"
tfOutputs=$(terraform output -json)
DC1_CONSUL_SERVER_ADDR=$(echo "$tfOutputs" | jq -rc '.dc1_server_url.value')
DC2_CONSUL_SERVER_ADDR=$(echo "$tfOutputs" | jq -rc '.dc2_server_url.value')

MESH_CLIENT_APP_LB_ADDR=$(echo "$tfOutputs" | jq -rc '.client_lb_address.value')
MESH_CLIENT_APP_LB_ADDR="${MESH_CLIENT_APP_LB_ADDR%/ui}"

CLIENT_APP_NAME=$(echo "$tfOutputs" | jq -rc '.client_app_consul_service_name.value')
SERVER_APP_NAME=$(echo "$tfOutputs" | jq -rc '.server_app_consul_service_name.value')

DC1_MESH_GW_NAME=$(echo "$tfOutputs" | jq -rc '.dc1_mesh_gateway_name.value')
DC2_MESH_GW_NAME=$(echo "$tfOutputs" | jq -rc '.dc2_mesh_gateway_name.value')

# wait for services to be registered in Consul
waitfor ${DC1_CONSUL_SERVER_ADDR} ${CLIENT_APP_NAME}
echo ""

waitfor ${DC2_CONSUL_SERVER_ADDR} ${SERVER_APP_NAME}
echo ""

waitfor ${DC1_CONSUL_SERVER_ADDR} ${DC1_MESH_GW_NAME}
echo ""

waitfor ${DC2_CONSUL_SERVER_ADDR} ${DC2_MESH_GW_NAME}
echo ""

# hit the client app's LB to check if the server app is reachable
echo -n "calling client app's load balancer"

# make the call to the upstream in a loop because it may take some time for the
# exported-service config and service intention to propagate.
count=0
success=false
while [[ $count -le 20 ]]; do
echo -n "."
response=$(curl -s ${MESH_CLIENT_APP_LB_ADDR} 2> /dev/null)
if echo "$response" | grep -q 'Hello World'; then
echo $response
responseCode=$(echo $response | jq -rc '.code')
if [[ "$responseCode" == "200" ]]; then
success=true
break
fi
fi
sleep 20
((count++))
done
echo ""

if [ ! "$success" ]; then
echo "e2e setup for Consul peering on ECS failed!!"
exit 1
fi

echo "e2e setup for Consul peering on ECS is successful!!"
2 changes: 1 addition & 1 deletion examples/dev-server-ec2/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ while [[ $count -le 20 ]]; do
if echo "$response" | grep -q 'Hello World'; then
echo $response
responseCode=$(echo $response | jq -rc '.code')
if "$responseCode" == "200"; then
if [[ "$responseCode" == "200" ]]; then
success=true
break
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/dev-server-fargate/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ while [[ $count -le 20 ]]; do
if echo "$response" | grep -q 'Hello World'; then
echo $response
responseCode=$(echo $response | jq -rc '.code')
if "$responseCode" == "200"; then
if [[ "$responseCode" == "200" ]]; then
success=true
break
fi
Expand Down
2 changes: 1 addition & 1 deletion examples/mesh-gateways/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ while [[ $count -le 20 ]]; do
if echo "$response" | grep -q 'Hello World'; then
echo $response
responseCode=$(echo $response | jq -rc '.code')
if "$responseCode" == "200"; then
if [[ "$responseCode" == "200" ]]; then
success=true
break
fi
Expand Down

0 comments on commit 6773d6b

Please sign in to comment.