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

VR: Add "ready" OpenRC function to Keepalived #114

Merged
merged 1 commit into from
Jun 7, 2024
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
13 changes: 13 additions & 0 deletions appliances/VRouter/Failover/execute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ def up

load_env

# Give keepalived 30 seconds to setup VIPs..
6.times do
bash 'rc-service keepalived ready', terminate: false
break
rescue RuntimeError
sleep 5
end.then do |result|
unless result.nil?
msg :error, 'Keepalived not ready!'
return
end
end

SERVICES.each do |service, settings|
enabled = env settings[:_ENABLED], settings[:fallback]

Expand Down
40 changes: 39 additions & 1 deletion appliances/VRouter/Keepalived/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,29 @@ def parse_env(default_vrid = ONEAPP_VNF_KEEPALIVED_VRID)
end
end

def install
def install(initdir: '/etc/init.d')
msg :info, 'Keepalived::install'

puts bash 'apk --no-cache add keepalived'

script = File.open("#{initdir}/keepalived").each_with_object([]) do |line, acc|
if line =~ /^extra_started_commands="(.*)"$/
acc << %{extra_started_commands="#{$1} ready"\n}
else
acc << line
end
end.join

file "#{initdir}/keepalived", <<~SCRIPT, mode: 'u=rwx,go=rx', overwrite: true
#{script}

ready() {
ebegin "Checking readiness"
source /run/one-context/one_env
/usr/bin/ruby -r #{__FILE__} -e Service::Keepalived.ready
eend $?
}
SCRIPT
end

def configure(basedir: '/etc/keepalived')
Expand Down Expand Up @@ -173,5 +192,24 @@ def toggle(operations)
def bootstrap
msg :info, 'Keepalived::bootstrap'
end

def ready
detect_vips.each do |nic, vips|
vips = vips.values.map do |vip|
vip.split(%[/])[0] # remove the CIDR "prefixlen" if present
end

addrs = ip_addr_show(nic)['addr_info']&.each_with_object([]) do |item, acc|
acc << item['local'] unless item['local'].nil?
end

if (vips & addrs) != vips
msg :debug, { nic => { vips: vips, addrs: addrs, ready: false } }
exit 1
end
end

exit 0
end
end
end