Skip to content

Commit 47244df

Browse files
committed
ipfailover - control preempt strategy
This allows the admin to control the VRRP preempt strategy. The default strategy, preempt_delay <sec>, switches to the higher priority master after a <sec> (default 300) delay. The second strategy, nopreempt, suppresses switchin when a higher priority host becomes available. The 'oc adm ipfailover --preempt-strategy' option can set the desired strategy. --preempt-strategy sets the OPENSHIFT_HA_PREEMPTION environment variable. bug 1465987 https://bugzilla.redhat.com/show_bug.cgi?id=1465987 openshift docs PR 4674 openshift/openshift-docs#4674
1 parent cecd46a commit 47244df

File tree

5 files changed

+21
-11
lines changed

5 files changed

+21
-11
lines changed

images/ipfailover/keepalived/conf/settings.sh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ HA_NOTIFY_SCRIPT="${OPENSHIFT_HA_NOTIFY_SCRIPT:-""}"
6868
# Default is 2
6969
HA_CHECK_INTERVAL="${OPENSHIFT_HA_CHECK_INTERVAL:-"2"}"
7070

71+
# VRRP will preempt a lower priority machine when a higher priority one
72+
# comes back online. You can change the preemption strategy to either:
73+
# "nopreempt" - which allows the lower priority machine to maintain its
74+
# 'MASTER' status.
75+
# OR
76+
# "preempt_delay 300" - waits 5 mins (in seconds) after startup to
77+
# preempt lower priority MASTERs.
78+
PREEMPTION="${OPENSHIFT_HA_PREEMPTION:-"preempt_delay 300"}"
79+
7180

7281
# ========================================================================
7382
# Default settings - not currently exposed or overridden on OpenShift.
@@ -94,17 +103,6 @@ SMTP_SERVER="${OPENSHIFT_HA_SMTP_SERVER:-"127.0.0.1"}"
94103
# SMTP connect timeout (in seconds).
95104
SMTP_CONNECT_TIMEOUT=30
96105

97-
98-
# VRRP will preempt a lower priority machine when a higher priority one
99-
# comes back online. You can change the preemption strategy to either:
100-
# "nopreempt" - which allows the lower priority machine to maintain its
101-
# 'MASTER' status.
102-
# OR
103-
# "preempt_delay 300" - waits 5 mins (in seconds) after startup to
104-
# preempt lower priority MASTERs.
105-
PREEMPTION="preempt_delay 300"
106-
107-
108106
# By default, the IP for binding vrrpd is the primary IP on the above
109107
# specified interface. If you want to hide the location of vrrpd, you can
110108
# specify a src_addr for multicast/unicast vrrp packets.

pkg/cmd/experimental/ipfailover/ipfailover.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ func NewCmdIPFailoverConfig(f *clientcmd.Factory, parentName, name string, out,
102102
cmd.Flags().StringVar(&options.NotifyScript, "notify-script", "", "Run this script when state changes.")
103103
cmd.Flags().StringVar(&options.CheckScript, "check-script", "", "Run this script at the check-interval to verify service is OK")
104104
cmd.Flags().IntVar(&options.CheckInterval, "check-interval", ipfailover.DefaultCheckInterval, "Run the check-script at this interval (seconds)")
105+
cmd.Flags().StringVar(&options.Preemption, "preemption-strategy", "preempt_delay 300", "Normlly VRRP will preempt a lower priority machine when a higher priority one comes online. 'nopreempt' allows the lower priority machine to maintain its MASTER status. The default 'preempt_delay 300' causes MASTER to switch after 5 min.")
105106
cmd.Flags().StringVar(&options.IptablesChain, "iptables-chain", ipfailover.DefaultIptablesChain, "Add a rule to this iptables chain to accept 224.0.0.28 multicast packets if no rule exists. When iptables-chain is empty do not change iptables.")
106107
cmd.Flags().StringVarP(&options.NetworkInterface, "interface", "i", "", "Network interface bound by VRRP to use for the set of virtual IP ranges/addresses specified.")
107108

pkg/ipfailover/keepalived/generator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func generateEnvEntries(name string, options *ipfailover.IPFailoverConfigCmdOpti
3636
"OPENSHIFT_HA_IPTABLES_CHAIN": options.IptablesChain,
3737
"OPENSHIFT_HA_NOTIFY_SCRIPT": options.NotifyScript,
3838
"OPENSHIFT_HA_CHECK_SCRIPT": options.CheckScript,
39+
"OPENSHIFT_HA_PREEMPTION": options.Preemption,
3940
"OPENSHIFT_HA_CHECK_INTERVAL": interval,
4041
// "OPENSHIFT_HA_UNICAST_PEERS": "127.0.0.1",
4142
})

pkg/ipfailover/types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ const (
2626
// between calls to the CheckScript
2727
DefaultCheckInterval = 2
2828

29+
// DefaultPreemption strategy determines what to do when a lower
30+
// priority machine has MASTER and a higher priority machine becomes
31+
// available. The choices are "nopreempt" which leaves the lower priority
32+
// machine as MASTER and "preempt_delay 300" (the default) which allows the
33+
// supplied number of seconds to settle and then switches to the higher
34+
// priority machine.
35+
DefaultPreemption = "preempt_delay 300"
36+
2937
// DefaultIptablesChain is the default iptables chain on which to add
3038
// a rule that accesses 224.0.0.18 (if none exists).
3139
DefaultIptablesChain = "INPUT"
@@ -51,6 +59,7 @@ type IPFailoverConfigCmdOptions struct {
5159
NotifyScript string
5260
CheckScript string
5361
CheckInterval int
62+
Preemption string
5463
NetworkInterface string
5564
WatchPort int
5665
VRRPIDOffset int

test/cmd/router.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --ipta
8484
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --check-interval=1177 --dry-run -o yaml' 'value: "1177"'
8585
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --check-script="ChkScript.sh" --dry-run -o yaml' 'value: ChkScript.sh'
8686
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --notify-script="NotScript.sh" --dry-run -o yaml' 'value: NotScript.sh'
87+
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --preemption-strategy="nopreempt" --dry-run -o yaml' 'value: nopreempt'
8788
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --dry-run -o yaml --vrrp-id-offset=56' 'hostPort: 63056'
8889
os::cmd::expect_failure_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --dry-run -o yaml --vrrp-id-offset=255' 'error: The vrrp-id-offset must be in the range 0..254'
8990
os::cmd::expect_success 'oadm policy remove-scc-from-user privileged -z ipfailover'

0 commit comments

Comments
 (0)