Skip to content

Commit

Permalink
BFD Implementation - changes for cicd scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Feb 7, 2024
1 parent 97f4e41 commit 28bb937
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 22 deletions.
20 changes: 4 additions & 16 deletions cicd/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ hns="sudo ip netns "
hexist="$vrn$hn"
lxdocker="ghcr.io/loxilb-io/loxilb:latest"
cluster_opts=""
ka_opts=""
var=$(lsb_release -r | cut -f2)
if [[ $var == *"22.04"* ]];then
lxdocker="ghcr.io/loxilb-io/loxilb:latestu22"
Expand Down Expand Up @@ -104,24 +105,9 @@ spawn_docker_host() {
fi
if [[ ! -z ${ka+x} ]]; then
sudo mkdir -p /etc/shared/$dname/
if [[ "$ka" == "in" ]];then
ka_opts="-k in"
if [[ ! -z "$kpath" ]]; then
ka_conf="-v $kpath:/etc/keepalived/"
fi
fi
docker run -u root --cap-add SYS_ADMIN --restart unless-stopped --privileged -dt --entrypoint /bin/bash $bgp_conf -v /dev/log:/dev/log -v /etc/shared/$dname:/etc/shared $loxilb_config $ka_conf --name $dname $lxdocker
docker run -u root --cap-add SYS_ADMIN --restart unless-stopped --privileged -dt --entrypoint /bin/bash $bgp_conf -v /dev/log:/dev/log -v /etc/shared/$dname:/etc/shared $loxilb_config --name $dname $lxdocker
get_llb_peerIP $dname
docker exec -dt $dname /root/loxilb-io/loxilb/loxilb $bgp_opts $cluster_opts $ka_opts

if [[ "$ka" == "out" ]];then
ka_opts="-k out"
if [[ ! -z "$kpath" ]]; then
ka_conf="-v $kpath:/container/service/keepalived/assets/"
fi

docker run -u root --cap-add SYS_ADMIN --restart unless-stopped --privileged -dit --network=container:$dname $ka_conf -v /etc/shared/$dname:/etc/shared --name ka_$dname osixia/keepalived:2.0.20
fi
else
docker run -u root --cap-add SYS_ADMIN --restart unless-stopped --privileged -dt --entrypoint /bin/bash $bgp_conf -v /dev/log:/dev/log $loxilb_config --name $dname $lxdocker $bgp_opts
docker exec -dt $dname /root/loxilb-io/loxilb/loxilb $bgp_opts $cluster_opts
Expand Down Expand Up @@ -170,6 +156,7 @@ get_llb_peerIP() {
llb2IP="$A.$B.$C.$((D+1))"
fi
cluster_opts=" --cluster=$llb2IP --self=0"
ka_opts=" --ka=$llb2IP"
elif [[ "$1" == "llb2" ]]; then
llb2IP=$(docker inspect --format='{{.NetworkSettings.IPAddress}}' llb2)
if [[ "lb$llb2IP" == "lb" ]];then
Expand All @@ -179,6 +166,7 @@ get_llb_peerIP() {
llb1IP="$A.$B.$C.$((D-1))"
fi
cluster_opts=" --cluster=$llb1IP --self=1"
ka_opts=" --ka=$llb1IP"
fi
}

Expand Down
9 changes: 4 additions & 5 deletions cicd/k3s-sctpmh/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ echo "#########################################"
echo "Spawning all hosts"
echo "#########################################"

spawn_docker_host --dock-type loxilb --dock-name llb1 --with-bgp yes --bgp-config $(pwd)/llb1_gobgp_config --with-ka in --ka-config $(pwd)/keepalived_config1
spawn_docker_host --dock-type loxilb --dock-name llb2 --with-bgp yes --bgp-config $(pwd)/llb2_gobgp_config --with-ka in --ka-config $(pwd)/keepalived_config2
spawn_docker_host --dock-type loxilb --dock-name llb1 --with-bgp yes --bgp-config $(pwd)/llb1_gobgp_config --with-ka in
spawn_docker_host --dock-type loxilb --dock-name llb2 --with-bgp yes --bgp-config $(pwd)/llb2_gobgp_config --with-ka in
spawn_docker_host --dock-type host --dock-name ep1
spawn_docker_host --dock-type host --dock-name ep2
spawn_docker_host --dock-type host --dock-name ep3
Expand Down Expand Up @@ -99,7 +99,8 @@ $hexec r1 ip route add 20.20.20.1/32 via 11.11.11.11
#add_route llb2 1.1.1.0/24 11.11.11.254

# Route back to user
sudo ip route add 11.11.11.0/24 via 12.12.12.1
sudo ip route add 11.11.11.0/24 via 14.14.14.1
sudo ip route add 123.123.123.0/24 via 14.14.14.1

# Change default route in llb1
$hexec llb1 ip route del default
Expand Down Expand Up @@ -195,11 +196,9 @@ $dexec llb1 loxicmd get lb -o wide
echo "llb1: loxicmd get ep -o wide"
echo "****************************"
$dexec llb1 loxicmd get ep -o wide
$dexec llb1 cat /etc/shared/keepalive.state
echo "llb2: loxicmd get lb -o wide"
echo "****************************"
$dexec llb2 loxicmd get lb -o wide
echo "llb2: loxicmd get ep -o wide"
echo "****************************"
$dexec llb2 loxicmd get ep -o wide
$dexec llb2 cat /etc/shared/keepalive.state
3 changes: 3 additions & 0 deletions cicd/k3s-sctpmh/nginx-svc-lb1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: v1
kind: Service
metadata:
name: nginx-lb1
annotations:
loxilb.io/lbmode: "fullnat"
loxilb.io/staticIP : "11.11.11.11"
spec:
externalTrafficPolicy: Local
loadBalancerClass: loxilb.io/loxilb
Expand Down
3 changes: 3 additions & 0 deletions cicd/k3s-sctpmh/nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: v1
kind: Pod
metadata:
name: nginx
annotations:
loxilb.io/lbmode: "fullnat"
loxilb.io/staticIP : "11.11.11.11"
labels:
app.kubernetes.io/name: proxy
spec:
Expand Down
19 changes: 19 additions & 0 deletions cicd/k3s-sctpmh/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ sleep 10
# Wait for cluster to be ready
wait_cluster_ready_full

for((i=0; i<120; i++))
do
extLB=$(sudo kubectl $KUBECONFIG get svc | grep "nginx-lb1")
read -a strarr <<< "$extLB"
len=${#strarr[*]}
if [[ $((len)) -lt 6 ]]; then
echo "Can't find nginx-lb service"
sleep 1
continue
fi
if [[ ${strarr[3]} != *"none"* ]]; then
extIP="$(cut -d'-' -f2 <<<${strarr[3]})"
port=${strarr[4]}
break
fi
echo "No external LB allocated"
sleep 1
done

out=$($hexec user curl -s --connect-timeout 10 http://$extIP:55002)
if [[ ${out} == *"Welcome to nginx"* ]]; then
echo "cluster-k3s TCP service nginx-lb del+add (kube-loxilb) [OK]"
Expand Down
2 changes: 1 addition & 1 deletion loxinet/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (ci *CIStateH) startBFDProto() {
time.Sleep(KAInitTiVal * time.Second)

bs := bfd.StructNew(3784)
err := bs.BFDAddRemote(ci.RemoteIP.String(), 3784, bfd.BFDMinSysTXIntervalUs, 3, "Default", ci)
err := bs.BFDAddRemote(ci.RemoteIP.String(), 3784, bfd.BFDMinSysTXIntervalUs, 3, cmn.CIDefault, ci)
if err != nil {
tk.LogIt(tk.LogCritical, "KA - Cant add BFD remote\n")
}
Expand Down

0 comments on commit 28bb937

Please sign in to comment.