Last active
November 14, 2019 05:09
-
-
Save stuart-warren/83645b697f20a08ce5dc0c833a06a146 to your computer and use it in GitHub Desktop.
weave-net scripts compatible with k8sh. from https://github.com/weaveworks/weave/issues/3659#issuecomment-514773808
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
#!/usr/bin/env bash | |
# takes a weave pod name and, after confirmation, removes the | |
# weave db and deletes the pod | |
WP=$1 | |
REPLY=$2 | |
if [[ ! $WP =~ weave-[a-z0-9]+ ]] | |
then | |
echo "Usage: $0 weave-podname" | |
echo "Will show details of the node hosting the weave pod and then" | |
echo "if confirmed, will remove the weave db and delete the weave pod" | |
exit 1 | |
fi | |
KUBECTL_CONTEXT=${KUBECTL_CONTEXT-"minikube"} | |
KUBECTL_NAMESPACE=${KUBECTL_NAMESPACE-"kube-system"} | |
alias kubectl="kubectl --context=${KUBECTL_CONTEXT} --namespace=${KUBECTL_NAMESPACE}" | |
NODE=$( kubectl get pod $WP -o wide --no-headers | awk '{ print $7 }' ) | |
echo -------------------------------------------- | |
echo "Weave pod $WP found on $NODE" | |
echo "Houses the following pods:" | |
kubectl describe node $NODE | sed -n -e '/^ ---------/,/Allocated/p' | sed -e '1d' -e '$d' | awk '{ print $1 "\t" $2 }' | |
echo -------------------------------------------- | |
if [[ -z $REPLY ]]; then | |
read -p "Enter 'YES' to bump this weave pod: " | |
fi | |
if [[ $REPLY != YES ]] | |
then | |
echo "No action taken" | |
exit | |
else | |
echo "Deleting db file..." | |
kubectl exec -ti $WP -c weave -- rm /weavedb/weave-netdata.db | |
kubectl delete pod $WP | |
fi |
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
#!/usr/bin/env bash | |
# | |
# This script will iterate over all weave pods and | |
# determine if they are all consistent or not | |
# | |
if [[ $* ]] | |
then | |
echo "usage: $0" | |
echo "This script will pull the 'ipam status' data from each node in the" | |
echo "current cluster and verify if they are all consistent. If they are not" | |
echo "consistent then the different groups of pods will be shown" | |
exit | |
fi | |
KUBECTL_CONTEXT=${KUBECTL_CONTEXT-"minikube"} | |
KUBECTL_NAMESPACE=${KUBECTL_NAMESPACE-"kube-system"} | |
alias kubectl="kubectl --context=${KUBECTL_CONTEXT} --namespace=${KUBECTL_NAMESPACE}" | |
# Get a list of all weave pods | |
echo "Gathering list of weave pods..." | |
WEAVEPODS=$( kubectl get pod | grep weave-net | awk '{ print $1 }' ) | |
WEAVECOUNT=$( echo "$WEAVEPODS" | wc -l ) | |
echo "Found $WEAVECOUNT weave pods." | |
# Checksums will hold the list of weave pods that sum to a particular checksum value | |
# Unreachable will hold the list of unreachable nodes for a given checksum value | |
declare -A CHECKSUMS | |
declare -A UNREACHABLE | |
# Compute the checksum and unreachables for each weave pod and put the name in the appropriate list | |
echo "Computing status checksum for weave pods..." | |
for wp in $WEAVEPODS | |
do | |
echo -n "." | |
# Peerdata contains the (sanitized) output from 'status ipam' such that it should be comparable between nodes | |
# Unreach contains the list of unreachables from the status output | |
# Peersum is the resulting checksum of the peerdata from above | |
PEERDATA=$( kubectl exec $wp -c weave -- ./weave --local status ipam | awk '{ print $1 "," $2 }' | sort ) | |
UNREACH=$( kubectl exec $wp -c weave -- ./weave --local status ipam | grep unreachable | sort ) | |
PEERSUM="sum$( echo "$PEERDATA" | sum | awk '{ print $1 }' )" | |
if [[ ${CHECKSUMS[$PEERSUM]} ]] | |
then | |
CHECKSUMS[$PEERSUM]="${CHECKSUMS[$PEERSUM]} $wp" | |
else | |
#echo "Found new sum $PEERSUM..." | |
CHECKSUMS[$PEERSUM]=$wp | |
fi | |
if [[ $UNREACH ]] | |
then | |
UNREACHABLES[$PEERSUM]="$UNREACH" | |
fi | |
done | |
echo | |
# If there's more than one checksum for the cluster, then there is an inconsistency. | |
if [[ ${#CHECKSUMS[@]} -gt 1 ]] | |
then | |
echo "Found ${#CHECKSUMS[@]} different peer lists..." | |
for ps in ${!CHECKSUMS[@]} | |
do | |
echo | |
echo "Group $ps has $( echo ${CHECKSUMS[$ps]} | wc -w ) nodes:" | |
echo ${CHECKSUMS[$ps]} | |
if [[ ${UNREACHABLES[$ps]} ]] | |
then | |
echo "The following unreachable peers exist:" | |
echo ${UNREACHABLES[$ps]} | sed -e 's/\! */\n/g' | |
fi | |
done | |
else | |
echo "All weave pods are consistent." | |
if [[ ${UNREACHABLES[$PEERSUM]} ]] | |
then | |
echo "The following unreachable peers exist:" | |
echo ${UNREACHABLES[$PEERSUM]} | sed -e 's/! */\n/g' | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment