# 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 cluster scoped objects" file: path: "{{ logs_dir }}/objects/cluster" state: directory - name: "Gathering descriptions for cluster scoped objects" shell: |- set -e export OBJECT_TYPE=node,clusterrole,clusterrolebinding,storageclass,namespace export PARALLELISM_FACTOR=2 function list_objects () { printf ${OBJECT_TYPE} | xargs -d ',' -I {} -P1 -n1 bash -c 'echo "$@"' _ {} } export -f list_objects function name_objects () { export OBJECT=$1 kubectl get ${OBJECT} -o name | xargs -L1 -I {} -P1 -n1 bash -c 'echo "${OBJECT} ${1#*/}"' _ {} } export -f name_objects function get_objects () { input=($1) export OBJECT=${input[0]} export NAME=${input[1]#*/} echo "${OBJECT}/${NAME}" DIR="{{ logs_dir }}/objects/cluster/${OBJECT}" mkdir -p ${DIR} kubectl get ${OBJECT} ${NAME} -o yaml > "${DIR}/${NAME}.yaml" kubectl describe ${OBJECT} ${NAME} > "${DIR}/${NAME}.txt" } export -f get_objects list_objects | \ xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'name_objects "$@"' _ {} | \ xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'get_objects "$@"' _ {} args: executable: /bin/bash ignore_errors: True - name: "creating directory for namespace scoped objects" file: path: "{{ logs_dir }}/objects/namespaced" state: directory - name: "Gathering descriptions for namespace scoped objects" shell: |- set -e export OBJECT_TYPE=configmaps,cronjobs,daemonsets,deployment,endpoints,ingresses,jobs,networkpolicies,pods,podsecuritypolicies,persistentvolumeclaims,rolebindings,roles,secrets,serviceaccounts,services,statefulsets export PARALLELISM_FACTOR=2 function get_namespaces () { kubectl get namespaces -o name | awk -F '/' '{ print $NF }' } function list_namespaced_objects () { export NAMESPACE=$1 printf ${OBJECT_TYPE} | xargs -d ',' -I {} -P1 -n1 bash -c 'echo "${NAMESPACE} $@"' _ {} } export -f list_namespaced_objects function name_objects () { input=($1) export NAMESPACE=${input[0]} export OBJECT=${input[1]} kubectl get -n ${NAMESPACE} ${OBJECT} -o name | xargs -L1 -I {} -P1 -n1 bash -c 'echo "${NAMESPACE} ${OBJECT} $@"' _ {} } export -f name_objects function get_objects () { input=($1) export NAMESPACE=${input[0]} export OBJECT=${input[1]} export NAME=${input[2]#*/} echo "${NAMESPACE}/${OBJECT}/${NAME}" DIR="{{ logs_dir }}/objects/namespaced/${NAMESPACE}/${OBJECT}" mkdir -p ${DIR} kubectl get -n ${NAMESPACE} ${OBJECT} ${NAME} -o yaml > "${DIR}/${NAME}.yaml" kubectl describe -n ${NAMESPACE} ${OBJECT} ${NAME} > "${DIR}/${NAME}.txt" } export -f get_objects get_namespaces | \ xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'list_namespaced_objects "$@"' _ {} | \ xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'name_objects "$@"' _ {} | \ xargs -r -n 1 -P ${PARALLELISM_FACTOR} -I {} bash -c 'get_objects "$@"' _ {} args: executable: /bin/bash ignore_errors: True - name: "Downloads logs to executor" synchronize: src: "{{ logs_dir }}/objects" dest: "{{ zuul.executor.log_root }}/{{ inventory_hostname }}" mode: pull ignore_errors: yes