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

feat(providers): single database mode #1101

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

vkrizan
Copy link
Contributor

@vkrizan vkrizan commented Dec 9, 2024

Creates a new database provider mode named single.
The aim of the mode is to create a single database instance and share it
between the apps by separating them by Posgres schemas.
Each app gets a schema created by the name of the requested database.
Schemas are created under environment's database, with the same name as
the ClowdEnv.

Adds the following refactorings:

  • provutils.DefaultPGPort to set port constant
  • provutils.DefaultPGAdminUsername to set default PG admin user
  • provutils.PGAdminConnectionStr that builds sanitized connection string to PG from a DatabaseConfig using admin creds
  • provutils.ReadDbConfigFromSecret to reuse read of DatabaseConfigs from secrets, optionally using a cache

RHINENG-14526

@vkrizan
Copy link
Contributor Author

vkrizan commented Dec 9, 2024

@psav I've opted for "single" as the name of the db mode. Suggestions and reviews are welcome. Thank you.

@vkrizan vkrizan force-pushed the single-db-provider branch 2 times, most recently from e0a2a56 to 86ee564 Compare December 20, 2024 14:44
@vkrizan vkrizan force-pushed the single-db-provider branch from 86ee564 to 5d02dad Compare January 13, 2025 14:18

var pgPassword string
if setAdmin {
pgPassword, err = utils.RandPassword(16, provutils.RCharSet)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

My initial thought was to disable admin user for apps, however some apps might still require this to do some setups (i.e. create additional users). @psav any suggestions how we should approach this situation? I guess, one of the option is to update those services needing such privileges, or look at the privileges case-by-case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's tricky because ephemeral usage often relies on them needing to do more stuff than usual, but in prod they will just get the credentials which are appropriate

Copy link
Contributor

Choose a reason for hiding this comment

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

There are some services that run a CREATE EXTENSION in their migrations ... for example advisor-backend uses the 'hll' extension. I'm not sure how something like that will work with 'single' DB mode. Perhaps we could have Clowder pre-load known extensions after it spins up the DB. Anyways, unless you need support for that right now, that is something a follow-up PR could address.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. I want to test those apps to see how they would work with this limited access... AFAIK Advisor, has dropped or is dropping the HLL extension.

Copy link
Contributor

Choose a reason for hiding this comment

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

We plan to remove use of the HLL extension next week (17th Feb 2025).

Copy link
Contributor

Choose a reason for hiding this comment

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

That's the only extension I'm aware of in Advisor.

@vkrizan
Copy link
Contributor Author

vkrizan commented Jan 13, 2025

I'm opening this up from a draft state for review. There still might be some small issues in certain conditions. I prefer to get this out sooner to do a bunch of testing on a test cluster. Thank you.

@vkrizan vkrizan marked this pull request as ready for review January 13, 2025 14:33
@vkrizan vkrizan force-pushed the single-db-provider branch from 5d02dad to b7285df Compare January 13, 2025 14:55
@psav
Copy link
Collaborator

psav commented Jan 13, 2025

I'm opening this up from a draft state for review. There still might be some small issues in certain conditions. I prefer to get this out sooner to do a bunch of testing on a test cluster. Thank you.

We should talk about the expectation here and I was thinking we can deploy this for testing in the cluster - without merging it and only merge when we are ready - allows us to not goof up the cluster too much. @bsquizz @wcmitchell

@adamrdrew
Copy link
Contributor

/retest

1 similar comment
@adamrdrew
Copy link
Contributor

/retest

Copy link
Contributor

@PaulWay PaulWay left a comment

Choose a reason for hiding this comment

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

I don't know Go or Clowder well enough to know whether it works or not but just contributing a few suggestions for the documentation.

the provider will pass through database credentials found
in the secret defined by the database name in the
ClowdApp, (*_local_*) where the provider will spin up a
local instance of the database, and (*_single_*) that is
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like the shared option is not documented here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hopefully fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

I think another make pre-push will be needed to get the above changes to the comment reflected in the description here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've called it again, and there is no visible change.

I've used this as the no-update target is git setup dependent:

make manifests generate genconfig build-template api-docs

@vkrizan vkrizan force-pushed the single-db-provider branch 2 times, most recently from 7e86346 to e270e2a Compare February 3, 2025 15:23
Copy link
Contributor

@bsquizz bsquizz left a comment

Choose a reason for hiding this comment

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

The approach looks good and I like the consolidation of common operations into provutils. Aside from my nitpicks on the DB mode descriptions, I think the biggest thing this needs is a kuttl test to ensure this works as expected. Let me know if you need help to get started on creating one.

Comment on lines +296 to +299
// where the provider will spin up a local instance of the database, (*_shared_*)
// where the provider will spin up only one shared instance per requested
// PostgreSQL version, and (*_single_*) that is similar to local and shared modes
// but keeps only one database deployment and isolates apps by PG schemas.
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to pick on shared mode since its not original intent of your PR to mess with this... I think the intent of it is to have 2+ ClowdApps share the same DB (same database, username, and password) correct?

The difference between 'shared' and 'single' can be confusing. Would wording like this clarify it better?

Suggested change
// where the provider will spin up a local instance of the database, (*_shared_*)
// where the provider will spin up only one shared instance per requested
// PostgreSQL version, and (*_single_*) that is similar to local and shared modes
// but keeps only one database deployment and isolates apps by PG schemas.
// where the provider will spin up a local instance of the database, (*_shared_*)
// where the provider will spin up one instance of the DB server intended to be
// accessed by multiple ClowdApps using the same database, and (*_single_*)
// which spins up one instance of the DB server and isolates each ClowdApp's
// access by creating a schema per ClowdApp.

the provider will pass through database credentials found
in the secret defined by the database name in the
ClowdApp, (*_local_*) where the provider will spin up a
local instance of the database, and (*_single_*) that is
Copy link
Contributor

Choose a reason for hiding this comment

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

I think another make pre-push will be needed to get the above changes to the comment reflected in the description here.

instance of the database.'
(*_local_*) where the provider will spin up a local instance
of the database, and (*_single_*) that is similar to local
but keeps only one database deployment and isolates apps
Copy link
Contributor

Choose a reason for hiding this comment

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

make pre-push will likely update this

instance of the database.'
(*_local_*) where the provider will spin up a local instance
of the database, and (*_single_*) that is similar to local
but keeps only one database deployment and isolates apps
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here


var pgPassword string
if setAdmin {
pgPassword, err = utils.RandPassword(16, provutils.RCharSet)
Copy link
Contributor

Choose a reason for hiding this comment

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

There are some services that run a CREATE EXTENSION in their migrations ... for example advisor-backend uses the 'hll' extension. I'm not sure how something like that will work with 'single' DB mode. Perhaps we could have Clowder pre-load known extensions after it spins up the DB. Anyways, unless you need support for that right now, that is something a follow-up PR could address.

Creates a new database provider mode named `single`.
The aim of the mode is to create a single database instance and share it
between the apps by separating them by Posgres schemas.
Each app gets a schema created by the name of the requested database.
Schemas are created under environment's database, with the same name as
the ClowdEnv.

RHINENG-14526
@vkrizan
Copy link
Contributor Author

vkrizan commented Feb 13, 2025

@bsquizz I've added a (blind) kuttl test. Blind, because I'm not able to run those locally. It's very heavy on resources.

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.

5 participants