AIAP - Extract logs from runner container

This adds a new script to the runner container that is run in the
entrypoint which runs the log gathering ansible playbook from
inside the runner container. The gate then extracts these logs
with a new role.

This also updates the image_build script to fix how it changes
the container imagePullPolicy

Closes: #658
Relates-To: #659
Change-Id: I24d11c66e7b71852256e164343f7bb2f331d1fef
This commit is contained in:
Michael Beaver 2021-11-08 19:27:54 +00:00
parent 4ed3a80412
commit 56972b4317
8 changed files with 133 additions and 12 deletions

View File

@ -0,0 +1,13 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
kubeconfig: "{{ airshipctl_config_dir_default | default(ansible_env.HOME) }}/.airship/kubeconfig"

View File

@ -0,0 +1,24 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
## This task will populate kctl_context_list variable with list of contexts if they exist
- name: "Download logs from runner container"
include_tasks: save-runner-logs.yaml
- name: "Downloads runner logs to executor"
synchronize:
src: "{{ logs_dir }}/aiap-runner-logs"
dest: "{{ zuul.executor.log_root }}/{{ inventory_hostname }}"
mode: pull
ignore_errors: True
tags: [zuul]

View File

@ -0,0 +1,28 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
- name: "creating directory for pod logs"
file:
path: "{{ logs_dir }}/aiap-runner-logs"
state: directory
- name: "retrieve all container logs, current and previous (if they exist)"
shell: |-
set -e
export KUBECONFIG="{{ kubeconfig }}"
kubectl cp airship-in-a-pod:/tmp/logs /tmp/logs/aiap-runner-logs -c runner
args:
executable: /bin/bash
ignore_errors: True
...

View File

@ -17,7 +17,14 @@ RUN apt-get update ;\
ca-certificates \
gnupg-agent \
libvirt-clients \
gettext-base ;\
gettext-base \
wget \
iptables \
rsync \
make; \
pip3 install --upgrade ansible; \
pip3 install --upgrade netaddr; \
pip3 install --upgrade yq; \
curl -sSLo /usr/local/bin/kubectl "${kubectl_url}" ;\
chmod +x /usr/local/bin/kubectl ;\
rm -rf /var/lib/apt/lists/*

View File

@ -17,6 +17,9 @@ set -ex
/signal_status "runner" "RUNNING"
success=false
function reportStatus() {
# Run the get-logs script while inside the airshipctl repo to run the
# ansible log gathering playbooks before sending the signal status
/get-logs.sh
if [[ "$success" == "false" ]]; then
/signal_status "runner" "FAILED"
else
@ -103,4 +106,5 @@ fi
./tools/deployment/25_deploy_gating.sh
success=true

View File

@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
set -xe
export AIRSHIPCTL_WS=${AIRSHIPCTL_WS:-$PWD}
export TMP_DIR=${TMP_DIR:-"$(dirname "$(mktemp -u)")"}
ANSIBLE_CFG=${ANSIBLE_CFG:-"${HOME}/.ansible.cfg"}
ANSIBLE_HOSTS=${ANSIBLE_HOSTS:-"${TMP_DIR}/ansible_hosts"}
PLAYBOOK_CONFIG=${PLAYBOOK_CONFIG:-"${TMP_DIR}/config.yaml"}
mkdir -p "$TMP_DIR"
envsubst <"${AIRSHIPCTL_WS}/tools/gate/config_template.yaml" > "$PLAYBOOK_CONFIG"
echo "primary ansible_host=localhost ansible_connection=local ansible_python_interpreter=/usr/bin/python3" > "$ANSIBLE_HOSTS"
printf "[defaults]\nroles_path = %s/roles:zuul-jobs/roles\n" "$AIRSHIPCTL_WS" > "$ANSIBLE_CFG"
sudo -E ansible-playbook -i "$ANSIBLE_HOSTS" \
playbooks/airship-collect-logs.yaml \
-e @"$PLAYBOOK_CONFIG" \
-e 'log_roles="[\"gather-system-logs\", \"airship-gather-libvirt-logs\", \"airship-gather-runtime-logs\", \"airship-airshipctl-gather-configs\", \"describe-kubernetes-objects\", \"airship-gather-pod-logs\"]"'

View File

@ -35,43 +35,48 @@ done
# Now that we have built/pulled the images, lets change the imagePullPolicy to
# Never to be 100% confident they are used
echo "- op: add
echo "- op: replace
path: \"/spec/containers/0/imagePullPolicy\"
value: Never
- op: add
- op: replace
path: \"/spec/containers/1/imagePullPolicy\"
value: Never
- op: add
- op: replace
path: \"/spec/containers/2/imagePullPolicy\"
value: Never
- op: add
- op: replace
path: \"/spec/containers/3/imagePullPolicy\"
value: Never
- op: add
- op: replace
path: \"/spec/containers/4/imagePullPolicy\"
value: Never
- op: add
- op: replace
path: \"/spec/containers/5/imagePullPolicy\"
value: Never
- op: add
- op: replace
path: \"/spec/containers/6/imagePullPolicy\"
value: Never
" >> examples/airshipctl/patchset.yaml
- op: replace
path: \"/spec/containers/7/imagePullPolicy\"
value: Never
# Also add the patchset to the environment variables
" >> examples/airshipctl/replacements.yaml
# Also replace the patchset to the environment variables
# while being sure to escape the slashes from the ref
echo "- op: replace
path: \"/spec/containers/4/env/6/value\"
value: $AIRSHIPCTL_REF
" >> examples/airshipctl/patchset.yaml
" >> examples/airshipctl/replacements.yaml
popd || exit
popd || exit

View File

@ -187,6 +187,7 @@
- airship-airshipctl-gather-configs
- describe-kubernetes-objects
- airship-gather-pod-logs
- aiap-gather-runner-vm-logs
voting: false
- job:
name: airship-airshipctl-gate-script-runner-docker