helm-charts icon indicating copy to clipboard operation
helm-charts copied to clipboard

feat: optionally run migrations as an init contianer

Open jagregory opened this issue 1 year ago • 1 comments

As covered in a few other issues and PRs, there's a deadlock situation with the chart when deploying with helm --wait and/or ArgoCD:

  1. The OpenFGA Pod won't start until the migrations have been applied
  2. The Migration Job applies the migrations, and is configured as a Helm Hook
  3. When using helm --wait (or ArgoCD) hooks aren't run until all Pods are healthy
  4. Deadlock: Job won't start because the Pod isn't healthy yet, Pod will never become healthy until the Job runs

Description

This PR introduces an alternative mechanism for running the migrations: an init container on the OpenFGA pod. Instead of waiting for a Job to run, the migrations are ran when the Pod first starts as an init container.

A new migrationType value is added, which can be set to job or initContainer and defaults to job (so is a backwards-compatible change). If set to job the chart behaves as it currently does, but if set to initContainer then the following happens:

  1. the Job is not created
  2. the wait-for-container init container is not included on the Deployment
  3. a new migrate-database init container is included instead

References

  • https://github.com/openfga/helm-charts/issues/100
  • https://github.com/openfga/helm-charts/issues/120
  • https://github.com/openfga/helm-charts/issues/131
  • https://github.com/openfga/helm-charts/pull/99
  • https://github.com/openfga/helm-charts/pull/138

Review Checklist

  • [x] I have clicked on "allow edits by maintainers".
  • [ ] I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • [x] The correct base branch is being used, if not main
  • [ ] I have added tests to validate that the change in functionality is working as expected

jagregory avatar Sep 15 '24 23:09 jagregory