Skip to content

Commit

Permalink
Collect logs of initContainers (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy authored May 12, 2021
1 parent 12cb2cc commit 50c76c2
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cicd/_common_deploy_logic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ function get_oc_events {
function get_pod_logs {
LOGS_DIR="$K8S_ARTIFACTS_DIR/logs"
mkdir -p $LOGS_DIR
# get array of pod_name:container for all containers in all pods
PODS_CONTAINERS=($(oc get pods --ignore-not-found=true -n $NAMESPACE -o 'jsonpath={range .items[*]}{.metadata.name}{range .spec.containers[*]}{":"}{.name}{" "}'))
# get array of pod_name:container1,container2,..,containerN for all containers in all pods
PODS_CONTAINERS=($(oc get pods --ignore-not-found=true -n $NAMESPACE -o "jsonpath={range .items[*]}{' '}{.metadata.name}{':'}{range .spec['containers', 'initContainers'][*]}{.name}{','}"))
for pc in ${PODS_CONTAINERS[@]}; do
# https://stackoverflow.com/a/4444841
POD=${pc%%:*}
CONTAINER=${pc#*:}
oc logs $POD -c $CONTAINER -n $NAMESPACE > $LOGS_DIR/${POD}_${CONTAINER}.log || continue
# https://stackoverflow.com/a/4444841
POD=${pc%%:*}
CONTAINERS=${pc#*:}
for container in ${CONTAINERS//,/ }; do
oc logs $POD -c $container -n $NAMESPACE > $LOGS_DIR/${POD}_${container}.log || continue
done
done
}

Expand Down

0 comments on commit 50c76c2

Please sign in to comment.