This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a separate HAProxy map file for mapping Marathon app IDs to backe…
…nds (#303) * Use a separate HAProxy map file to map app IDs to backends * Use os.path functions to generate map file paths * Implement /_haproxy_getappmap endpoint to get app ID -> backend map * Generalize getvhostmap.lua to fetch other map files * Rework validation to check new map files * Write map files before main config file * Edit temporary config file to include temporary map files so that new map files are validated * Small refactor - generalize some functions that work with temp files * Clean up and hopefully fix getmaps.lua * Hopefully fix map file reading * Hopefully actually fix map file reading * Run build-docs.sh
- Loading branch information
1 parent
dbb9f87
commit 75d9b08
Showing
7 changed files
with
309 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
-- A simple Lua script which serves up the HAProxy | ||
-- vhost to backend map file. | ||
function check_file_exists(name) | ||
local f = io.open(name, "r") | ||
if f ~= nil then io.close(f) return true else return false end | ||
end | ||
|
||
function read_file(filepath) | ||
-- Read all of the given file, returning an empty string if the file doesn't | ||
-- exist. | ||
local content = "" | ||
if check_file_exists(filepath) then | ||
local f = io.open(filepath, "rb") | ||
content = f:read("*all") | ||
f:close() | ||
end | ||
return content | ||
end | ||
|
||
function detect_config_dir() | ||
-- Read the process's (HAProxy's) cmdline proc and parse the path to the | ||
-- config file so that we can determine the config directory. | ||
local f = io.open("/proc/self/cmdline", "rb") | ||
local cmdline = f:read("*all") | ||
f:close() | ||
|
||
local found = false | ||
local sep = package.config:sub(1, 1) | ||
for opt in string.gmatch(cmdline, "%g+") do | ||
if opt == "-f" then | ||
found = true | ||
elseif found then | ||
return opt:match("(.*"..sep..")") | ||
end | ||
end | ||
end | ||
|
||
function load_map(filename) | ||
local config_dir = detect_config_dir() | ||
return read_file(config_dir..filename) | ||
end | ||
|
||
function send_map(applet, map) | ||
applet:set_status(200) | ||
applet:add_header("content-length", string.len(map)) | ||
applet:add_header("content-type", "text/plain") | ||
applet:start_response() | ||
applet:send(map) | ||
end | ||
|
||
core.register_service("getvhostmap", "http", function(applet) | ||
local haproxy_vhostmap = load_map("domain2backend.map") | ||
send_map(applet, haproxy_vhostmap) | ||
end) | ||
|
||
core.register_service("getappmap", "http", function(applet) | ||
local haproxy_appmap = load_map("app2backend.map") | ||
send_map(applet, haproxy_appmap) | ||
end) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.