github.com/imran-kn/cilium-fork@v1.6.9/contrib/scripts/bugtool-multinode-gather.sh (about)

     1  #!/bin/bash
     2  
     3  # Usage
     4  # ./bugtool-multinode-gather.sh <OUTPUT_DIR> <NAMESPACE> <LABEL> <OUTPUT_ARCHIVE>
     5  #
     6  # Running without arguments is the same as
     7  # 
     8  # ./bugtool-multinode-gather.sh `mktemp -d` kube-system k8s-app=cilium "`mktemp`.tar.gz"
     9  
    10  OUTPUT_DIR=${1:-"`mktemp -d`"}
    11  NAMESPACE=${2:-"kube-system"}
    12  LABEL=${3:-"k8s-app=cilium"}
    13  OUTPUT_ARCHIVE=${4:-"`mktemp`.tar.gz"}
    14  
    15  mkdir -pv ${OUTPUT_DIR}
    16  function cleanup {
    17    if [ "${OUTPUT_DIR}" == "/" ]; then
    18      echo "Aborting cleanup OUTPUT_DIR=${OUTPUT_DIR}"
    19      exit 0
    20    fi
    21    rm -rf ${OUTPUT_DIR}
    22  }
    23  trap cleanup EXIT
    24  
    25  for CILIUM in $(kubectl -n ${NAMESPACE} get pods --selector=${LABEL} --output=jsonpath={.items..metadata.name}); do
    26    BUGTOOL_CMD="cilium-bugtool --archive=false"
    27    echo "=============== ${CILIUM} ${BUGTOOL_CMD} ==============="
    28    ARCHIVE=`kubectl exec -n ${NAMESPACE} ${CILIUM} -- ${BUGTOOL_CMD} | grep DIRECTORY | awk '{ print $3}'`
    29    kubectl cp ${NAMESPACE}/${CILIUM}:${ARCHIVE} ${OUTPUT_DIR}/${CILIUM}
    30  done
    31  
    32  tar -cvzf ${OUTPUT_ARCHIVE} ${OUTPUT_DIR} > /dev/null
    33  
    34  echo ARCHIVE at ${OUTPUT_ARCHIVE}