ci: fix resource selection for serial log downloading (#2101)

Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>
Co-authored-by: Otto Bittner <cobittner@posteo.net>
This commit is contained in:
Moritz Sanft 2023-07-13 16:28:33 +02:00 committed by GitHub
parent 6ed8fce6b0
commit 43076e96a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 81 deletions

View File

@ -282,16 +282,18 @@ runs:
CSP: ${{ inputs.cloudProvider }}
run: |
echo "::group::Download boot logs"
CONSTELL_UID=$(yq '.uid' constellation-id.json)
case $CSP in
azure)
AZURE_RESOURCE_GROUP=$(yq eval ".provider.azure.resourceGroup" constellation-conf.yaml)
./.github/actions/constellation_create/az-logs.sh ${AZURE_RESOURCE_GROUP}
;;
gcp)
./.github/actions/constellation_create/gcp-logs.sh
GCP_ZONE=$(yq eval ".provider.gcp.zone" constellation-conf.yaml)
./.github/actions/constellation_create/gcp-logs.sh ${GCP_ZONE} ${CONSTELL_UID}
;;
aws)
./.github/actions/constellation_create/aws-logs.sh us-east-2
./.github/actions/constellation_create/aws-logs.sh us-east-2 ${CONSTELL_UID}
;;
esac
echo "::endgroup::"
@ -302,4 +304,6 @@ runs:
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: serial-logs-${{ inputs.artifactNameSuffix }}
path: "*.log"
path: |
*.log
!terraform.log

View File

@ -6,51 +6,26 @@ set -euo pipefail
shopt -s inherit_errexit
echo "Using AWS region: ${1}"
# TODO(msanft): Remove once 2.9.0 is released
CP_SELECTOR="module.instance_group_control_plane"
W_SELECTOR="module.instance_group_worker_nodes"
if [[ $(./constellation version) != *"2.8.0"* ]]; then
echo "Constellation version is not 2.8.0, using updated ASG selectors"
CP_SELECTOR='module.instance_group["control_plane_default"]'
W_SELECTOR='module.instance_group["worker_default"]'
fi
pushd constellation-terraform
controlAutoscalingGroup=$(
terraform show -json |
jq --arg selector "$CP_SELECTOR" \
-r .'values.root_module.child_modules[] |
select(.address == $selector) |
.resources[0].values.name'
)
workerAutoscalingGroup=$(
terraform show -json |
jq --arg selector "$W_SELECTOR" \
-r .'values.root_module.child_modules[] |
select(.address == $selector) |
.resources[0].values.name'
)
popd
echo "Using Constellation UID: ${2}"
controlInstances=$(
aws autoscaling describe-auto-scaling-groups \
aws ec2 describe-instances \
--filters "Name=tag:constellation-uid,Values=${2}" "Name=tag:constellation-role,Values=control-plane" \
--region "${1}" \
--no-paginate \
--output json \
--auto-scaling-group-names "${controlAutoscalingGroup}" |
jq -r '.AutoScalingGroups[0].Instances[].InstanceId'
--output json |
yq eval '.Reservations[].Instances[].InstanceId' -
)
workerInstances=$(
aws autoscaling describe-auto-scaling-groups \
aws ec2 describe-instances \
--filters "Name=tag:constellation-uid,Values=${2}" "Name=tag:constellation-role,Values=worker" \
--region "${1}" \
--no-paginate \
--output json \
--auto-scaling-group-names "${workerAutoscalingGroup}" |
jq -r '.AutoScalingGroups[0].Instances[].InstanceId'
--output json |
yq eval '.Reservations[].Instances[].InstanceId' -
)
echo "Fetching logs from control planes: ${controlInstances}"
echo "Fetching logs from control planes"
for instance in ${controlInstances}; do
printf "Fetching for %s\n" "${instance}"
@ -59,7 +34,7 @@ for instance in ${controlInstances}; do
tail -n +2 > control-plane-"${instance}".log
done
echo "Fetching logs from worker nodes: ${workerInstances}"
echo "Fetching logs from worker nodes"
for instance in ${workerInstances}; do
printf "Fetching for %s\n" "${instance}"

View File

@ -7,8 +7,8 @@ printf "Fetching logs of instances in resource group %s\n" "${1}"
# get list of all scale sets
scalesetsjson=$(az vmss list --resource-group "${1}" -o json)
scalesetslist=$(echo "${scalesetsjson}" | jq -r '.[] | .name')
subscription=$(az account show | jq -r .id)
scalesetslist=$(echo "${scalesetsjson}" | yq eval '.[] | .name' -)
subscription=$(az account show | yq eval .id -)
printf "Checking scalesets %s\n" "${scalesetslist}"
@ -18,7 +18,7 @@ for scaleset in ${scalesetslist}; do
--resource-group "${1}" \
--name "${scaleset}" \
-o json |
jq -r '.[] | .instanceId'
yq eval '.[] | .instanceId' -
)
printf "Checking instance IDs %s\n" "${instanceids}"
for instanceid in ${instanceids}; do
@ -26,7 +26,7 @@ for scaleset in ${scalesetslist}; do
az rest \
--method post \
--url https://management.azure.com/subscriptions/"${subscription}"/resourceGroups/"${1}"/providers/Microsoft.Compute/virtualMachineScaleSets/"${scaleset}"/virtualmachines/"${instanceid}"/retrieveBootDiagnosticsData?api-version=2022-03-01 |
jq '.serialConsoleLogBlobUri' -r
yq eval '.serialConsoleLogBlobUri' -
)
sleep 4
curl -fsSL -o "./${scaleset}-${instanceid}.log" "${bloburi}"

View File

@ -3,49 +3,19 @@
set -euo pipefail
shopt -s inherit_errexit
pushd constellation-terraform
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'
)
popd
echo "Using Zone: ${1}"
echo "Using Constellation UID: ${2}"
controlInstances=$(
gcloud compute instance-groups managed list-instances "${controlInstanceGroup##*/}" \
--zone "${zone}" \
--format=json |
jq -r '.[] | .instance'
allInstances=$(
gcloud compute instances list \
--filter="labels.constellation-uid=${2}" \
--format=json | yq eval '.[] | .name' -
)
workerInstances=$(
gcloud compute instance-groups managed list-instances "${workerInstanceGroup##*/}" \
--zone "${zone}" \
--format=json |
jq -r '.[] | .instance'
)
allInstances="${controlInstances} ${workerInstances}"
printf "Fetching logs for %s and %s\n" "${controlInstances}" "${workerInstances}"
for instance in ${allInstances}; do
shortName=${instance##*/}
printf "Fetching for %s\n" "${shortName}"
printf "Fetching for %s\n" "${instance}"
gcloud compute instances get-serial-port-output "${instance}" \
--port 1 \
--start 0 \
--zone "${zone}" > "${shortName}".log
--zone "${1}" > "${instance}".log
done