2022-10-10 08:21:17 -04:00
|
|
|
#!/usr/bin/env bash
|
2022-09-05 12:12:46 -04:00
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
set -euo pipefail
|
|
|
|
shopt -s inherit_errexit
|
2022-10-31 05:40:08 -04:00
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
controlInstanceGroup=$(terraform show -json | jq -r .'values.root_module.child_modules[] | select(.address == "module.instance_group_control_plane") | .resources[0].values.base_instance_name' )
|
|
|
|
workerInstanceGroup=$(terraform show -json | jq -r .'values.root_module.child_modules[] | select(.address == "module.instance_group_worker") | .resources[0].values.base_instance_name')
|
|
|
|
zone=$(terraform show -json | jq -r .'values.root_module.child_modules[] | select(.address == "module.instance_group_control_plane") | .resources[0].values.zone' )
|
2022-10-31 05:40:08 -04:00
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
controlInstanceGroup=${controlInstanceGroup##*/}
|
|
|
|
workerInstanceGroupShort=${workerInstanceGroup##*/}
|
2022-09-05 12:12:46 -04:00
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
controlInstances=$(gcloud compute instance-groups managed list-instances "${controlInstanceGroup}" --zone "${zone}" --format=json | jq -r '.[] | .instance')
|
|
|
|
workerInstances=$(gcloud compute instance-groups managed list-instances "${workerInstanceGroupShort}" --zone "${zone}" --format=json | jq -r '.[] | .instance')
|
2022-09-05 12:12:46 -04:00
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
ALL_INSTANCES="${controlInstances} ${workerInstances}"
|
2022-09-05 12:12:46 -04:00
|
|
|
|
2022-11-10 04:28:35 -05:00
|
|
|
printf "Fetching logs for %s and %s\n" "${controlInstances}" "${workerInstances}"
|
|
|
|
|
|
|
|
for INSTANCE in ${ALL_INSTANCES}; do
|
2022-09-05 12:12:46 -04:00
|
|
|
SHORT_NAME=${INSTANCE##*/}
|
2022-11-10 04:28:35 -05:00
|
|
|
printf "Fetching for %s\n" "${SHORT_NAME}"
|
|
|
|
gcloud compute instances get-serial-port-output "${INSTANCE}" \
|
2022-09-05 12:12:46 -04:00
|
|
|
--port 1 \
|
|
|
|
--start 0 \
|
2022-11-10 04:28:35 -05:00
|
|
|
--zone "${zone}" > "${SHORT_NAME}".log
|
2022-09-05 12:12:46 -04:00
|
|
|
done
|