diff --git a/ci-operator/step-registry/gather/gcp-console/OWNERS b/ci-operator/step-registry/gather/gcp-console/OWNERS new file mode 100644 index 0000000000000..6e617161317b6 --- /dev/null +++ b/ci-operator/step-registry/gather/gcp-console/OWNERS @@ -0,0 +1,7 @@ +approvers: +- cgwalters +- enxebre +- jstuever +- patrickdillon +- vrutkovs +- wking diff --git a/ci-operator/step-registry/gather/gcp-console/gather-gcp-console-commands.sh b/ci-operator/step-registry/gather/gcp-console/gather-gcp-console-commands.sh new file mode 100755 index 0000000000000..df9b44883da93 --- /dev/null +++ b/ci-operator/step-registry/gather/gcp-console/gather-gcp-console-commands.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +set -o nounset +set -o errexit +set -o pipefail + +trap 'CHILDREN=$(jobs -p); if test -n "${CHILDREN}"; then kill ${CHILDREN} && wait; fi' TERM + +export GOOGLE_CLOUD_KEYFILE_JSON="${CLUSTER_PROFILE_DIR}/gce.json" +gcloud auth activate-service-account --key-file="${GOOGLE_CLOUD_KEYFILE_JSON}" + +if test ! -f "${SHARED_DIR}/metadata.json" +then + echo "No metadata.json, so unknown GCP project, so unable to gathering console logs." + exit 0 +fi + +gcloud config set project "$(jq -r .gcp.projectID "${SHARED_DIR}/metadata.json")" + +if test -f "${KUBECONFIG}" +then + oc --request-timeout=5s get nodes -o jsonpath --template '{range .items[*]}{.spec.providerID}{"\n"}{end}' | sed 's|.*/||' > "${TMPDIR}/node-provider-IDs.txt" & + wait "$!" + + 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.txt" & + wait "$!" +else + echo "No kubeconfig; skipping providerID extraction." +fi + +if test -f "${SHARED_DIR}/gcp-instance-ids.txt" +then + cat "${SHARED_DIR}/gcp-instance-ids.txt" >> "${TMPDIR}/node-provider-IDs.txt" +fi + +cat "${TMPDIR}/node-provider-IDs.txt" | sort | uniq | while read -r INSTANCE_ID +do + echo "Finding the zone for ${INSTANCE_ID}" + ZONE="$( + gcloud --format json compute instances list "--filter=name=(${INSTANCE_ID})" | jq -r '.[].zone' & + wait "$!" + )" + if test -z "${ZONE}" + then + echo "No zone found for ${INSTANCE_ID}, so not attempting to gather console logs" + fi + echo "Gathering console logs for ${INSTANCE_ID} from ${ZONE}" + gcloud --format json compute instances get-serial-port-output --zone "${ZONE}" "${INSTANCE_ID}" > "${ARTIFACT_DIR}/${INSTANCE_ID}.json" & + wait "$!" +done diff --git a/ci-operator/step-registry/gather/gcp-console/gather-gcp-console-ref.metadata.json b/ci-operator/step-registry/gather/gcp-console/gather-gcp-console-ref.metadata.json new file mode 100644 index 0000000000000..095f2779dabaf --- /dev/null +++ b/ci-operator/step-registry/gather/gcp-console/gather-gcp-console-ref.metadata.json @@ -0,0 +1,13 @@ +{ + "path": "gather/gcp-console/gather-gcp-console-ref.yaml", + "owners": { + "approvers": [ + "cgwalters", + "enxebre", + "jstuever", + "patrickdillon", + "vrutkovs", + "wking" + ] + } +} \ No newline at end of file diff --git a/ci-operator/step-registry/gather/gcp-console/gather-gcp-console-ref.yaml b/ci-operator/step-registry/gather/gcp-console/gather-gcp-console-ref.yaml new file mode 100644 index 0000000000000..74dcc60f53175 --- /dev/null +++ b/ci-operator/step-registry/gather/gcp-console/gather-gcp-console-ref.yaml @@ -0,0 +1,18 @@ +ref: + as: gather-gcp-console + optional_on_success: true + from_image: + namespace: ocp + name: "4.5" + tag: upi-installer + commands: gather-gcp-console-commands.sh + env: + - name: TMPDIR + default: /tmp + documentation: A pathname of a directory made available for programs that need a place to create temporary files. + resources: + requests: + cpu: 300m + memory: 300Mi + documentation: |- + The pre-deprovision artifacts step collects console logs from GCP instances. It gathers console logs for all nodes and machines with a provider ID, as well as any instance IDs listed in ${SHARED_DIR}/gcp-instance-ids.txt. gcp-instance-ids.txt entries should have a single provider ID per line. Duplicate entries are ok; the step deduplicates before gathering. diff --git a/ci-operator/step-registry/ipi/gcp/post/ipi-gcp-post-chain.yaml b/ci-operator/step-registry/ipi/gcp/post/ipi-gcp-post-chain.yaml index 1e277e804a1fa..0ba5581cc71e0 100644 --- a/ci-operator/step-registry/ipi/gcp/post/ipi-gcp-post-chain.yaml +++ b/ci-operator/step-registry/ipi/gcp/post/ipi-gcp-post-chain.yaml @@ -1,6 +1,7 @@ chain: as: ipi-gcp-post steps: + - ref: gather-gcp-console - chain: ipi-deprovision documentation: |- The IPI cleanup step contains all steps that deprovision an OpenShift