Skip to content

Commit 8b06582

Browse files
authored
add config for enabling tuf_repo_pruner task (#9396)
Fixes #9139.
1 parent 1d02ed3 commit 8b06582

File tree

21 files changed

+371
-39
lines changed

21 files changed

+371
-39
lines changed

dev-tools/omdb/src/bin/omdb/nexus/reconfigurator_config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ pub struct ReconfiguratorConfigOpts {
5252

5353
#[clap(long, action = ArgAction::Set)]
5454
add_zones_with_mupdate_override: Option<bool>,
55+
56+
#[clap(long, action = ArgAction::Set)]
57+
tuf_repo_pruner_enabled: Option<bool>,
5558
}
5659

5760
impl ReconfiguratorConfigOpts {
@@ -69,6 +72,9 @@ impl ReconfiguratorConfigOpts {
6972
current.planner_config.add_zones_with_mupdate_override,
7073
),
7174
},
75+
tuf_repo_pruner_enabled: self
76+
.tuf_repo_pruner_enabled
77+
.unwrap_or(current.tuf_repo_pruner_enabled),
7278
}
7379
}
7480

dev-tools/omdb/src/bin/omdb/reconfigurator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ async fn cmd_reconfigurator_config_history(
428428
version: String,
429429
planner_enabled: String,
430430
add_zones_with_mupdate_override: String,
431+
tuf_repo_pruner_enabled: String,
431432
time_modified: String,
432433
}
433434

@@ -441,6 +442,7 @@ async fn cmd_reconfigurator_config_history(
441442
planner_enabled,
442443
planner_config:
443444
PlannerConfig { add_zones_with_mupdate_override },
445+
tuf_repo_pruner_enabled,
444446
},
445447
time_modified,
446448
} = s;
@@ -449,6 +451,7 @@ async fn cmd_reconfigurator_config_history(
449451
planner_enabled: planner_enabled.to_string(),
450452
add_zones_with_mupdate_override:
451453
add_zones_with_mupdate_override.to_string(),
454+
tuf_repo_pruner_enabled: tuf_repo_pruner_enabled.to_string(),
452455
time_modified: time_modified.to_string(),
453456
}
454457
})

dev-tools/omdb/tests/successes.out

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ task: "tuf_repo_pruner"
876876
configured period: every <REDACTED_DURATION>m
877877
last completed activation: <REDACTED ITERATIONS>, triggered by <TRIGGERED_BY_REDACTED>
878878
started at <REDACTED_TIMESTAMP> (<REDACTED DURATION>s ago) and ran for <REDACTED DURATION>ms
879+
status: enabled
879880
configuration:
880881
nkeep_recent_releases: 3
881882
nkeep_recent_uploads: 3
@@ -1437,6 +1438,7 @@ task: "tuf_repo_pruner"
14371438
configured period: every <REDACTED_DURATION>m
14381439
last completed activation: <REDACTED ITERATIONS>, triggered by <TRIGGERED_BY_REDACTED>
14391440
started at <REDACTED_TIMESTAMP> (<REDACTED DURATION>s ago) and ran for <REDACTED DURATION>ms
1441+
status: enabled
14401442
configuration:
14411443
nkeep_recent_releases: 3
14421444
nkeep_recent_uploads: 3
@@ -1816,6 +1818,7 @@ stdout:
18161818
Reconfigurator config:
18171819
version: 1
18181820
modified time: <REDACTED_TIMESTAMP>
1821+
tuf repo pruner enabled: true
18191822
planner enabled: false
18201823
planner config:
18211824
add zones with mupdate override: false
@@ -1896,7 +1899,8 @@ termination: Exited(0)
18961899
---------------------------------------------
18971900
stdout:
18981901
reconfigurator config updated to version 2:
1899-
* planner enabled: false -> true
1902+
tuf repo pruner enabled: true (unchanged)
1903+
* planner enabled::::::::: false -> true
19001904
planner config:
19011905
add zones with mupdate override: false (unchanged)
19021906
---------------------------------------------
@@ -1908,7 +1912,8 @@ termination: Exited(0)
19081912
---------------------------------------------
19091913
stdout:
19101914
reconfigurator config updated to version 3:
1911-
planner enabled: true (unchanged)
1915+
tuf repo pruner enabled: true (unchanged)
1916+
planner enabled::::::::: true (unchanged)
19121917
planner config:
19131918
* add zones with mupdate override: false -> true
19141919
---------------------------------------------
@@ -1922,6 +1927,7 @@ stdout:
19221927
Reconfigurator config:
19231928
version: 3
19241929
modified time: <REDACTED_TIMESTAMP>
1930+
tuf repo pruner enabled: true
19251931
planner enabled: true
19261932
planner config:
19271933
add zones with mupdate override: true

