Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kong] rework migration job configuration #102

Merged
merged 6 commits into from
Apr 8, 2020
Merged

Conversation

rainest
Copy link
Contributor

@rainest rainest commented Apr 1, 2020

What this PR does / why we need it:

  • Create a new migrations section in values.yaml.
  • Add configurable annotations to migration jobs, with default annotations to disable Istio and Kuma sidecars.
  • Splits runMigrations into per-migration toggles under migrations.
  • Points NOTES.txt deprecation warnings to the relevant UPGRADE.md section rather than explaining the issue in place.
  • Add documentation for split deployments and init conflict issue.

This addresses several different issues:

Which issue this PR fixes

Fixes #19
Fixes #43

Special notes for your reviewer:

This supersedes #101

Checklist

[Place an '[x]' (no spaces) in all applicable fields. Please remove unrelated fields.]

  • PR is based off the current tip of the next branch and targets next, not master
  • New or modified sections of values.yaml are documented in the README.md
  • Title of the PR and commit headers start with chart name (e.g. [kong])

* Replace runMigrations with settings for each migration job under a
migrations block.
* Add support for job annotations, with default annotations to disable
  some service mesh sidecars.
* Add documentation instructing users to disable initial migrations
  after installing.
* Add documentation for managing clusters split across multiple
  releases.
* Update NOTES.txt warnings to reference URLs in the upgrade guide
  rather than explaining the issue in place.
* Add warning for runMigrations.
charts/kong/values.yaml Outdated Show resolved Hide resolved
charts/kong/values.yaml Outdated Show resolved Hide resolved
charts/kong/templates/migrations.yaml Outdated Show resolved Hide resolved
charts/kong/UPGRADE.md Outdated Show resolved Hide resolved
charts/kong/UPGRADE.md Outdated Show resolved Hide resolved
charts/kong/README.md Outdated Show resolved Hide resolved
charts/kong/README.md Show resolved Hide resolved
charts/kong/FAQs.md Outdated Show resolved Hide resolved
Apply various updates based on feedback in #102

Notably, this now fully automates creation of init-migrations during
install only, and deletes it after. It removes user control over that
job, as there should no longer be any scenario where it's needed.

This should be squashed into 857215e
with an amended message mentioning automatic init-migrations handling
before merger.
@rainest
Copy link
Contributor Author

rainest commented Apr 2, 2020

20f853f is mostly doc changes requested above. It has one major functionality change: the init job handling is now fully automated and avoids the conflict issue. It should be squashed into 857215e with an update to the original message.

Edit: git commit --fixup does not work how I think. 6913d3d should be squashed also.

I tried to make migrations.init effectively a hidden setting, i.e. it's not listed in values.yaml but does exist, and if set to false in values.yaml would indeed disable that job. For some reason that's not clear to me, the default in the template appears to always apply even when that is set, so the job cannot be disabled.

I've left the default in there since it'd otherwise rely on runMigrations only, with the net effect that the job is never disabled, even if you have runMigrations: false. However, with the addition of the .Release.IsInstall condition, I don't think this should be a concern: there really shouldn't be any reason to ever disable the init migrations job on install, and worst case (you have an already-initialized database), it simply exits without doing anything.

@rainest rainest requested a review from hbagdi April 2, 2020 21:26
Fix another newline chomp issue in NOTES.txt. This continues the work in
00fd543 and fixes a similar issue when
the proxy is not a LoadBalancer.

There do not appear to be any options for this other than placing the
"else if" and its first line of text on the same line, so it looks a bit
odd in the template itself.
charts/kong/UPGRADE.md Outdated Show resolved Hide resolved
charts/kong/README.md Outdated Show resolved Hide resolved
# Set runMigrations to run Kong migrations
runMigrations: true
# Enable/disable migration jobs, and set annotations for them
migrations:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Do we need to clarify with a doc line saying this is only valid for Kong installations backed by DB?
The reason I ask is because it is not totally obvious from just reading this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really--the job templates already disable themselves if DB-less is in use, and no changes are required to this config for it.

