feat: Add generic database connection mechanism#1163
feat: Add generic database connection mechanism#1163
Conversation
This reverts commit 8e05224. It was actually mot needed :)
| #[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct GenericCeleryDatabaseConnection { | ||
| /// The name of the Secret that contains an `uri` key with the complete SQLAlchemy URI. |
There was a problem hiding this comment.
Copied over from https://github.com/stackabletech/airflow-operator/pull/743/changes#r2786318061:
I feel URI is very generic. I think connectionString is a better description?
Techassi
left a comment
There was a problem hiding this comment.
Only a partial review, but I left a bunch of comments with my concern and ideas/suggestions
| { | ||
| self.env | ||
| .get_or_insert_with(Vec::new) | ||
| .extend(env_vars.into_iter().map(|e| e.borrow().clone())); |
There was a problem hiding this comment.
note: This makes zero sense. We make it look like we take an iterator of items which can be borrowed as EnvVar, but they are not actually not only borrowed, but cloned under the hood.
I would go as far as to call this an anti-pattern.
| @@ -0,0 +1,20 @@ | |||
| use k8s_openapi::api::core::v1::{EnvVar, EnvVarSource, SecretKeySelector}; | |||
|
|
|||
| pub fn env_var_from_secret( | |||
There was a problem hiding this comment.
note: I think this is not an appropriate name. We are not constructing an env var from a Kubernetes secret (which would need to be looked up), but we instead prepare the env var in such a way that it will source its value from a Secret (which the Kubernetes apiserver or the kubelet is responsible for).
| /// against the MySQL server. | ||
| pub credentials_secret: String, | ||
|
|
||
| /// Additional map of JDBC connection parameters to append to the connection URL. The given |
There was a problem hiding this comment.
note: I would avoid mentioning JDBC explicitly, because these parameters are not unique to JDBC. Most database connection URI schemas support these extra parameters in some shape or form.
|
|
||
| /// Name of a Secret containing the `username` and `password` keys used to authenticate | ||
| /// against the MySQL server. | ||
| pub credentials_secret: String, |
There was a problem hiding this comment.
note: I would like to follow the Kubernetes convention here and call this credentials_secret_name/credentialsSecretName instead.
| pub location: Option<String>, | ||
| } | ||
|
|
||
| impl JDBCDatabaseConnection for DerbyConnection { |
There was a problem hiding this comment.
note: This should be named JdbcDatabaseConnection instead.
| pub fn add_to_container(&self, cb: &mut ContainerBuilder) { | ||
| let env_vars = self.username_env.iter().chain(self.password_env.iter()); | ||
| cb.add_env_vars(env_vars); | ||
| } |
There was a problem hiding this comment.
note: This function name doesn't clearly convey what is being added to the container.
Putting this very bluntly: Add the connection details? What does this even mean? Do we write a file, do we spawn a command which does something, do we add env vars?
Of course I can see what the function does when I look at the body, but just looking at the name doesn't tell me anything. A better name could be add_env_vars_to_container.
| ) | ||
| } | ||
|
|
||
| /// Returns |
There was a problem hiding this comment.
question: Returns... what? Seems like half of the sentence is missing here.
|
|
||
| #[derive(Debug, Snafu)] | ||
| pub enum Error { | ||
| #[snafu(context(false), display("PostgreSQL error"))] |
There was a problem hiding this comment.
note: I don't see a reason why we would want/need context(false). If there is a good reason, it should be explained as a dev comment.
note: The error messages seem a little bland. We could at least say what happened, like "failed to construct PostgreSQL connection string/uri".
| } | ||
|
|
||
| #[derive(Copy, Clone, Debug, Default)] | ||
| pub enum TemplatingMechanism { |
There was a problem hiding this comment.
question: Do we really need both mechanims? If so, we should describe that in a dev comment.
| pub enum DummyDatabaseConnection { | ||
| Postgresql(PostgresqlConnection), | ||
| Mysql(MysqlConnection), | ||
| Derby(DerbyConnection), | ||
| Redis(RedisConnection), | ||
| GenericJDBC(GenericJDBCDatabaseConnection), | ||
| GenericSQLAlchemy(GenericSQLAlchemyDatabaseConnection), | ||
| GenericCelery(GenericCeleryDatabaseConnection), | ||
| } |
There was a problem hiding this comment.
note: Again, I have a whole couple of issues with this:
- I think this enum should be provided by the framework, just with the right variants:
postgresql,mysql,redis(new), andgeneric. - All the
Generic*variants are misplaced in my opinion. As per ADR, they should be covered by a singlegenericvariant. - The enum itself could provide helper functions to downstream users to construct/get the connection details.
Description
Part of stackabletech/issues#238
Definition of Done Checklist
Author
Reviewer
Acceptance