nexus-config/src/nexus_config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,7 @@ mod test {
11541154
[initial_reconfigurator_config]
11551155
planner_enabled = true
11561156
planner_config.add_zones_with_mupdate_override = true
1157+
tuf_repo_pruner_enabled = false
11571158
[background_tasks]
11581159
dns_internal.period_secs_config = 1
11591160
dns_internal.period_secs_servers = 2
@@ -1314,6 +1315,7 @@ mod test {
13141315
planner_config: PlannerConfig {
13151316
add_zones_with_mupdate_override: true,
13161317
},
1318+
tuf_repo_pruner_enabled: false,
13171319
}),
13181320
background_tasks: BackgroundTaskConfig {
13191321
dns_internal: DnsTasksConfig {

nexus/db-model/src/reconfigurator_config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct ReconfiguratorConfig {
1616
pub planner_enabled: bool,
1717
pub time_modified: DateTime<Utc>,
1818
pub add_zones_with_mupdate_override: bool,
19+
pub tuf_repo_pruner_enabled: bool,
1920
}
2021

2122
impl From<deployment::ReconfiguratorConfigView> for ReconfiguratorConfig {
@@ -28,6 +29,7 @@ impl From<deployment::ReconfiguratorConfigView> for ReconfiguratorConfig {
2829
.config
2930
.planner_config
3031
.add_zones_with_mupdate_override,
32+
tuf_repo_pruner_enabled: value.config.tuf_repo_pruner_enabled,
3133
}
3234
}
3335
}
@@ -42,6 +44,7 @@ impl From<ReconfiguratorConfig> for deployment::ReconfiguratorConfigView {
4244
add_zones_with_mupdate_override: value
4345
.add_zones_with_mupdate_override,
4446
},
47+
tuf_repo_pruner_enabled: value.tuf_repo_pruner_enabled,
4548
},
4649
time_modified: value.time_modified,
4750
}

nexus/db-model/src/schema_versions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{collections::BTreeMap, sync::LazyLock};
1616
///
1717
/// This must be updated when you change the database schema. Refer to
1818
/// schema/crdb/README.adoc in the root of this repository for details.
19-
pub const SCHEMA_VERSION: Version = Version::new(207, 0, 0);
19+
pub const SCHEMA_VERSION: Version = Version::new(208, 0, 0);
2020

2121
/// List of all past database schema versions, in *reverse* order
2222
///
@@ -28,6 +28,7 @@ static KNOWN_VERSIONS: LazyLock<Vec<KnownVersion>> = LazyLock::new(|| {
2828
// | leaving the first copy as an example for the next person.
2929
// v
3030
// KnownVersion::new(next_int, "unique-dirname-with-the-sql-files"),
31+
KnownVersion::new(208, "disable-tuf-repo-pruner"),
3132
KnownVersion::new(207, "disk-types"),
3233
KnownVersion::new(206, "fm-sitreps-by-parent-id-index"),
3334
KnownVersion::new(205, "fm-sitrep"),

nexus/db-queries/src/db/datastore/reconfigurator_config.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use nexus_db_errors::public_error_from_diesel;
2020
use nexus_db_lookup::DbConnection;
2121
use nexus_db_model::ReconfiguratorConfig as DbReconfiguratorConfig;
2222
use nexus_db_model::SqlU32;
23+
use nexus_types::deployment::PlannerConfig;
24+
use nexus_types::deployment::ReconfiguratorConfig;
2325
use nexus_types::deployment::ReconfiguratorConfigParam;
2426
use nexus_types::deployment::ReconfiguratorConfigView;
2527
use omicron_common::api::external::DataPageParams;
@@ -142,22 +144,38 @@ impl DataStore {
142144
));
143145
}
144146

