Skip to content

Commit

Permalink
Fixes #37325 - make postgres the container gateway default DB
Browse files Browse the repository at this point in the history
  • Loading branch information
ianballou committed Apr 9, 2024
1 parent 5da646f commit e92564d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ class { 'foreman_proxy::plugin::ansible':
}
```

### Katello Container Gateway Support

If installing a Foreman Proxy with the Container Gateway, ensure that the
postgresql module is available for use on the system.

## Contributing

* Fork the project
Expand Down
26 changes: 26 additions & 0 deletions manifests/plugin/container_gateway.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
#
# $pulp_endpoint:: Pulp 3 server endpoint
#
# $database_backend:: 'sqlite' or 'postgres'
#
# $postgresql_host:: Host of the postgres database.
#
# $postgresql_port:: Port of the postgres database.
#
# $postgresql_database:: Name of the postgres database
#
# $postgresql_user:: User for the postgres database
#
# $postgresql_password:: User password for the postgres database
#
# $sqlite_db_path:: Absolute path for the SQLite DB file to exist at
#
# $sqlite_timeout:: Database busy timeout in milliseconds
Expand All @@ -22,13 +34,27 @@
Boolean $enabled = true,
Foreman_proxy::ListenOn $listen_on = 'https',
Stdlib::HTTPUrl $pulp_endpoint = "https://${facts['networking']['fqdn']}",
String $database_backend = 'postgres',
Stdlib::Absolutepath $sqlite_db_path = '/var/lib/foreman-proxy/smart_proxy_container_gateway.db',
Optional[Integer] $sqlite_timeout = undef,
Stdlib::Host $postgresql_host = 'localhost',
Stdlib::Port $postgresql_port = 5432,
String $postgresql_database = 'container_gateway',
String $postgresql_user = 'foreman-proxy',
String $postgresql_password = extlib::cache_data('container_gateway_cache_data', 'db_password', extlib::random_password(32))
) {
foreman_proxy::plugin::module { 'container_gateway':
version => $version,
enabled => $enabled,
feature => 'Container_Gateway',
listen_on => $listen_on,
}
include postgresql::server
postgresql::server::db { $foreman_proxy::plugin::postgresql_database:
user => $foreman_proxy::plugin::postgresql_user,
password => postgresql::postgresql_password($foreman_proxy::plugin::postgresql_user, $foreman_proxy::plugin::postgresql_db_password),
encoding => 'utf8',
locale => 'en_US.utf8',
require => Package['glibc-langpack-en'],
}
}
22 changes: 21 additions & 1 deletion spec/classes/foreman_proxy__plugin__container_gateway_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,20 @@
let(:pre_condition) { 'include foreman_proxy' }

describe 'with default settings' do
# TODO: Should the random postgres password be tested?
let :postgresql_password do 'changeme' end
it { should contain_foreman_proxy__plugin__module('container_gateway') }
it 'container_gateway.yml should contain the correct configuration' do
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml', [
'---',
':enabled: https',
":pulp_endpoint: https://#{facts[:fqdn]}",
':database_backend: postgresql',
':postgresql_host: localhost',
':postgresql_port: 5432',
':postgresql_database: container_gateway',
':postgresql_user: foreman-proxy',
':postgresql_password: changeme'
':sqlite_db_path: /var/lib/foreman-proxy/smart_proxy_container_gateway.db'
])
end
Expand All @@ -21,17 +29,29 @@
describe 'with overwritten parameters' do
let :params do {
:pulp_endpoint => 'https://test.example.com',
:database_backend => 'postgresql',
:sqlite_db_path => '/dev/null.db',
:sqlite_timeout => 12345,
:postgresql_host => 'test.example.com',
:postgresql_port => 5432,
:postgresql_database => 'container_gateway'
:postgresql_user => 'foreman-proxy'
:postgresql_password => 'changeme'
} end

it 'container_gateway.yml should contain the correct configuration' do
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/container_gateway.yml', [
'---',
':enabled: https',
':pulp_endpoint: https://test.example.com',
':database_backend: postgresql',
':sqlite_db_path: /dev/null.db',
':sqlite_timeout: 12345'
':sqlite_timeout: 12345',
':postgresql_host: test.example.com',
':postgresql_port: 5432',
':postgresql_database: container_gateway',
':postgresql_user: foreman-proxy',
':postgresql_password: changeme'
])
end
end
Expand Down
12 changes: 12 additions & 0 deletions templates/plugin/container_gateway.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,19 @@
# Container Gateway for Katello
:enabled: <%= @module_enabled %>
:pulp_endpoint: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::pulp_endpoint") %>
:database_backend: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::database_backend") %>
:sqlite_db_path: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_db_path") %>
<% if scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_timeout") -%>
:sqlite_timeout: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::sqlite_timeout") %>
<% end -%>
:postgresql_connection_string: postgres://<%=
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_user")}:" \
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_password")}@" \
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_host")}:" \
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_port")}/" \
"#{scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_database")}"
%>
:postgresql_host: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_host") %>
:postgresql_port: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_port") %>
:postgresql_user: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_user") %>
:postgresql_password: <%= scope.lookupvar("foreman_proxy::plugin::container_gateway::postgresql_password") %>

0 comments on commit e92564d

Please sign in to comment.