Support running database migrations
What does this MR do?
The archive of the PoC was moved to !35 (closed)
It requires !32 (merged), and needs to be rebased.
Similar to GitLab Chart, it provides a single migration Job that handles seeding/migrating the GitLab database. The Job runs using the GitLab Rails codebase.
More details can be found: https://docs.gitlab.com/charts/charts/gitlab/migrations/
This change enables the controller to create the Job resources to run the migration Job when it is enabled and:
- The GitLab instance is installed for the first time
- The GitLab CR has been updated
The migration Job will be named as {{ GitLab.Name }}-migrations-{{ GitLab.Generation }}
, and the latest Job will be kept for troubleshooting.
Overview of changes
Key changes are:
api/v2alpha1
assets/templates/migrations
internal/controller/helpers/migrations
internal/controller/tasks
internal/controller/gitlab_controller.go
api/v2alpha1
- A top-level
initialRootPassword
field is added to initialize the root password upon installation. It is currently required. - A top-level
databaseMigration
field is added. Database migrations are enabled by default. Users can disable unneeded migrations by setting theenabled
to false. Like other services, the image migration Jobs uses can also be customized.
Generated codes in config/crd/bases
are also updated.
assets/templates/migrations
Templates for the migration Jobs.
internal/controller/helpers/migrations
Database migrations are defined as MigrationTask
.
Before running the task, all required secrets must exist as prerequisites:
- rails-config
- rails-secret
- workhorse-secret (currently required because of reusing rail config, but not actually used)
- initial root password secret (currently required)
It will:
- Build a migration Job from the templates.
- Apply the Job resource.
- Wait for the job to complete.
internal/controller/tasks
To facilitate the MigrationTask
, a Wait
task is added to help wait for a Job to complete.
What is done
-
Configuration of the migration from GitLab CR -
Running Migration as a Task
Before merging
-
Rebase onto !32 (merged)
Furthur TODOs (what is missing):
-
Updating the status of GitLab CR -
Cleaning up previous Jobs. See operator v1 gitlab_controller.gg#L479-501 -
Pre-Migration -
Dropping workhorse secret dependency
Author's Checklist
For anything in this list which will not be completed, please provide a reason in the MR discussion.
Required
-
Ensure a release milestone is set. -
MR title and description are up to date, accurate, and descriptive. -
MR targeting the appropriate branch. -
MR has a green pipeline on GitLab.com. -
When ready for review, MR is labeled workflowready for review per the MR workflow.
Expected
-
Test plan indicating conditions for success has been posted and passes. -
Documentation is created or updated. -
Tests are added.
Related issues
Closes #5 (closed)