Skip to content

Commit

Permalink
Interface substitution script
Browse files Browse the repository at this point in the history
Signed-off-by: Lazar Cvetković <[email protected]>
  • Loading branch information
cvetkovic committed Feb 20, 2024
1 parent a074619 commit c45e8a9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
Empty file modified configs/k8s_ha/check_apiserver.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion configs/k8s_ha/keepalived_backup.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ vrrp_script check_apiserver {

vrrp_instance VI_1 {
state BACKUP
interface enp4s0f1
interface $INTERFACE_NAME
virtual_router_id 51
priority 101
authentication {
Expand Down
2 changes: 1 addition & 1 deletion configs/k8s_ha/keepalived_master.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ vrrp_script check_apiserver {

vrrp_instance VI_1 {
state MASTER
interface enp4s0f1
interface $INTERFACE_NAME
virtual_router_id 51
priority 101
authentication {
Expand Down
10 changes: 10 additions & 0 deletions configs/k8s_ha/substitute_interface.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

readonly DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"

export INTERFACE_NAME=$(ifconfig | grep -B1 "10.0.1" | head -n1 | sed 's/:.*//')

cat $DIR/keepalived_master.conf | envsubst > $DIR/keepalived_master.conff
cat $DIR/keepalived_backup.conf | envsubst > $DIR/keepalived_backup.conff

echo "Successfully created HA load balancer configuration!"
9 changes: 7 additions & 2 deletions scripts/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,18 @@ func SetupSystem(haMode string) error {
return err
}

_, err = utils.ExecVHiveBashScript("configs/k8s_ha/substitute_interface.sh")
if !utils.CheckErrorWithTagAndMsg(err, "Failed to create HA load balancer !\n") {
return err
}

if haMode == "MASTER" {
err = utils.CopyToDir(path.Join(k8s_ha_path, "keepalived_master.conf"), "/etc/keepalived/keepalived.conf", true)
err = utils.CopyToDir(path.Join(k8s_ha_path, "keepalived_master.conff"), "/etc/keepalived/keepalived.conf", true)
if !utils.CheckErrorWithMsg(err, "Failed to copy files to /etc/keepalived/keepalived.conf!\n") {
return err
}
} else {
err = utils.CopyToDir(path.Join(k8s_ha_path, "keepalived_backup.conf"), "/etc/keepalived/keepalived.conf", true)
err = utils.CopyToDir(path.Join(k8s_ha_path, "keepalived_backup.conff"), "/etc/keepalived/keepalived.conf", true)
if !utils.CheckErrorWithMsg(err, "Failed to copy files to /etc/keepalived/keepalived.conf!\n") {
return err
}
Expand Down

0 comments on commit c45e8a9

Please sign in to comment.