Skip to content

Commit 819cd5b

Browse files
abhinavm117Abhinav Mishra
and
Abhinav Mishra
authored
Script to fetch test report added (#291)
* Chart to install g2p-sandbox, fineract and mojaloop with placeholders * Chart with conditional deployment * Corrected chart.yaml * Added Readme * updated fineract version * Added script to fetch test report * Review changes --------- Co-authored-by: Abhinav Mishra <[email protected]>
1 parent c18c5ca commit 819cd5b

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

scripts/fetch_test_report.sh

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
3+
# Function to display usage instructions
4+
usage() {
5+
echo "Usage: $0 [-n NAMESPACE] [-p POD_NAME] [-c CONTAINER_NAME] [-f FOLLOW] [-o OUTPUT_FILE]"
6+
echo " -n NAMESPACE : The namespace of the pod (default: default)"
7+
echo " -p POD_NAME : The name of the pod"
8+
echo " -c CONTAINER_NAME : The name of the container (optional)"
9+
echo " -f FOLLOW : Follow the log output (optional, default: false)"
10+
echo " -o OUTPUT_FILE : The file to write the logs to (optional)"
11+
exit 1
12+
}
13+
14+
# Default values
15+
NAMESPACE="default"
16+
FOLLOW=false
17+
OUTPUT_FILE=""
18+
19+
# Parse command line arguments
20+
while getopts ":n:p:c:fo:" opt; do
21+
case ${opt} in
22+
n )
23+
NAMESPACE=$OPTARG
24+
;;
25+
p )
26+
POD_NAME=$OPTARG
27+
;;
28+
c )
29+
CONTAINER_NAME=$OPTARG
30+
;;
31+
f )
32+
FOLLOW=true
33+
;;
34+
o )
35+
OUTPUT_FILE=$OPTARG
36+
;;
37+
\? )
38+
usage
39+
;;
40+
: )
41+
echo "Invalid option: $OPTARG requires an argument" 1>&2
42+
usage
43+
;;
44+
esac
45+
done
46+
47+
# Validate required arguments
48+
if [ -z "${POD_NAME}" ]; then
49+
echo "Error: Pod name is required"
50+
usage
51+
fi
52+
53+
# Construct the kubectl command
54+
KUBECTL_CMD="kubectl logs -n ${NAMESPACE} ${POD_NAME}"
55+
56+
# Append container name if provided
57+
if [ ! -z "${CONTAINER_NAME}" ]; then
58+
KUBECTL_CMD="${KUBECTL_CMD} -c ${CONTAINER_NAME}"
59+
fi
60+
61+
# Append follow flag if set
62+
if [ "${FOLLOW}" = true ]; then
63+
KUBECTL_CMD="${KUBECTL_CMD} -f"
64+
fi
65+
66+
# Execute the command and handle output
67+
if [ ! -z "${OUTPUT_FILE}" ]; then
68+
echo "Fetching logs for pod '${POD_NAME}' in namespace '${NAMESPACE}' and writing to '${OUTPUT_FILE}'..."
69+
$KUBECTL_CMD > "${OUTPUT_FILE}"
70+
else
71+
echo "Fetching logs for pod '${POD_NAME}' in namespace '${NAMESPACE}'..."
72+
$KUBECTL_CMD
73+
fi

0 commit comments

Comments
 (0)