Skip to content

Commit 1b02464

Browse files
committed
Add loadbalancer support
Signed-off-by: Eric D. Helms <[email protected]>
1 parent 96b747d commit 1b02464

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

lib/smart_proxy_container_gateway/container_gateway.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Plugin < ::Proxy::Plugin
4141
container_instance.singleton_dependency :container_gateway_main_impl, (lambda do
4242
Proxy::ContainerGateway::ContainerGatewayMain.new(
4343
database: container_instance.get_dependency(:database_impl),
44-
**settings.slice(:pulp_endpoint, :pulp_client_ssl_ca, :pulp_client_ssl_cert, :pulp_client_ssl_key)
44+
**settings.slice(:pulp_endpoint, :pulp_client_ssl_ca, :pulp_client_ssl_cert, :pulp_client_ssl_key, :loadbalancer)
4545
)
4646
end)
4747
end

lib/smart_proxy_container_gateway/container_gateway_api.rb

+6-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ class Api < ::Sinatra::Base
4545
status pulp_response.code.to_i
4646
body pulp_response.body
4747
else
48-
redirection_location = pulp_response['location']
49-
redirect to(redirection_location)
48+
redirection_uri = URI(pulp_response['location'])
49+
redirection_uri.host = URI(container_gateway_main.loadbalancer).host
50+
redirect(redirection_uri.to_s)
5051
end
5152
end
5253

@@ -217,8 +218,9 @@ def head_or_get_blobs
217218
status pulp_response.code.to_i
218219
body pulp_response.body
219220
else
220-
redirection_location = pulp_response['location']
221-
redirect to(redirection_location)
221+
redirection_uri = URI(pulp_response['location'])
222+
redirection_uri.host = URI(container_gateway_main.loadbalancer).host
223+
redirect(redirection_uri.to_s)
222224
end
223225
end
224226

lib/smart_proxy_container_gateway/container_gateway_main.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ module ContainerGateway
99
extend ::Proxy::Log
1010

1111
class ContainerGatewayMain
12-
attr_reader :database
12+
attr_reader :database, :loadbalancer
1313

14-
def initialize(database:, pulp_endpoint:, pulp_client_ssl_ca:, pulp_client_ssl_cert:, pulp_client_ssl_key:)
14+
# rubocop:disable Metrics/ParameterLists, Layout/LineLength
15+
def initialize(database:, pulp_endpoint:, pulp_client_ssl_ca:, pulp_client_ssl_cert:, pulp_client_ssl_key:, loadbalancer: nil)
1516
@database = database
1617
@pulp_endpoint = pulp_endpoint
18+
@loadbalancer = loadbalancer || pulp_endpoint
1719
@pulp_client_ssl_ca = pulp_client_ssl_ca
1820
@pulp_client_ssl_cert = OpenSSL::X509::Certificate.new(File.read(pulp_client_ssl_cert))
1921
@pulp_client_ssl_key = OpenSSL::PKey::RSA.new(
2022
File.read(pulp_client_ssl_key)
2123
)
2224
end
25+
# rubocop:enable Metrics/ParameterLists, Layout/LineLength
2326

2427
def pulp_registry_request(uri, headers)
2528
http_client = Net::HTTP.new(uri.host, uri.port)

0 commit comments

Comments
 (0)