Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR - fixes related to cluster state #356

Merged
merged 8 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions .github/workflows/build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@ jobs:

- name: Install Latest Docker
run: |
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
# sudo apt-get update
# sudo apt-get install ca-certificates curl gnupg
# sudo install -m 0755 -d /etc/apt/keyrings
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# sudo chmod a+r /etc/apt/keyrings/docker.gpg

# echo \
# "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
# "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
# sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# sudo apt-get update
# sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
echo "Done"

- name: Build the loxilb Docker image
run: |
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Install Latest Docker
run: |
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

- name: Build the latest loxilb Docker image
if: github.event.inputs.tagName == ''
run: docker build . --tag ghcr.io/loxilb-io/loxilb:latest
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ RUN arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) && echo $arch && i
tar -xzf gobgp_3.5.0_linux_amd64.tar.gz && rm gobgp_3.5.0_linux_amd64.tar.gz && \
mv gobgp* /usr/sbin/ && rm LICENSE README.md && \
apt-get purge -y clang llvm libelf-dev libpcap-dev libbsd-dev build-essential \
elfutils dwarves git bison flex curl wget unzip && apt-get -y autoremove && \
elfutils dwarves git bison flex wget unzip && apt-get -y autoremove && \
apt-get install -y libllvm10 && \
# cleanup unnecessary packages
if [ "$arch" = "arm64" ] ; then apt purge -y gcc-multilib-arm-linux-gnueabihf; else apt update && apt purge -y gcc-multilib;fi && \
Expand All @@ -68,9 +68,9 @@ RUN arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) && echo $arch && i
echo "fi" >> /root/.bashrc

# Optional files, only apply when files exist
COPY ./loxilb.rep* /root/loxilb-io/loxilb/loxilb
COPY ./llb_ebpf_main.o.rep* /opt/loxilb/llb_ebpf_main.o
COPY ./llb_xdp_main.o.rep* /opt/loxilb/llb_xdp_main.o
# COPY ./loxilb.rep* /root/loxilb-io/loxilb/loxilb
# COPY ./llb_ebpf_main.o.rep* /opt/loxilb/llb_ebpf_main.o
# COPY ./llb_xdp_main.o.rep* /opt/loxilb/llb_xdp_main.o

ENTRYPOINT ["/root/loxilb-io/loxilb/loxilb"]

Expand Down
41 changes: 18 additions & 23 deletions loxinet/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type ClusterNode struct {
type CIStateH struct {
SpawnKa bool
kaMode bool
ClusterMap map[string]ClusterInstance
ClusterMap map[string]*ClusterInstance
StateMap map[string]int
NodeMap map[string]*ClusterNode
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func kaSpawn() {
}
}

func (ci *CIStateH) CISync(doNotify bool) {
func (ci *CIStateH) CISync() {
var sm cmn.HASMod
var ciState int
var ok bool
Expand All @@ -127,7 +127,7 @@ func (ci *CIStateH) CISync(doNotify bool) {
var vip string
// Format style -
// INSTANCE default is in BACKUP state
_, err = fmt.Sscanf(fsc.Text(), "INSTANCE %s is in %s state, vip %s", &inst, &state, &vip)
_, err = fmt.Sscanf(fsc.Text(), "INSTANCE %s is in %s state vip %s", &inst, &state, &vip)
if err != nil {
continue
}
Expand All @@ -146,19 +146,12 @@ func (ci *CIStateH) CISync(doNotify bool) {
}
}

if notify && doNotify {
tk.LogIt(tk.LogInfo, "ci-change instance %s - state %s vip %s\n", inst, state, vip)
if notify {
sm.Instance = inst
sm.State = state
sm.Vip = net.ParseIP(vip)
tk.LogIt(tk.LogInfo, "ci-change instance %s - state %s vip %v\n", inst, state, sm.Vip)
ci.CIStateUpdate(sm)
} else {
if ciState != cmn.CIStateMaster && ciState != cmn.CIStateBackup {
continue
}

nci := ClusterInstance{State: ciState, StateStr: state}
ci.ClusterMap[inst] = nci
}
}

Expand All @@ -169,7 +162,7 @@ func (ci *CIStateH) CISync(doNotify bool) {
// CITicker - Periodic ticker for Cluster module
func (ci *CIStateH) CITicker() {
mh.mtx.Lock()
ci.CISync(true)
ci.CISync()
mh.mtx.Unlock()
}

Expand All @@ -191,14 +184,13 @@ func CIInit(spawnKa bool, kaMode bool) *CIStateH {
nCIh.StateMap["NOT_DEFINED"] = cmn.CIStateNotDefined
nCIh.SpawnKa = spawnKa
nCIh.kaMode = kaMode
nCIh.ClusterMap = make(map[string]ClusterInstance)
// nCIh.CISync(false)
nCIh.ClusterMap = make(map[string]*ClusterInstance)

if _, ok := nCIh.ClusterMap[cmn.CIDefault]; !ok {
var ci ClusterInstance
ci.State = cmn.CIStateNotDefined
ci.StateStr = "NOT_DEFINED"
ci.Vip = net.IPv4zero
ci := &ClusterInstance{State: cmn.CIStateNotDefined,
StateStr: "NOT_DEFINED",
Vip: net.IPv4zero,
}
nCIh.ClusterMap[cmn.CIDefault] = ci
if mh.bgp != nil {
mh.bgp.UpdateCIState(cmn.CIDefault, ci.State, ci.Vip)
Expand Down Expand Up @@ -236,7 +228,7 @@ func (h *CIStateH) CIStateGet() ([]cmn.HASMod, error) {
// CIVipGet - routine to get HA state
func (h *CIStateH) CIVipGet(inst string) (net.IP, error) {
if ci, ok := h.ClusterMap[inst]; ok {
if !ci.Vip.IsUnspecified() {
if ci.Vip != nil && !ci.Vip.IsUnspecified() {
return ci.Vip, nil
}
}
Expand All @@ -252,13 +244,17 @@ func (h *CIStateH) IsCIKAMode() bool {
func (h *CIStateH) CIStateUpdate(cm cmn.HASMod) (int, error) {

if _, ok := h.ClusterMap[cm.Instance]; !ok {
h.ClusterMap[cm.Instance] = ClusterInstance{State: cmn.CIStateNotDefined,
h.ClusterMap[cm.Instance] = &ClusterInstance{State: cmn.CIStateNotDefined,
StateStr: "NOT_DEFINED",
Vip: net.IPv4zero}
tk.LogIt(tk.LogDebug, "[CLUSTER] New Instance %s created\n", cm.Instance)
}

ci := h.ClusterMap[cm.Instance]
ci, found := h.ClusterMap[cm.Instance]
if !found {
tk.LogIt(tk.LogError, "[CLUSTER] New Instance %s find error\n", cm.Instance)
return -1, errors.New("Cluster instance not found")
}

if ci.StateStr == cm.State {
return ci.State, nil
Expand All @@ -270,7 +266,6 @@ func (h *CIStateH) CIStateUpdate(cm cmn.HASMod) (int, error) {
ci.StateStr = cm.State
ci.State = h.StateMap[cm.State]
ci.Vip = cm.Vip
h.ClusterMap[cm.Instance] = ci
if h.SpawnKa && (cm.State == "FAULT" || cm.State == "STOP") {
RunCommand("pkill keepalived", false)
}
Expand Down