Skip to content

Commit 1dc73a1

Browse files
committed
Store username and password envs separately
1 parent f8a0b62 commit 1dc73a1

4 files changed

Lines changed: 56 additions & 29 deletions

File tree

crates/stackable-operator/src/crd/database/client/celery.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,29 @@ pub struct CeleryDatabaseConnectionDetails {
2020
/// `<generic URI from the user>`.
2121
pub uri_template: String,
2222

23-
/// The [`EnvVar`]s the operator needs to mount into the created Pods.
24-
pub env_vars: Vec<EnvVar>,
23+
/// The [`EnvVar`] that mounts the credentials Secret and provides the username.
24+
pub username_env: Option<EnvVar>,
25+
26+
/// The [`EnvVar`] that mounts the credentials Secret and provides the password.
27+
pub password_env: Option<EnvVar>,
28+
29+
/// The [`EnvVar`] that mounts the user-specified Secret and provides the generic URI.
30+
pub generic_uri_var: Option<EnvVar>,
2531
}
2632

2733
impl CeleryDatabaseConnectionDetails {
34+
pub fn env_vars(&self) -> impl Iterator<Item = &EnvVar> {
35+
[
36+
&self.username_env,
37+
&self.password_env,
38+
&self.generic_uri_var,
39+
]
40+
.into_iter()
41+
.flatten()
42+
}
43+
2844
pub fn add_to_container(&self, cb: &mut ContainerBuilder) {
29-
cb.add_env_vars(self.env_vars.iter());
45+
cb.add_env_vars(self.env_vars());
3046
}
3147
}
3248

@@ -51,7 +67,9 @@ impl CeleryDatabaseConnection for GenericCeleryDatabaseConnection {
5167

5268
CeleryDatabaseConnectionDetails {
5369
uri_template: format!("${{{uri_env_name}}}"),
54-
env_vars: vec![uri_env_var],
70+
username_env: None,
71+
password_env: None,
72+
generic_uri_var: Some(uri_env_var),
5573
}
5674
}
5775
}

crates/stackable-operator/src/crd/database/client/sqlalchemy.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,29 @@ pub struct SQLAlchemyDatabaseConnectionDetails {
2020
/// `<generic URI from the user>`.
2121
pub uri_template: String,
2222

23-
/// The [`EnvVar`]s the operator needs to mount into the created Pods.
24-
pub env_vars: Vec<EnvVar>,
23+
/// The [`EnvVar`] that mounts the credentials Secret and provides the username.
24+
pub username_env: Option<EnvVar>,
25+
26+
/// The [`EnvVar`] that mounts the credentials Secret and provides the password.
27+
pub password_env: Option<EnvVar>,
28+
29+
/// The [`EnvVar`] that mounts the user-specified Secret and provides the generic URI.
30+
pub generic_uri_var: Option<EnvVar>,
2531
}
2632

2733
impl SQLAlchemyDatabaseConnectionDetails {
34+
pub fn env_vars(&self) -> impl Iterator<Item = &EnvVar> {
35+
[
36+
&self.username_env,
37+
&self.password_env,
38+
&self.generic_uri_var,
39+
]
40+
.into_iter()
41+
.flatten()
42+
}
43+
2844
pub fn add_to_container(&self, cb: &mut ContainerBuilder) {
29-
cb.add_env_vars(self.env_vars.iter());
45+
cb.add_env_vars(self.env_vars());
3046
}
3147
}
3248

@@ -51,7 +67,9 @@ impl SQLAlchemyDatabaseConnection for GenericSQLAlchemyDatabaseConnection {
5167

5268
SQLAlchemyDatabaseConnectionDetails {
5369
uri_template: format!("${{{uri_env_name}}}"),
54-
env_vars: vec![uri_env_var],
70+
username_env: None,
71+
password_env: None,
72+
generic_uri_var: Some(uri_env_var),
5573
}
5674
}
5775
}

crates/stackable-operator/src/crd/database/server/postgresql.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ impl SQLAlchemyDatabaseConnection for PostgresqlConnection {
102102
);
103103
SQLAlchemyDatabaseConnectionDetails {
104104
uri_template,
105-
env_vars: vec![username_env, password_env],
105+
username_env: Some(username_env),
106+
password_env: Some(password_env),
107+
generic_uri_var: None,
106108
}
107109
}
108110
}
@@ -129,14 +131,9 @@ mod tests {
129131
sqlalchemy_connection_details.uri_template,
130132
"postgresql+psycopg2://${METADATA_DATABASE_USERNAME}:${METADATA_DATABASE_PASSWORD}@airflow-postgresql:5432/airflow"
131133
);
132-
assert_eq!(
133-
sqlalchemy_connection_details
134-
.env_vars
135-
.iter()
136-
.map(|env| &env.name)
137-
.collect::<Vec<_>>(),
138-
vec!["METADATA_DATABASE_USERNAME", "METADATA_DATABASE_PASSWORD"]
139-
);
134+
assert!(sqlalchemy_connection_details.username_env.is_some());
135+
assert!(sqlalchemy_connection_details.password_env.is_some());
136+
assert!(sqlalchemy_connection_details.generic_uri_var.is_none());
140137

141138
let jdbc_connection_details = postgres_connection
142139
.jdbc_connection_details(UNIQUE_DATABASE_NAME)

crates/stackable-operator/src/crd/database/server/redis.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ impl CeleryDatabaseConnection for RedisConnection {
5959
);
6060
CeleryDatabaseConnectionDetails {
6161
uri_template,
62-
env_vars: vec![username_env, password_env],
62+
username_env: Some(username_env),
63+
password_env: Some(password_env),
64+
generic_uri_var: None,
6365
}
6466
}
6567
}
@@ -87,16 +89,8 @@ mod tests {
8789
celery_connection_details.uri_template,
8890
"redis://${WORKER_QUEUE_DATABASE_USERNAME}:${WORKER_QUEUE_DATABASE_PASSWORD}@my-redis:42/13"
8991
);
90-
assert_eq!(
91-
celery_connection_details
92-
.env_vars
93-
.iter()
94-
.map(|env| &env.name)
95-
.collect::<Vec<_>>(),
96-
vec![
97-
"WORKER_QUEUE_DATABASE_USERNAME",
98-
"WORKER_QUEUE_DATABASE_PASSWORD"
99-
]
100-
);
92+
assert!(celery_connection_details.username_env.is_some());
93+
assert!(celery_connection_details.password_env.is_some());
94+
assert!(celery_connection_details.generic_uri_var.is_none());
10195
}
10296
}

0 commit comments

Comments
 (0)