-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDN-1334: Pod to pod connectivity for OVN
Signed-off-by: Surya Seetharaman <suryaseetharaman.9@gmail.com>
- Loading branch information
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/bin/bash | ||
|
||
create_pod () { | ||
|
||
POD_NAME=${1} | ||
DEBUG_NETWORK_NAMESPACE=${2} | ||
NODE_SELECTOR_LABEL=${3} | ||
|
||
if [ -z $NODE_SELECTOR_LABEL ]; then | ||
cat <<EOF | sed "s/{{POD_NAME}}/$POD_NAME/g" | sed "s/{{DEBUG_NETWORK_NAMESPACE}}/$DEBUG_NETWORK_NAMESPACE/g" | kubectl apply -f - | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: {{POD_NAME}} | ||
namespace: {{DEBUG_NETWORK_NAMESPACE}} | ||
labels: | ||
pod-name: {{POD_NAME}} | ||
spec: | ||
containers: | ||
- name: {{POD_NAME}} | ||
image: docker.io/centos/tools:latest | ||
command: | ||
- /sbin/init | ||
EOF | ||
else | ||
cat <<EOF | sed "s/{{POD_NAME}}/$POD_NAME/g" | sed "s/{{DEBUG_NETWORK_NAMESPACE}}/$DEBUG_NETWORK_NAMESPACE/g" | sed "s/{{NODE_SELECTOR_LABEL}}/$NODE_SELECTOR_LABEL/g" | kubectl apply -f - | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: {{POD_NAME}} | ||
namespace: {{DEBUG_NETWORK_NAMESPACE}} | ||
labels: | ||
pod-name: {{POD_NAME}} | ||
spec: | ||
containers: | ||
- name: {{POD_NAME}} | ||
image: docker.io/centos/tools:latest | ||
command: | ||
- /sbin/init | ||
nodeSelector: | ||
use: {{NODE_SELECTOR_LABEL}} | ||
EOF | ||
fi | ||
} | ||
|
||
do_pod_to_pod_connectivity_check () { | ||
|
||
src_node=${1} | ||
dst_node=${2} | ||
|
||
# create a debug-network namespace | ||
DEBUG_NETWORK_NAMESPACE=${DEBUG_NETWORK_NAMESPACE:-"openshift-debug-network"} | ||
oc create namespace $DEBUG_NETWORK_NAMESPACE | ||
|
||
# create two pods | ||
if [ -z $src_node ] && [ -z $dst_node]; then | ||
create_pod "client-debug" $DEBUG_NETWORK_NAMESPACE | ||
create_pod "server-debug" $DEBUG_NETWORK_NAMESPACE | ||
else | ||
oc label nodes $src_node "use=client-pod" | ||
oc label nodes $dst_node "use=server-pod" | ||
create_pod "client-debug" $DEBUG_NETWORK_NAMESPACE "client-pod" | ||
create_pod "server-debug" $DEBUG_NETWORK_NAMESPACE "server-pod" | ||
fi | ||
|
||
# wait till pods are running | ||
while [[ $(oc -n $DEBUG_NETWORK_NAMESPACE get pods client-debug -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "waiting for pod client-debug" && sleep 1; done | ||
while [[ $(oc -n $DEBUG_NETWORK_NAMESPACE get pods server-debug -o 'jsonpath={..status.conditions[?(@.type=="Ready")].status}') != "True" ]]; do echo "waiting for pod server-debug" && sleep 1; done | ||
|
||
client_debug_pod_ip=$(oc get pods -n openshift-debug-network client-debug -o template --template '{{.status.podIP}}') | ||
server_debug_pod_ip=$(oc get pods -n openshift-debug-network server-debug -o template --template '{{.status.podIP}}') | ||
|
||
# rsh into the client pod and ping the server | ||
if [ oc rsh -n $DEBUG_NETWORK_NAMESPACE client-debug ping $server_debug_pod_ip -c 1 -W 2 &> /dev/null ]; then | ||
echo "ping $server_debug_pod_ip -> success" | ||
else | ||
echo "ping $server_debug_pod_ip -> failed" | ||
echo "Running traceroute from client pod to server pod:" | ||
oc rsh -n $DEBUG_NETWORK_NAMESPACE client-debug yum install traceroute -y | ||
oc rsh -n $DEBUG_NETWORK_NAMESPACE client-debug traceroute $server_debug_pod_ip -m 10 | ||
# incorportate the logic to use ovnkube-trace to output the ovn/ovs trace | ||
echo "Something is wrong, running the ovnkube-trace and detrace to help figure out the packet route..." | ||
# [TODO]: Once ovnkube-trace is packed is oc, we can start using it directly and cleanup the nonsense from the below lines. | ||
git clone --single-branch --branch ovnkube-trace https://github.com/mccv1r0/ovn-kubernetes.git && \ | ||
pushd ovn-kubernetes/go-controller && make && \ | ||
_output/go/bin/ovnkube-trace --kubeconfig $KUBECONFIG --tcp --dst-port 80 --src client-debug --dst server-debug -dst-namespace $DEBUG_NETWORK_NAMESPACE -src-namespace $DEBUG_NETWORK_NAMESPACE --loglevel=5 | ||
popd && rm -rf ovn-kubernetes | ||
fi | ||
|
||
# delete debug-network namespace | ||
oc delete namespace $DEBUG_NETWORK_NAMESPACE | ||
} | ||
|
||
main () { | ||
if [ -z "$KUBECONFIG" -o ! -f "$KUBECONFIG" ]; then | ||
die "KUBECONFIG is unset or incorrect" | ||
else | ||
echo "Enter the name of the src node to run the client-debug pod: (leave empty if you do not want to pick a node)" | ||
read src_node_name | ||
echo "Enter the name of the dst node to run the server-debug pod: (leave empty if you do not want to pick a node)" | ||
read dst_node_name | ||
do_pod_to_pod_connectivity_check $src_node_name $dst_node_name | ||
fi | ||
} | ||
|
||
main |