File tree 1 file changed +49
-0
lines changed
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # function to print usage message
4
+ function usage {
5
+ echo " Usage: $0 [namespace]"
6
+ echo " namespace (optional): the Kubernetes namespace where the pods are running"
7
+ echo " This script will ping google.com from all pods containing 'ue' in their names."
8
+ }
9
+
10
+ # Function to prompt the user to select a namespace from a list
11
+ select_namespace () {
12
+ echo " Select a namespace:"
13
+ select NAMESPACE in $( kubectl get namespaces -o jsonpath=' {range .items[*]}{.metadata.name}{"\n"}{end}' )
14
+ do
15
+ if [ -n " $NAMESPACE " ]
16
+ then
17
+ break
18
+ fi
19
+ done
20
+ }
21
+
22
+ # Display help message if no namespace is provided
23
+ if [ " $# " -eq 0 ]
24
+ then
25
+ select_namespace
26
+ else
27
+ NAMESPACE=$1
28
+ fi
29
+
30
+ PODS=$( kubectl get pods -n $NAMESPACE | grep " ueransim-ue" | awk ' {print $1}' )
31
+
32
+ if [ -z " $PODS " ]
33
+ then
34
+ echo " No pods found containing 'ueransim-ue' in namespace: $NAMESPACE "
35
+ exit 1
36
+ fi
37
+
38
+ echo " Initiating random activity from UE pods..."
39
+
40
+ # Loop through all matching pods and execute ping command, logging output
41
+ for POD in $PODS
42
+ do
43
+ CONTAINER=$( kubectl get pod $POD -n $NAMESPACE -o jsonpath=' {.spec.containers[0].name}' )
44
+ echo " Pinging from pod: $POD , container: $CONTAINER "
45
+ # Creating a unique log file for each pod to avoid conflicts
46
+ LOGFILE=" ping-$( date +%s) -$POD .log"
47
+ kubectl exec $POD -n $NAMESPACE -c $CONTAINER -- sh -c " python3 random_activity.py > /tmp/$LOGFILE 2>&1 &"
48
+ echo " Random activity initiated in pod: $POD , container: $CONTAINER . Logs at /tmp/$LOGFILE "
49
+ done
You can’t perform that action at this time.
0 commit comments