Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Register app dns vhost for secondary haproxy gears
Browse files Browse the repository at this point in the history
Modify the vhost frontend plugin to create a 2nd base vhost conf file
for the app dns so secondary haproxy gears can handle requests for
$OPENSHIFT_APP_DNS

Bug 1161072
  • Loading branch information
Andy Goldstein committed Nov 12, 2014
1 parent c7fbda3 commit f778d2b
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 17 deletions.
8 changes: 7 additions & 1 deletion node-util/conf/watchman/plugins.d/frontend_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ def apply(iteration)

@logger.info %Q(watchman frontend plugin cleaned up #{conf_file})
File.delete(conf_file)

reload_needed = true

# skip deleting the gear_dir if this is the _ha.conf file,
# as deletion will be handled by the regular .conf file.
next if conf_file.end_with?('_ha.conf')

gear_dir = conf_file.gsub('_0_', '_')
gear_dir = gear_dir.gsub('.conf', '')

FileUtils.rm_r(gear_dir)
reload_needed = true
end

if reload_needed
Expand Down
2 changes: 1 addition & 1 deletion node-util/sbin/oo-admin-gear
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ command :destroygear do |c|
end

if config.get('OPENSHIFT_FRONTEND_HTTP_PLUGINS').include?('openshift-origin-frontend-apache-vhost')
entries = Dir.glob("#{options.with_container_uuid}_*.conf")
entries = Dir.glob("#{options.with_container_uuid}_*.conf").reject {|e| e.end_with?("_ha.conf")}
if 1 == entries.length
fqdn = %x[/bin/awk -- '/ServerName/ {print $2; exit}' #{entries.first}].chomp
options.default fqdn: fqdn unless fqdn.empty?
Expand Down
1 change: 1 addition & 0 deletions node/test/node_functional/frontend_plugin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_no_delete

def test_delete
FileUtils.touch(File.join(@testdir, 'test_0_dir.conf'), mtime: (Time.now - 7200))
FileUtils.touch(File.join(@testdir, 'test_0_dir_ha.conf'), mtime: (Time.now - 7200))
conf_dir = File.join(@testdir, 'test_dir')
FileUtils.mkdir_p(conf_dir)
FileUtils.touch(File.join(conf_dir, 'test_file'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def conf_path
PathUtils.join(@basedir, "#{@container_uuid}_#{@namespace}_0_#{@container_name}.conf")
end

def ha_conf_path
PathUtils.join(@basedir, "#{@container_uuid}_#{@namespace}_0_#{@container_name}_ha.conf")
end

def element_path(path)
if path == "*"
tpath = "*"
Expand Down Expand Up @@ -120,6 +124,24 @@ def destroy
end
end

def write_base_config(file_name)
File.open(file_name, FILE_OPTS, 0644) do |f|
# setup binding environment
server_name = @fqdn
include_path = @app_path
app_uuid = @application_uuid
gear_uuid = @container_uuid
app_namespace = @namespace
ssl_certificate_file = @ssl_cert_path
ssl_certificate_chain_file = @ssl_chain_path
ssl_key_file = @ssl_key_path

buffer = ERB.new(File.read(@template_http)).result(binding) << "\n"
buffer << ERB.new(File.read(@template_https)).result(binding) << "\n"
f.write(buffer)
end
end

def connect(*elements)
with_lock_and_reload do

Expand All @@ -128,21 +150,14 @@ def connect(*elements)

# The base config won't exist until the first connection is created
unless File.size?(conf_path)
File.open(conf_path, FILE_OPTS, 0644) do |f|
# setup binding environment
server_name = @fqdn
include_path = @app_path
app_uuid = @application_uuid
gear_uuid = @container_uuid
app_namespace = @namespace
ssl_certificate_file = @ssl_cert_path
ssl_certificate_chain_file = @ssl_chain_path
ssl_key_file = @ssl_key_path

buffer = ERB.new(File.read(@template_http)).result(binding) << "\n"
buffer << ERB.new(File.read(@template_https)).result(binding) << "\n"
f.write(buffer)
end
write_base_config(conf_path)
end

# Secondary haproxy gear: if the @fqdn is the app dns, then it won't start with
# @container_name (as that should be the gear's uuid). If the ha conf file
# doesn't exist, create it
if !@fqdn.start_with?(@container_name) and !File.size?(ha_conf_path)
write_base_config(ha_conf_path)
end

# Process target_update option by loading the old values
Expand Down
21 changes: 21 additions & 0 deletions plugins/frontend/apache-vhost/test/functional/apache_vhost_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ def test_connections
end
end

def test_ha_conf
app_cfg = File.join(@basedir, "#{@container_uuid}_#{@namespace}_0_#{@container_name}.conf")
ha_app_cfg = File.join(@basedir, "#{@container_uuid}_#{@namespace}_0_#{@container_name}_ha.conf")

exercise_connections_api
assert File.size?(app_cfg), "App configuration must exist"
assert !File.size?(ha_app_cfg), "HA app configuration must not exist"

gear_fqdn = @fqdn
app_fqdn = "somegear-#{@namespace}.#{@domain}"
@plugin.fqdn = app_fqdn
exercise_connections_api
assert File.size?(app_cfg), "App configuration must exist"
app_cfg_fqdn = %x[/bin/awk -- '/ServerName/ {print $2; exit}' #{app_cfg}].chomp
assert_equal gear_fqdn, app_cfg_fqdn, "App configuration's ServerName must be gear's FQDN"

assert File.size?(ha_app_cfg), "HA app configuration must exist"
ha_app_cfg_fqdn = %x[/bin/awk -- '/ServerName/ {print $2; exit}' #{ha_app_cfg}].chomp
assert_equal app_fqdn, ha_app_cfg_fqdn, "HA app configuration's ServerName must be app's FQDN"
end

def test_aliases
exercise_aliases_api do |mode|
@aliases.each do |server_alias|
Expand Down

0 comments on commit f778d2b

Please sign in to comment.