github.com/milvus-io/milvus-sdk-go/v2@v2.4.1/ci/scripts/export_log_k8s_for_operator.sh (about)

     1  #!/bin/bash
     2  
     3  # Exit immediately for non zero status
     4  set -e
     5  
     6  ns_name=$1
     7  instance_name=$2
     8  log_dir=${3:-"k8s_logs"}
     9  
    10  #show proxy pod log
    11  array=($(kubectl get pod -n ${ns_name} -l "app.kubernetes.io/component=proxy, app.kubernetes.io/instance=${instance_name}"| awk 'NR == 1 {next} {print $1}'))
    12  echo ${array[@]}
    13  
    14  for pod in ${array[*]}
    15  do
    16  echo "show log of proxy pod $pod "
    17  kubectl logs $pod -n ${ns_name} --tail=100 || echo "show log for pod $pod failed"
    18  done
    19  
    20  # export info of etcd
    21  array=($(kubectl get pod -n ${ns_name} -l "app.kubernetes.io/name=etcd, app.kubernetes.io/instance=${instance_name}-etcd"| awk 'NR == 1 {next} {print $1}'))
    22  echo ${array[@]}
    23  mkdir -p $log_dir/etcd_session
    24  for pod in ${array[*]}
    25  do
    26  echo "check session for etcd pod $pod "
    27  kubectl exec $pod -n ${ns_name} -- etcdctl get --prefix by-dev/meta/session > ./$log_dir/etcd_session/$pod.log || echo "export session for pod $pod failed"
    28  done
    29  echo "check session done"
    30  
    31  # export logs of all pods
    32  array_1=($(kubectl get pod -n ${ns_name} -l "app.kubernetes.io/instance=${instance_name}"| awk 'NR == 1 {next} {print $1}'))
    33  array_2=($(kubectl get pod -n ${ns_name} -l "app.kubernetes.io/instance=${instance_name}-etcd"| awk 'NR == 1 {next} {print $1}'))
    34  array_3=($(kubectl get pod -n ${ns_name} -l "release=${instance_name}-minio"| awk 'NR == 1 {next} {print $1}'))
    35  array_4=($(kubectl get pod -n ${ns_name} -l "release=${instance_name}-pulsar"| awk 'NR == 1 {next} {print $1}'))
    36  
    37  array=(${array_1[@]} ${array_2[@]} ${array_3[@]} ${array_4[@]})
    38  
    39  echo ${array[@]}
    40  if [ ! -d $log_dir/pod_log ] || [ ! -d $log_dir/pod_describe ];
    41  then
    42      mkdir -p $log_dir/pod_log
    43      mkdir -p $log_dir/pod_log_previous
    44      mkdir -p $log_dir/pod_describe
    45  fi
    46  echo "export logs start"
    47  for pod in ${array[*]}
    48  do
    49  echo "export logs for pod $pod "
    50  kubectl logs $pod -n ${ns_name} > ./$log_dir/pod_log/$pod.log 2>&1 || echo "export log for pod $pod failed"
    51  kubectl logs $pod --previous -n ${ns_name} > ./$log_dir/pod_log_previous/$pod.log 2>&1 || echo "pod $pod has no previous log"
    52  kubectl describe pod $pod -n ${ns_name} > ./$log_dir/pod_describe/$pod.log || echo "export describe for pod $pod failed"
    53  done
    54  echo "export logs done"