Add Patroni to Omnibus
What does this MR do?
This MR incorporates Patroni in GitLab Omnibus for database clustering. It does it in a very specific way which has its benefits and limitations.
In this MR, the design decisions were made to achieve the following objectives:
- Patroni must co-exit with RepMgr.
- Patroni must be an opt-in solution for database clustering. It implies that the user may switch between RepMgr and Patroni.
- Database cluster configuration in
gitlab.rb
must be kept as simple as possible. - Introduction of new configuration attributes in
gitlab.rb
must be minimal, ideally none.
An overview of this MR
Roughly speaking, this MR has five pieces:
-
Software definitions for Patroni and Psycopg2. The software definitions use the latest bundled PostgreSQL version, i.e.
postgresql_new
. This is because they need,libpq
, the PostgreSQL client library. This MR relies on backward-compatibility oflibpq
to work with older PostgreSQL versions. -
Adjustments to Consul service registration to work with both repmgr and Patroni. In order to configure PgBouncer, Consul must work with Patroni to track changes of the cluster, in particular to answer "who is the leader?". Using a helper and predefined service checks
consul::service_postgresql
fills the gap and monitors PostgreSQL cluster status regardless of HA solution (Patroni or repmgr). -
Changing PostgreSQL cookbook to work for Patroni as well. Patroni actively takes over the configuration of PostgreSQL and manages its process(es). When Patroni is enabled, some resources must be skipped, e.g. running
initdb
orcreatedb
, or creating PostgreSQL user and enablingpostgresql
service (these are the tasks that are delegated to Patroni). Also, PostgreSQL configuration files,*.conf
, must be relocated to be picked up later after Patroni bootstraps the node. All of these is to ensure that Patroni and PostgreSQL won't collide. Enabling Patroni effectively removespostgresql
service from the list of GitLab services. Users must interact with Patroni to start or stop with PostgreSQL. That being said, the way that the bundled PostgreSQL is configured is left almost intact. Users can still work withpostgresql[...]
attributes ingitlab.rb
. Only a few attributes are overridden for Patroni (namelypatroni['postgresql'][...]
). -
Patroni cookbook which contains anything that is needed for configuring and running Patroni. To keep PostgreSQL configuration as is and to compensate for some of the steps that are skipped in
postgresql::enable
this MR leverages Patroni'scustom_bootstrap
andpost_bootstrap
features to copy PostgreSQL configuration and execute operations that require a running database instance such as creating roles and other database objects. -
patroni
sub-command forgitlab-ctl
. This MR only offers the very basics that are needed for the existing implementation to work. Further commands will be added in #5115 (closed).
How to test it?
https://gitlab.com/pursultani/gitlab-patroni-test contains Terraform provisioning and configuration scripts for setting up a GitLab HA cluster with Patroni on GCP. You can use the build artifact of this MR's pipeline to run the test (GitLab token is required).
This MR was tested for both creating a new cluster and converting an existing repmgr cluster.
Documentation
The MR for the documentation can be found here: gitlab!33363 (merged)
Caveats
- There is a known issue with conversion of standalone PostgreSQL instances. This issue can be fixed and will be addressed in #5265 (closed).
Improvements
- Add more test for Patroni cookbook and
gitlab-ctl patroni
sub-command.
Closes #5112 (closed)