Skip to content

Commit 06de107

Browse files
authored
fix(k8s): Inject actual environment when creating stateful set (#348)
1 parent 2022886 commit 06de107

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

etl-api/src/k8s/base.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@ use thiserror::Error;
1010
pub enum K8sError {
1111
/// A serialization or deserialization error while building or parsing
1212
/// Kubernetes resources.
13-
#[error("An error occurred in serde: {0}")]
13+
#[error("An error occurred in serde when dealing with K8s: {0}")]
1414
Serde(#[from] serde_json::error::Error),
1515
/// An error returned by the [`kube`] client when talking to the API
1616
/// server.
17-
#[error("An error occurred with kube: {0}")]
17+
#[error("An error occurred with kube when dealing with K8s: {0}")]
1818
Kube(#[from] kube::Error),
19-
/// The environment-dependent replicator configuration could not be
20-
/// determined.
21-
#[error("An error occurred while configuring the replicator")]
22-
ReplicatorConfiguration,
19+
/// The environment was not found while configuring K8s.
20+
#[error("Could not get environment when dealing with K8s")]
21+
MissingEnvironment,
2322
}
2423

2524
/// A simplified view of a pod phase.

etl-api/src/k8s/http.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ struct DynamicReplicatorConfig {
7474

7575
impl DynamicReplicatorConfig {
7676
/// Loads the runtime limits for the current environment.
77-
fn load() -> Result<Self, K8sError> {
78-
let environment = Environment::load().map_err(|_| K8sError::ReplicatorConfiguration)?;
79-
77+
fn load(environment: &Environment) -> Result<Self, K8sError> {
8078
let config = match environment {
8179
Environment::Prod => Self {
8280
max_memory: REPLICATOR_MAX_MEMORY_PROD,
@@ -302,6 +300,9 @@ impl K8sClient for HttpK8sClient {
302300
) -> Result<(), K8sError> {
303301
info!("patching stateful set");
304302

303+
let environment = Environment::load().map_err(|_| K8sError::MissingEnvironment)?;
304+
let config = DynamicReplicatorConfig::load(&environment)?;
305+
305306
let stateful_set_name = format!("{prefix}-{REPLICATOR_STATEFUL_SET_SUFFIX}");
306307
let replicator_app_name = format!("{prefix}-{REPLICATOR_APP_SUFFIX}");
307308
let replicator_container_name = format!("{prefix}-{REPLICATOR_CONTAINER_NAME_SUFFIX}");
@@ -310,8 +311,6 @@ impl K8sClient for HttpK8sClient {
310311
let bq_secret_name = format!("{prefix}-{BQ_SECRET_NAME_SUFFIX}");
311312
let replicator_config_map_name = format!("{prefix}-{REPLICATOR_CONFIG_MAP_NAME_SUFFIX}");
312313

313-
let config = DynamicReplicatorConfig::load()?;
314-
315314
let mut stateful_set_json = json!({
316315
"apiVersion": "apps/v1",
317316
"kind": "StatefulSet",
@@ -419,7 +418,7 @@ impl K8sClient for HttpK8sClient {
419418
"env": [
420419
{
421420
"name": "APP_ENVIRONMENT",
422-
"value": "prod"
421+
"value": environment.to_string()
423422
},
424423
{
425424
"name": "APP_SENTRY__DSN",

0 commit comments

Comments
 (0)