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

fix(prefect-server): better support for internal and external database configs #365

Merged
merged 11 commits into from
Aug 13, 2024

Conversation

mitchnielsen
Copy link
Contributor

@mitchnielsen mitchnielsen commented Jul 23, 2024

Summary

This will be a breaking change, so we should release this in a new major version. The configuration keys have moved around. If we really need to, we can try to build in some backwards-compatibility, but that always ends up looking pretty rough in Helm.

Ensures that the PostgreSQL Secret is created, even if postgresql.enabled=false. This ensures that we support a use case where folks want to use an external instance of PostgreSQL, but still want the Secret to automatically be generated with the proper connection string.

With a recent change, we would skip creation of this secret if PostgreSQL was disabled which forced users to create a Secret themselves. This change now allows them to continue providing the auth values and letting the chart build the Secret with the correct connection string.

I ended up needing to go a step further by removing any custom configuration that was injected under the postgresql key, which should be dedicated to overriding default values from the PostgreSQL chart. There's now a new secret key, which aligns with the other top-level keys (deployment, service, etc.). These values will be considered if postgresql.enabled=false.

Closes #358

Follow-up to #341.

Testing

See the added test suite.

Ensures that the PostgreSQL Secret is created, even if
`postgresql.enabled=false`. This ensures that we support a use case
where folks want to use an external instance of PostgreSQL, but still
want the Secret to automatically be generated with the proper connection
string.

With a recent change, we would skip creation of this secret if
PostgreSQL was disabled which forced users to create a Secret
themselves. This change now allows them to continue providing the `auth`
values and letting the chart build the Secret with the correct
connection string.

Closes #358
@mitchnielsen mitchnielsen added the fix A fix for a bug in an existing feature label Jul 23, 2024
@mitchnielsen mitchnielsen self-assigned this Jul 23, 2024
@mitchnielsen
Copy link
Contributor Author

@ahgraber @tmyhu @MRocholl - I believe this should cover all the use cases you mentioned. Could you please give this a look when you have a moment and let me know if this needs any tweaking?

Trying to make it flexible enough to cover all use cases while keeping it as consistent/straightforward as possible. Thanks!

@tmyhu
Copy link
Contributor

tmyhu commented Jul 23, 2024

@mitchnielsen it looks good to me, but won't make any difference for our use case since we are using SQLite. I assume that's not something you really want to support specifically since there is no hint about it anywhere in the helm chart I could see? We should probably migrate to PostgreSQL anyway, but for now I'm happy to continue creating the secret and connection string manually for SQLite.

@ahgraber
Copy link

@mitchnielsen Thanks for this effort!

The output connection string from the test deployment's secret is missing the hostname in the database address; will that still be pulled in from postgresql.externalHostname? If so, I believe this covers the requested use case.

@mitchnielsen mitchnielsen mentioned this pull request Jul 24, 2024
2 tasks
@mitchnielsen
Copy link
Contributor Author

it looks good to me, but won't make any difference for our use case since we are using SQLite. I assume that's not something you really want to support specifically since there is no hint about it anywhere in the helm chart I could see? We should probably migrate to PostgreSQL anyway, but for now I'm happy to continue creating the secret and connection string manually for SQLite.

@tmyhu fair point. We have this in mind and are tracking in #345. I'd like to provide the auth configuration outside of the context of the postgresql key to make the configuration more clear, and open the door for supporting SQLite since we provide that information in our self-hosted docs. That said, moving to PostgreSQL is probably the ideal longer-term move.

@mitchnielsen
Copy link
Contributor Author

@ahgraber great call-out, let me see if I can make a minimal change to make that configuration supported. If not, may need to jump ahead to providing this config outside of the postgresql key because of how some of the nested templates are used.

The `postgresql` key in `values.yaml` is for overriding the PostgreSQL
chart's default values. It's not a good place to define custom keys
because these are conflated with the actual configuration from the
subchart. This changes removes those custom configs.

It also removes any configured values that already matched the default
from the PostgreSQL subchart, and were therefore not doing anything.
When the PostgreSQL subchart is disabled, we need a way to provide the
connection string information for the external instance. This adds the
required values and template helpers to calculate the connection string
in this scenario.
- Supports setting the name to use for the Secret
- Supports controlling whether or not to create the Secret
- Supports someone providing their own existing Secret
Uses https://github.com/helm-unittest/helm-unittest
to unit test the database configuration. This is a replacement
for coming up with test cases locally, running `helm template`, and
manually validating the output.
- Adds script to run helm-unittest locally
- Adds CI workflow to run helm-unittest in GitHub Actions
Updates the README to reflect the new configuration for external
databases.
@mitchnielsen mitchnielsen added breaking feature A new feature and removed fix A fix for a bug in an existing feature labels Jul 25, 2024
@mitchnielsen mitchnielsen changed the title fix(prefect-server): create PostgreSQL Secret even if postgresql.enabled=false fix(prefect-server): better support for internal and external database configs Jul 25, 2024
@mitchnielsen
Copy link
Contributor Author

@ahgraber @tmyhu @MRocholl - alrighty, bit of a rework here to make sure we have proper support for either internal or external database configuration. For some examples of the configuration you'd provide, check out the updated docs or the unit test file. Welcoming any feedback here 🤝

@MRocholl
Copy link

@mitchnielsen sorry for the late reply. These changes should satisfy the requirements I believe 👍 Thx for the great work

@mitchnielsen mitchnielsen marked this pull request as ready for review August 12, 2024 19:38
@mitchnielsen mitchnielsen requested a review from a team as a code owner August 12, 2024 19:38
@mitchnielsen
Copy link
Contributor Author

sorry for the late reply. These changes should satisfy the requirements I believe 👍 Thx for the great work

@MRocholl - no worries at all, thank you for confirming 🤝

@@ -340,8 +342,6 @@ postgresql:
persistence:
# -- enable PostgreSQL Primary data persistence using PVC
enabled: false
# -- PVC Storage Request for PostgreSQL volume
size: 8Gi
Copy link
Contributor

Choose a reason for hiding this comment

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

does this default need to be re-implemented somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't need to, since it's the default in Bitnami's values.yaml. We could technically leave this here, but I deleted it to make it more clear that everything defined under postgresql is an override for the chart's defaults.

@@ -293,7 +293,26 @@ ingress:
## port:
## name: http

# Postgresql configuration
# Secret configuration
secret:
Copy link
Contributor

Choose a reason for hiding this comment

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

just so i understand, .Values.secret is specifically for BYO postgres credentials?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, it gives us somewhere outside of the context of postgresql. to define database configs (so we can dedicate postgresql. settings for the PostgreSQL chart without overloading it with our own chart's configs).

Installs the helm/chart-testing binary at its latest version.
Needed for the tests defined under `charts/<chart>/tests/test-*.yaml`.
@mitchnielsen mitchnielsen merged commit bfe341a into main Aug 13, 2024
17 checks passed
@mitchnielsen mitchnielsen deleted the db-secret-config branch August 13, 2024 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking feature A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changes to chart with postgresql.enabled = false and external postgres break deployment
6 participants