* Correct a typo in split release instructions.
* Remove superfluous configuration from example.
@rainest rainest requested a review from hbagdi April 6, 2020 21:04
@rainest rainest merged commit 8353a64 into next Apr 8, 2020
@hbagdi hbagdi deleted the feat/migration-split branch April 10, 2020 20:52
rainest added a commit that referenced this pull request Apr 10, 2020
* Replace runMigrations with settings for upgrade migrations jobs under
  a migrations block.
* Handle deleting init-migrations jobs automatically.
* Add warning for deprecated runMigrations setting.
* Add support for job annotations, with default annotations to disable
  some service mesh sidecars.
* Add documentation for managing clusters split across multiple
  releases.
* Update NOTES.txt warnings to reference URLs in the upgrade guide
  rather than explaining the issue in place.
* Fix a newline chomp issue in NOTES.txt.
@chenguang-Steve
Copy link

Hi @hbagdi @rainest
I see the below changes are closed and not included in latest release. I want to trigger migrations-post-upgrade.yaml and migrations-pre-upgrade.yaml when using helm install. But currently these are only triggered by helm upgrade. Is it possible add another hook annotations like helm.sh/hook: "pre-install" in migrations-pre-upgrade.yaml and helm.sh/hook: "post-install" in migrations-pre-upgrade.yaml

annotations:
helm.sh/hook: "post-upgrade"
helm.sh/hook-delete-policy: "before-hook-creation"
{{- range $key, $value := .Values.migrationAnnotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}

@rainest
Copy link
Contributor Author

rainest commented Jul 30, 2020

Could you elaborate? That's by design, as there's no reason for migrations up and migrations finish to roun outside the context of an upgrade.

Installs are handled using a different command (migrations bootstrap) with its own Job: https://github.com/Kong/charts/blob/master/charts/kong/templates/migrations.yaml. That's essentially always enabled (it does in fact have its own enable/disable toggle, but we don't list it in values.yaml, as it should never be necessary to disable that Job).

@chenguang-Steve
Copy link

Hi, thanks for your quick response.
The kong is integrated into my project. When project execute "stop" commands, then stop kong(helm delete), when project start then start kong(helm install)
The steps:

  1. project start(helm install kong), migrations command execute successfully. (migrations bootstrap)
  2. project stop(helm delete kong)
  3. Add additional plugin migration.
  4. project start(helm install kong)
    The kong failed to start because of below errors.

waiting for db
Error: /usr/local/share/lua/5.1/kong/cmd/start.lua:64: nginx: [error] init_by_lua error: /usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:20: New migrations available; run 'kong migrations up' to proceed
stack traceback:
[C]: in function 'error'
/usr/local/share/lua/5.1/kong/cmd/utils/migrations.lua:20: in function 'check_state'
/usr/local/share/lua/5.1/kong/init.lua:411: in function 'init'
init_by_lua:3: in main chunk
lua:3: in main chunk

I guess when add new plugin migrations based on already bootstrapped , we have to execute "migrations up"?
That is why I want execute to pre-update job when install. But this may does not work.
So for my case, possibly always execute helm install and helm upgrade when start my project?

@rainest
Copy link
Contributor Author

rainest commented Jul 31, 2020

@chenguang-Steve yeah--that's an atypical strategy we wouldn't normally expect to support: we'd normally expect users to have any custom plugins present when running helm install (which would then run their migrations during the kong bootstrap job) or to run helm upgrade when adding new plugins that require migrations.

Is there any reason you perform a full delete and re-install for this? I'd normally expect a helm upgrade in the scenario you describe, and don't see any reason it wouldn't achieve the same end.

You could probably perform a full delete and re-install when adding the additional plugin if you also reset your database or delete its PVC after deletion (note: don't do this if you aren't using the ingress controller or decK to manage configuration--it will destroy all configuration added manually through the admin API). However, it normally shouldn't be necessary to do so--an upgrade should suffice for most use cases. If there's a case where it doesn't, I'd be curious to know--it may be something we can handle better with improvements elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants