Skip to content

[Controller] Add logic to perform upgrades

Mitchell Nielsen requested to merge 4-implement-upgrade-logic into master

Summary

Adds upgrade logic based on that of the previous operator to:

  • Check if upgrading (when existing version on the CR status != desired version in CR spec)
  • If upgrading, run upgrade-specific steps (pre/post migrations, pausing/rolling Deployments)

Closes #4 (closed)

Closes #89 (closed)

To do

  • Track Version on CR
  • Track "Upgrading" status on CR
  • Cleanup/organization
  • Documentation

When upgrading

  • Deployments pause
  • Pre migrations run
  • Deployments unpause
  • Post migrations run
  • Deployments roll

When not upgrading

  • Deployments do not pause
  • Pre and post migrations run together (posed question: should we disable migrations in this scenario?)

Testing instructions

Initial release

  1. Deploy this branch (TAG=4-implement-upgrade-logic make build_operator and kubectl create ns gitlab-system && kubectl apply -f .build/operator.yaml).
  2. Deploy a standard GitLab CR using the second-newest GitLab version for spec.chart.version (at this time, that's 5.0.6).
  3. Watch the progress of the release:
    1. Observe that a migrations job with pre in the name is launched.
    2. At the same time, Webservice and Sidekiq deployments exist but are paused via spec.paused.
    3. Observe that when pre-migrations are done, the Webservice and Sidekiq pods come up (with BYPASS_SCHEMA_VERSION set in the dependencies initContainer).
    4. Once those are up, observe that the standard/post migrations job is created (no pre in the name).
    5. When standard/post migrations job is done, observe that the Webservice and Sidekiq pods are rolled (without the BYPASS_SCHEMA_VERSION set in the dependencies initContainer).
    6. When all pods are running, confirm that the GitLab CR status.phase=Running and status.version is set to 5.0.6.

Version upgrade

  1. Update your GitLab CR: .spec.chart.version=5.1.1 (the latest available in CHART_VERSIONS) and apply it to the cluster.
  2. Observe similar behavior to the above.

Normal update (configuration change)

  1. Update your GitLab CR's spec.chart.values with something like global.ingress.hostSuffix=foo (something that will update resources but not constitute a version upgrade).
  2. Observe that a normal migrations job is run (i.e. without pre in the name, running pre and post migrations together).
  3. Observe that status.version on the CR does not change.

Test example (logs)

2021-09-14T21:08:17.468Z        INFO    controllers.GitLab      Reconciling GitLab      {"gitlab": "gitlab-system/gitlab"}
2021-09-14T21:08:17.469Z        DEBUG   controllers.GitLab      version information     {"gitlab": "gitlab-system/gitlab", "upgrade": true, "current version": "5.0.6", "desired version": "5.1.1"}
2021-09-14T21:08:17.913Z        INFO    controllers.GitLab      reconciling Webservice and Sidekiq Deployments (paused) {"gitlab": "gitlab-system/gitlab"}
2021-09-14T21:08:18.406Z        INFO    controllers.GitLab      reconciling pre migrations      {"gitlab": "gitlab-system/gitlab"}
2021-09-14T21:08:18.407Z        DEBUG   controllers.GitLab      Creating object {"gitlab": "gitlab.gitlab-system", "type": "*v1.Job", "reference": "gitlab-system/gitlab-migrations-1-ab0-pre"}
2021-09-14T21:09:21.437Z        INFO    controllers.GitLab      ensuring Webservice and Sidekiq Deployments are unpaused        {"gitlab": "gitlab-system/gitlab"}
2021-09-14T21:09:21.465Z        INFO    controllers.GitLab      ensuring Webservice and Sidekiq Deployments are running {"gitlab": "gitlab-system/gitlab"}
2021-09-14T21:09:26.466Z        DEBUG   controllers.GitLab      sidekiq not fully running       {"gitlab": "gitlab.gitlab-system", "namespace": "gitlab-system"}
2021-09-14T21:10:26.468Z        DEBUG   controllers.GitLab      check passed, proceeding        {"gitlab": "gitlab.gitlab-system", "namespace": "gitlab-system"}
2021-09-14T21:10:31.468Z        DEBUG   controllers.GitLab      webservice not fully running    {"gitlab": "gitlab.gitlab-system", "namespace": "gitlab-system"}
2021-09-14T21:11:31.471Z        DEBUG   controllers.GitLab      check passed, proceeding        {"gitlab": "gitlab.gitlab-system", "namespace": "gitlab-system"}
2021-09-14T21:11:31.471Z        INFO    controllers.GitLab      reconciling post migrations     {"gitlab": "gitlab-system/gitlab"}
2021-09-14T21:11:31.471Z        DEBUG   controllers.GitLab      Creating object {"gitlab": "gitlab.gitlab-system", "type": "*v1.Job", "reference": "gitlab-system/gitlab-migrations-1-ab0"}
2021-09-14T21:12:28.487Z        INFO    controllers.GitLab      performing a rolling update on Webservice and Sidekiq Deployments       {"gitlab": "gitlab-system/gitlab"}
2021-09-14T21:12:28.513Z        INFO    controllers.GitLab      ensuring Webservice and Sidekiq Deployments are running {"gitlab": "gitlab-system/gitlab"}
2021-09-14T21:12:33.514Z        DEBUG   controllers.GitLab      sidekiq not fully running       {"gitlab": "gitlab.gitlab-system", "namespace": "gitlab-system"}
2021-09-14T21:16:03.527Z        DEBUG   controllers.GitLab      check passed, proceeding        {"gitlab": "gitlab.gitlab-system", "namespace": "gitlab-system"}
2021-09-14T21:16:18.613Z        DEBUG   controllers.GitLab      gitlab successfully reconciled  {"gitlab": "gitlab-system/gitlab"}
Edited by Mitchell Nielsen

Merge request reports