-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add port range support to haproxy template * fix haproxy systemd startup issue after a reboot - haproxy restart forced after all interfaces are created * error handling - show_exceptions false * added controllers default error handler
- Loading branch information
1 parent
856f8b3
commit b447231
Showing
10 changed files
with
74 additions
and
60 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
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 |
---|---|---|
@@ -1,30 +1,47 @@ | ||
require 'mkit/app/model/service' | ||
require 'mkit/exceptions' | ||
|
||
class ServicePort < ActiveRecord::Base | ||
belongs_to :service | ||
|
||
CONFIG_EXPRESSION=/^(.*?):(.*?):(tcp|http):(.*?)$/ | ||
|
||
def self.create(service:, config:) | ||
sp = ServicePort.new(service: service, version: service.version) | ||
sp.parse_config(config) | ||
sp | ||
end | ||
|
||
# haproxy support for port range - leave src blank | ||
# haproxy support for port range - leave dest blank | ||
# service: | ||
# ports: | ||
# # src:dest:tcp|http:load-balancing | ||
# # src:dest:tcp|http:round_robin|leastconn | ||
# - 5532:5432:tcp:round_robin | ||
# - 5532-6000::tcp:round_robin | ||
# model: | ||
# service_ports: | ||
# - external: 5432 | ||
# internal: 5432 | ||
# mode: tcp|http | ||
# load_bal: | ||
# load_bal: round_robin | ||
def parse_config(config) | ||
ports = config.split(':') | ||
self.external_port = ports[0] | ||
self.internal_port = ports[1] | ||
self.mode = ports[2] | ||
self.load_bal = ports[3] | ||
ports = config.match(CONFIG_EXPRESSION) | ||
raise MKIt::InvalidPortsConfiguration.new("no match with config expression $#{CONFIG_EXPRESSION}") if ports.nil? | ||
|
||
self.external_port = ports[1] | ||
self.internal_port = ports[2] | ||
self.mode = ports[3] | ||
self.load_bal = ports[4] | ||
end | ||
|
||
def load_balance | ||
case self.load_bal | ||
when /^round_robin$/ | ||
"roundrobin" | ||
when /^leastconn$/ | ||
"leastconn" | ||
else | ||
"roundrobin" | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,30 +1,27 @@ | ||
# | ||
# MKIt generated file | ||
# | ||
<% public_ports.each { |external_port|%> | ||
<% service_port.each { |port|%> | ||
# | ||
# start <%=name%>-<%=external_port%> | ||
# start <%=name%>-<%=port.external_port%> | ||
# | ||
frontend <%=name%>-<%=external_port%>-front | ||
bind <%=lease.ip%>:<%=external_port%> | ||
mode <%=ports_mode_by_external(external_port)%> | ||
frontend <%=name%>-<%=port.external_port%>-front | ||
bind <%=lease.ip%>:<%=port.external_port%> | ||
mode <%=port.mode%> | ||
# | ||
use_backend <%=name%>-<%=external_port%>-back | ||
use_backend <%=name%>-<%=port.external_port%>-back | ||
|
||
backend <%=name%>-<%=external_port%>-back | ||
mode <%=ports_mode_by_external(external_port)%> | ||
#balance leastconn | ||
balance roundrobin | ||
<%if ports_mode_by_external(external_port) == 'http'%> | ||
option httpclose | ||
option forwardfor | ||
cookie JSESSIONID prefix | ||
<%end%> | ||
<%ports_by_external(external_port).each { |port| %> | ||
<%port.service.pod.each { | pod | %> | ||
server <%=pod.name%> <%=pod.ip%>:<%=port.internal_port%> <%if port.mode == 'http'%>cookie A<%end%> check<%}%><%}%> | ||
# | ||
# end of <%=name%>-<%=external_port%> | ||
backend <%=name%>-<%=port.external_port%>-back | ||
mode <%=port.mode%> | ||
balance <%=port.load_balance%> | ||
<%if port.mode == 'http'%> | ||
option httpclose | ||
option forwardfor | ||
cookie JSESSIONID prefix | ||
<%end%><%port.service.pod.each { | pod | %> | ||
server <%=pod.name%> <%=pod.ip%><%unless port.internal_port.nil? || port.internal_port.empty? then%><%=":#{port.internal_port}"%> <%if port.mode == 'http'%>cookie A<%end%> check<%end%> | ||
<%}%> | ||
# | ||
<%}%> | ||
|
||
# end of <%=name%>-<%=port.external_port%> | ||
# | ||
<%}%> |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module MKIt | ||
VERSION = "0.3.0" | ||
VERSION = "0.4.0" | ||
end | ||
|
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