147+
// This statement exists just to trigger compilation errors when the
148+
// `ReconfiguratorConfigView` type changes so that people are prompted
149+
// to fix this query. If you get a compiler error here, you probably
150+
// added or removed a field to this type, and you will need to adjust
151+
// the query below accordingly.
152+
let ReconfiguratorConfigView {
153+
version,
154+
config:
155+
ReconfiguratorConfig {
156+
planner_enabled,
157+
planner_config:
158+
PlannerConfig { add_zones_with_mupdate_override },
159+
tuf_repo_pruner_enabled,
160+
},
161+
time_modified,
162+
} = *switches;
163+
145164
sql_query(
146165
r"INSERT INTO reconfigurator_config
147166
(version, planner_enabled, time_modified,
148-
add_zones_with_mupdate_override)
149-
SELECT $1, $2, $3, $4
167+
add_zones_with_mupdate_override, tuf_repo_pruner_enabled)
168+
SELECT $1, $2, $3, $4, $5
150169
WHERE $1 - 1 IN (
151170
SELECT COALESCE(MAX(version), 0)
152171
FROM reconfigurator_config
153172
)",
154173
)
155-
.bind::<sql_types::BigInt, SqlU32>(switches.version.into())
156-
.bind::<sql_types::Bool, _>(switches.config.planner_enabled)
157-
.bind::<sql_types::Timestamptz, _>(switches.time_modified)
158-
.bind::<sql_types::Bool, _>(
159-
switches.config.planner_config.add_zones_with_mupdate_override,
160-
)
174+
.bind::<sql_types::BigInt, SqlU32>(version.into())
175+
.bind::<sql_types::Bool, _>(planner_enabled)
176+
.bind::<sql_types::Timestamptz, _>(time_modified)
177+
.bind::<sql_types::Bool, _>(add_zones_with_mupdate_override)
178+
.bind::<sql_types::Bool, _>(tuf_repo_pruner_enabled)
161179
.execute_async(conn)
162180
.await
163181
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))
@@ -186,12 +204,13 @@ mod tests {
186204
.is_empty()
187205
);
188206

189-
// Fail to insert a swtiches with version 0
207+
// Fail to insert version 0
190208
let mut switches = ReconfiguratorConfigParam {
191209
version: 0,
192210
config: ReconfiguratorConfig {
193211
planner_enabled: false,
194212
planner_config: PlannerConfig::default(),
213+
tuf_repo_pruner_enabled: true,
195214
},
196215
};
197216

nexus/db-schema/src/schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,6 +1967,7 @@ table! {
19671967
planner_enabled -> Bool,
19681968
time_modified -> Timestamptz,
19691969
add_zones_with_mupdate_override -> Bool,
1970+
tuf_repo_pruner_enabled -> Bool,
19701971
}
19711972
}
19721973

nexus/src/app/background/init.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl BackgroundTasksInitializer {
568568
watchers: vec![
569569
Box::new(inventory_load_watcher.clone()),
570570
Box::new(rx_blueprint.clone()),
571-
Box::new(reconfigurator_config_watcher),
571+
Box::new(reconfigurator_config_watcher.clone()),
572572
],
573573
activator: task_blueprint_planner,
574574
});
@@ -981,9 +981,10 @@ impl BackgroundTasksInitializer {
981981
task_impl: Box::new(tuf_repo_pruner::TufRepoPruner::new(
982982
datastore.clone(),
983983
config.tuf_repo_pruner.clone(),
984+
reconfigurator_config_watcher.clone(),
984985
)),
985986
opctx: opctx.child(BTreeMap::new()),
986-
watchers: vec![],
987+
watchers: vec![Box::new(reconfigurator_config_watcher)],
987988
activator: task_tuf_repo_pruner,
988989
});
989990

nexus/src/app/background/tasks/blueprint_planner.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,7 @@ mod test {
429429
use nexus_test_utils::db::TestDatabase;
430430
use nexus_test_utils_macros::nexus_test;
431431
use nexus_types::deployment::{
432-
PendingMgsUpdates, PlannerConfig, ReconfiguratorConfig,
433-
ReconfiguratorConfigView,
432+
PendingMgsUpdates, ReconfiguratorConfig, ReconfiguratorConfigView,
434433
};
435434
use omicron_test_utils::dev;
436435
use omicron_uuid_kinds::OmicronZoneUuid;
@@ -488,7 +487,7 @@ mod test {
488487
version: 1,
489488
config: ReconfiguratorConfig {
490489
planner_enabled: true,
491-
planner_config: PlannerConfig::default(),
490+
..ReconfiguratorConfig::default()
492491
},
493492
time_modified: now_db_precision(),
494493
}),
@@ -660,7 +659,7 @@ mod test {
660659
version: 1,
661660
config: ReconfiguratorConfig {
662661
planner_enabled: true,
663-
planner_config: PlannerConfig::default(),
662+
..ReconfiguratorConfig::default()
664663
},
665664
time_modified: now_db_precision(),
666665
}),

0 commit comments

Comments
 (0)