Skip to content

Commit 9ce598e

Browse files
Merge pull request #9743 from wking/aws-console-gather-step
gather/aws/console: Add a step to gather console logs on AWS
2 parents cdc3a9c + 390d6be commit 9ce598e

File tree

6 files changed

+62
-5
lines changed

6 files changed

+62
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
approvers:
2+
- cgwalters
3+
- enxebre
4+
- vrutkovs
5+
- wking
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
set -o nounset
4+
set -o errexit
5+
set -o pipefail
6+
7+
trap 'CHILDREN=$(jobs -p); if test -n "${CHILDREN}"; then kill ${CHILDREN} && wait; fi' TERM
8+
9+
export AWS_SHARED_CREDENTIALS_FILE="${CLUSTER_PROFILE_DIR}/.awscred"
10+
11+
if test ! -f "${SHARED_DIR}/metadata.json"
12+
then
13+
echo "No metadata.json, so unknown AWS region, so unable to gathering console logs."
14+
exit 0
15+
fi
16+
17+
if test -f "${KUBECONFIG}"
18+
then
19+
oc --request-timeout=5s get nodes -o jsonpath --template '{range .items[*]}{.spec.providerID}{"\n"}{end}' | sed 's|.*/||' > "${TMPDIR}/node-provider-IDs.txt" &
20+
wait "$!"
21+
22+
oc --request-timeout=5s -n openshift-machine-api get machines -o jsonpath --template '{range .items[*]}{.spec.providerID}{"\n"}{end}' | sed 's|.*/||' >> "${TMPDIR}/node-provider-IDs" &
23+
wait "$!"
24+
else
25+
echo "No kubeconfig; skipping providerID extraction."
26+
exit 0
27+
fi
28+
29+
if test -f "${SHARED_DIR}/aws-instance-ids.txt"
30+
then
31+
cat "${SHARED_DIR}/aws-instance-ids.txt" >> "${TMPDIR}/node-provider-IDs.txt"
32+
fi
33+
34+
REGION="$(jq -r .aws.region "${SHARED_DIR}/metadata.json")"
35+
cat "${TMPDIR}/node-provider-IDs.txt" | sort | uniq | while read -r INSTANCE_ID
36+
do
37+
echo "Gathering console logs for ${INSTANCE_ID}"
38+
aws --region "${REGION}" ec2 get-console-output --instance-id "${INSTANCE_ID}" --output text > "${ARTIFACT_DIR}/${INSTANCE_ID}" &
39+
wait "$!"
40+
done
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ref:
2+
as: gather-aws-console
3+
from: upi-installer
4+
commands: gather-aws-console-commands.sh
5+
env:
6+
- name: TMPDIR
7+
default: /tmp
8+
documentation: A pathname of a directory made available for programs that need a place to create temporary files.
9+
resources:
10+
requests:
11+
cpu: 300m
12+
memory: 300Mi
13+
documentation: |-
14+
The pre-deprovision artifacts step collects console logs from AWS instances. It gathers console logs for all nodes and machines with a provider ID, as well as any instance IDs listed in ${SHARED_DIR}/aws-instance-ids.txt. aws-instance-ids.txt entries should have a single provider ID per line. Duplicate entries are ok; the step deduplicates before gathering.

ci-operator/step-registry/gather/extra/gather-extra-commands.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ echo "Gathering artifacts ..."
2828
mkdir -p ${ARTIFACT_DIR}/pods ${ARTIFACT_DIR}/nodes ${ARTIFACT_DIR}/metrics ${ARTIFACT_DIR}/bootstrap ${ARTIFACT_DIR}/network ${ARTIFACT_DIR}/oc_cmds
2929

3030
oc --insecure-skip-tls-verify --request-timeout=5s get nodes -o jsonpath --template '{range .items[*]}{.metadata.name}{"\n"}{end}' > /tmp/nodes
31-
oc --insecure-skip-tls-verify --request-timeout=5s get nodes -o jsonpath --template '{range .items[*]}{.spec.providerID}{"\n"}{end}' | sed 's|.*/||' > /tmp/node-provider-IDs
32-
oc --insecure-skip-tls-verify --request-timeout=5s -n openshift-machine-api get machines -o jsonpath --template '{range .items[*]}{.spec.providerID}{"\n"}{end}' | sed 's|.*/||' >> /tmp/node-provider-IDs
3331
oc --insecure-skip-tls-verify --request-timeout=5s get pods --all-namespaces --template '{{ range .items }}{{ $name := .metadata.name }}{{ $ns := .metadata.namespace }}{{ range .spec.containers }}-n {{ $ns }} {{ $name }} -c {{ .name }}{{ "\n" }}{{ end }}{{ range .spec.initContainers }}-n {{ $ns }} {{ $name }} -c {{ .name }}{{ "\n" }}{{ end }}{{ end }}' > /tmp/containers
3432
oc --insecure-skip-tls-verify --request-timeout=5s get pods -l openshift.io/component=api --all-namespaces --template '{{ range .items }}-n {{ .metadata.namespace }} {{ .metadata.name }}{{ "\n" }}{{ end }}' > /tmp/pods-api
3533

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
chain:
22
as: ipi-aws-post
33
steps:
4+
- ref: gather-aws-console
45
- chain: ipi-deprovision
56
documentation: |-
6-
The IPI cleanup step contains all steps that deprovision an OpenShift
7-
cluster on AWS, provisioned by the `ipi-aws-pre` chain.
7+
The IPI cleanup step contains all steps that gather and deprovision an OpenShift cluster on AWS, provisioned by the `ipi-aws-pre` chain.

ci-operator/step-registry/ipi/deprovision/ipi-deprovision-chain.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ chain:
44
- chain: gather
55
- ref: ipi-deprovision-deprovision
66
documentation: |-
7-
The IPI deprovision step chain contains all the individual steps necessary to deprovision an OpenShift cluster.
7+
The IPI deprovision step chain contains all the individual steps necessary to gather and deprovision an OpenShift cluster.

0 commit comments

Comments
 (0)