Skip to content

Commit 0649973

Browse files
committed
reworked crd change following decision
1 parent b91afae commit 0649973

4 files changed

Lines changed: 45 additions & 16 deletions

File tree

deploy/helm/airflow-operator/crds/crds.yaml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,16 @@ spec:
591591
- repo
592592
type: object
593593
type: array
594-
dbInit:
595-
default: true
596-
description: Whether to execute the database initialization routines (a combination of database initialization, upgrade and migration depending on the Airflow version). Defaults to true to be backwward compatible.
597-
type: boolean
594+
databaseInitialization:
595+
default:
596+
enabled: true
597+
description: 'Whether to execute the database initialization routines (a combination of database initialization, upgrade and migration depending on the Airflow version). Defaults to true to be (techincally) backwards-compatible but also safe. WARNING: setting this to false is *unsupported* as subsequent updates to the Airflow cluster may result in broken behaviour due to inconsistent metadata! Do not change the default unless you know what you are doing!'
598+
properties:
599+
enabled:
600+
default: true
601+
description: Whether to execute the database initialization routines (a combination of database initialization, upgrade and migration depending on the Airflow version). Defaults to true to be backwward compatible.
602+
type: boolean
603+
type: object
598604
exposeConfig:
599605
default: false
600606
description: for internal use only - not for production use.

docs/modules/airflow/pages/usage-guide/db-init.adoc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
= Database initialization
2-
:description: Configure Airflow DB start-up.
2+
:description: Configure Airflow Database start-up.
33

44
By default, Airflow will run database initialization routines (checking and/or creating the metadata schema and creating an admin user) on start-up.
55
These are idempotent and can be run every time as the overhead is minimal.
@@ -14,9 +14,13 @@ metadata:
1414
name: airflow
1515
spec:
1616
clusterConfig:
17-
dbInit: false # <1>
17+
databaseInitialization:
18+
enabled: false # <1>
1819
----
19-
<1> Turn off the initialization routine by setting `dbInit` to `false`
20+
<1> Turn off the initialization routine by setting `databaseInitialization.enabled` to `false`
2021

21-
NOTE: The field `dbInit` is `true` by default to be backwards-compatible.
22+
NOTE: The field `databaseInitialization.enabled` is `true` by default to be backwards-compatible.
2223
A fresh Airflow cluster cannot be created with this field set to `false` as this results in missing metadata in the Airflow database.
24+
25+
WARNING: Setting `databaseInitialization.enabled` to `false` is an unsupported operation as subsequent updates to a running Airflow cluster can result in broken behaviour due to inconsistent metadata.
26+
Only set `databaseInitialization.enabled` to `false` if you know what you are doing!

rust/operator-binary/src/crd/mod.rs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ pub mod versioned {
251251
#[serde(default)]
252252
pub load_examples: bool,
253253

254-
/// Whether to execute the database initialization routines (a combination of database initialization, upgrade and migration depending on the Airflow version). Defaults to true to be backwward compatible.
255-
#[serde(default = "default_db_init")]
256-
pub db_init: bool,
254+
/// Whether to execute the database initialization routines (a combination of database initialization, upgrade and migration depending on the Airflow version). Defaults to true to be (techincally) backwards-compatible but also safe.
255+
/// WARNING: setting this to false is *unsupported* as subsequent updates to the Airflow cluster may result in broken behaviour due to inconsistent metadata!
256+
/// Do not change the default unless you know what you are doing!
257+
#[serde(default)]
258+
pub database_initialization: DatabaseInitializationConfig,
257259

258260
/// Name of the Vector aggregator [discovery ConfigMap](DOCS_BASE_URL_PLACEHOLDER/concepts/service_discovery).
259261
/// It must contain the key `ADDRESS` with the address of the Vector aggregator.
@@ -285,7 +287,23 @@ pub mod versioned {
285287
}
286288
}
287289

288-
fn default_db_init() -> bool {
290+
#[derive(Clone, Debug, Deserialize, JsonSchema, PartialEq, Serialize)]
291+
#[serde(rename_all = "camelCase")]
292+
pub struct DatabaseInitializationConfig {
293+
/// Whether to execute the database initialization routines (a combination of database initialization, upgrade and migration depending on the Airflow version). Defaults to true to be backwward compatible.
294+
#[serde(default = "default_db_init")]
295+
pub enabled: bool,
296+
}
297+
298+
impl Default for DatabaseInitializationConfig {
299+
fn default() -> Self {
300+
Self {
301+
enabled: default_db_init(),
302+
}
303+
}
304+
}
305+
306+
pub fn default_db_init() -> bool {
289307
true
290308
}
291309

@@ -585,7 +603,7 @@ impl AirflowRole {
585603
]);
586604
}
587605
AirflowRole::Scheduler => {
588-
if airflow.spec.cluster_config.db_init {
606+
if airflow.spec.cluster_config.database_initialization.enabled {
589607
tracing::info!("Database initialization...");
590608
command.extend(vec![
591609
"airflow db migrate".to_string(),
@@ -626,7 +644,7 @@ impl AirflowRole {
626644
]);
627645
}
628646
AirflowRole::Scheduler => {
629-
if airflow.spec.cluster_config.db_init {
647+
if airflow.spec.cluster_config.database_initialization.enabled {
630648
tracing::info!("Database initialization...");
631649
command.extend(vec![
632650
// Database initialization is limited to the scheduler, see https://github.com/stackabletech/airflow-operator/issues/259
@@ -1008,6 +1026,6 @@ mod tests {
10081026
assert!(cluster.spec.cluster_config.load_examples);
10091027
assert!(cluster.spec.cluster_config.expose_config);
10101028
// defaults to true
1011-
assert!(cluster.spec.cluster_config.db_init);
1029+
assert!(cluster.spec.cluster_config.database_initialization.enabled);
10121030
}
10131031
}

tests/templates/kuttl/cluster-operation/30-restart-airflow.yaml.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ spec:
2525
vectorAggregatorConfigMapName: vector-aggregator-discovery
2626
{% endif %}
2727
credentialsSecret: test-airflow-credentials
28-
dbInit: false
28+
databaseInitialization:
29+
enabled: false
2930
webservers:
3031
roleConfig:
3132
listenerClass: external-unstable

0 commit comments

Comments
 (0)