Created
January 13, 2021 11:44
-
-
Save mangelajo/62e45008f3594b4b44686d14af2124f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
KUBEMASTERS=$(kubectl get pods -A | grep ovnkube-master | awk '{ print $2 }') | |
function detect_ovn_pods { | |
if [[ "$NBDB_POD" != "" && "$SBDB_POD" != "" ]]; then | |
return | |
fi | |
echo "Detecting ovnkube-master for sbdb and nbdb" | |
for master in $KUBEMASTERS; do | |
if [[ "$NBDB_POD" == "" ]]; then | |
kubectl exec -ti -n openshift-ovn-kubernetes $master -c northd -- ovn-nbctl --timeout=2 show >/dev/null 2>&1 && NBDB_POD=$master | |
fi | |
if [[ "$SBDB_POD" == "" ]]; then | |
kubectl exec -ti -n openshift-ovn-kubernetes $master -c northd -- ovn-sbctl --timeout=2 show >/dev/null 2>&1 && SBDB_POD=$master | |
fi | |
if [[ "$NBDB_POD" != "" && "$SBDB_POD" != "" ]]; then | |
break | |
fi | |
done | |
cat >${KUBECONFIG}.ovn-pods <<-EOF | |
SBDB_POD=$SBDB_POD | |
NBDB_POD=$NBDB_POD | |
EOF | |
} | |
[[ -f ${KUBECONFIG}.ovn-pods ]] && source ${KUBECONFIG}.ovn-pods | |
detect_ovn_pods | |
function ovn_nbtest { | |
kubectl exec -n openshift-ovn-kubernetes -c northd $NBDB_POD -- true | |
} | |
function ovn_sbtest { | |
kubectl exec -n openshift-ovn-kubernetes -c northd $SBDB_POD -- true | |
} | |
# verify if the pods changed (new deployment?) | |
ovn_nbtest || NBDB_POD= | |
ovn_sbtest || SBDB_POD= | |
echo sbdb: $SBDB_POD nbdb: $NBDB_POD | |
if [[ "$NBDB_POD" == "" || "$SBDB_POD" == "" ]]; then | |
detect_ovn_pods | |
fi | |
function ovn_nbctl { | |
kubectl exec -n openshift-ovn-kubernetes -c northd $NBDB_POD -- ovn-nbctl $* | |
} | |
function ovn_sbctl { | |
kubectl exec -n openshift-ovn-kubernetes -c northd $SBDB_POD -- ovn-sbctl $* | |
} | |
function ovn_nbsh { | |
kubectl exec -n openshift-ovn-kubernetes -c northd $NBDB_POD -ti -- bash | |
} | |
function ovn_sbsh { | |
kubectl exec -n openshift-ovn-kubernetes -c northd $SBDB_POD -ti -- bash | |
} | |
ovn_nbctl lr-list | |
#ovn_sbctl show | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment