Skip to content

Commit b9b62b8

Browse files
committed
Interface substitution script
Signed-off-by: Lazar Cvetković <[email protected]>
1 parent b00bdc7 commit b9b62b8

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

configs/k8s_ha/check_apiserver.sh

100644100755
File mode changed.

configs/k8s_ha/keepalived_backup.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ vrrp_script check_apiserver {
1313

1414
vrrp_instance VI_1 {
1515
state BACKUP
16-
interface enp4s0f1
16+
interface $INTERFACE_NAME
1717
virtual_router_id 51
1818
priority 101
1919
authentication {

configs/k8s_ha/keepalived_master.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ vrrp_script check_apiserver {
1313

1414
vrrp_instance VI_1 {
1515
state MASTER
16-
interface enp4s0f1
16+
interface $INTERFACE_NAME
1717
virtual_router_id 51
1818
priority 101
1919
authentication {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
readonly DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
4+
5+
export INTERFACE_NAME=$(ifconfig | grep -B1 "10.0.1" | head -n1 | sed 's/:.*//')
6+
7+
cat $DIR/keepalived_master.conf | envsubst > $DIR/keepalived_master.conff
8+
cat $DIR/keepalived_backup.conf | envsubst > $DIR/keepalived_backup.conff
9+
10+
echo "Successfully created HA load balancer configuration!"

scripts/setup/setup.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,18 @@ func SetupSystem(haMode string) error {
306306
return err
307307
}
308308

309+
_, err = utils.ExecVHiveBashScript("configs/k8s_ha/substitute_interface.sh")
310+
if !utils.CheckErrorWithTagAndMsg(err, "Failed to create HA load balancer !\n") {
311+
return err
312+
}
313+
309314
if haMode == "MASTER" {
310-
err = utils.CopyToDir(path.Join(k8s_ha_path, "keepalived_master.conf"), "/etc/keepalived/keepalived.conf", true)
315+
err = utils.CopyToDir(path.Join(k8s_ha_path, "keepalived_master.conff"), "/etc/keepalived/keepalived.conf", true)
311316
if !utils.CheckErrorWithMsg(err, "Failed to copy files to /etc/keepalived/keepalived.conf!\n") {
312317
return err
313318
}
314319
} else {
315-
err = utils.CopyToDir(path.Join(k8s_ha_path, "keepalived_backup.conf"), "/etc/keepalived/keepalived.conf", true)
320+
err = utils.CopyToDir(path.Join(k8s_ha_path, "keepalived_backup.conff"), "/etc/keepalived/keepalived.conf", true)
316321
if !utils.CheckErrorWithMsg(err, "Failed to copy files to /etc/keepalived/keepalived.conf!\n") {
317322
return err
318323
}

0 commit comments

Comments
 (0)