Skip to content

Commit 21d47c5

Browse files
authored
[reconfigurator] Remove spicy blueprint -> sled-agent From impls (#7505)
This is followup from #7308 and #7500 (comment): * Remove `From<BlueprintZonesConfig> for OmicronZonesConfig`. This included expunged zones, but thankfully had no callers. * Change `BlueprintZonesConfig::to_omicron_zones_config(filter)` to `BlueprintZonesConfig::into_running_omicron_zones_config()` (no `filter` argument). All the callers of this method were passing `BlueprintZoneFilter::ShouldBeRunning`, and I don't think there's a reason to use any other filter? * Remove `From<BlueprintPhysicalDisksConfig> for OmicronPhysicalDisksConfig` (which included expunged disks), and replace it with `BlueprintPhysicalDisksConfig::into_in_service_disks()`. This one _did_ have callers, including the blueprint executor, but I think we've avoided problems because the planner current [drops disks if the incoming planning input says they're not in service](https://github.com/oxidecomputer/omicron/blob/3ae42bf76cb9b55993705b817157e4f60935b6dd/nexus/reconfigurator/planning/src/blueprint_builder/builder.rs#L1090-L1097). I'm not sure that planner behavior is right, and might change with #7286, so it seemed safer to go ahead and fix this now.
1 parent 0c6ab09 commit 21d47c5

File tree

7 files changed

+60
-61
lines changed

7 files changed

+60
-61
lines changed

nexus/reconfigurator/execution/src/clickhouse.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use futures::future::Either;
2222
use futures::stream::FuturesUnordered;
2323
use futures::stream::StreamExt;
2424
use nexus_db_queries::context::OpContext;
25-
use nexus_sled_agent_shared::inventory::OmicronZoneType;
25+
use nexus_types::deployment::Blueprint;
2626
use nexus_types::deployment::BlueprintZoneFilter;
2727
use nexus_types::deployment::BlueprintZonesConfig;
2828
use nexus_types::deployment::ClickhouseClusterConfig;
@@ -182,18 +182,9 @@ pub(crate) async fn deploy_single_node(
182182
opctx: &OpContext,
183183
zones: &BTreeMap<SledUuid, BlueprintZonesConfig>,
184184
) -> Result<(), anyhow::Error> {
185-
if let Some(zone) = zones
186-
.values()
187-
.flat_map(|zones| {
188-
zones
189-
.to_omicron_zones_config(BlueprintZoneFilter::ShouldBeRunning)
190-
.zones
191-
.into_iter()
192-
.find(|zone| {
193-
matches!(zone.zone_type, OmicronZoneType::Clickhouse { .. })
194-
})
195-
})
196-
.next()
185+
if let Some((_, zone)) =
186+
Blueprint::filtered_zones(zones, BlueprintZoneFilter::ShouldBeRunning)
187+
.find(|(_, zone)| zone.zone_type.is_clickhouse())
197188
{
198189
let admin_addr = SocketAddr::V6(SocketAddrV6::new(
199190
zone.underlay_ip(),

nexus/reconfigurator/execution/src/omicron_physical_disks.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ pub(crate) async fn deploy_disks(
4848
&log,
4949
);
5050
let result = client
51-
.omicron_physical_disks_put(&config.clone().into())
51+
.omicron_physical_disks_put(
52+
&config.clone().into_in_service_disks(),
53+
)
5254
.await
5355
.with_context(|| {
5456
format!("Failed to put {config:#?} to sled {sled_id}")

nexus/reconfigurator/execution/src/omicron_zones.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use nexus_db_queries::db::datastore::CollectorReassignment;
1919
use nexus_db_queries::db::DataStore;
2020
use nexus_types::deployment::BlueprintZoneConfig;
2121
use nexus_types::deployment::BlueprintZoneDisposition;
22-
use nexus_types::deployment::BlueprintZoneFilter;
2322
use nexus_types::deployment::BlueprintZoneType;
2423
use nexus_types::deployment::BlueprintZonesConfig;
2524
use omicron_common::address::COCKROACH_ADMIN_PORT;
@@ -65,8 +64,8 @@ pub(crate) async fn deploy_zones(
6564
db_sled.sled_agent_address(),
6665
&opctx.log,
6766
);
68-
let omicron_zones = config
69-
.to_omicron_zones_config(BlueprintZoneFilter::ShouldBeRunning);
67+
let omicron_zones =
68+
config.clone().into_running_omicron_zones_config();
7069
let result = client
7170
.omicron_zones_put(&omicron_zones)
7271
.await

nexus/reconfigurator/planning/src/example.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use crate::system::SledBuilder;
1515
use crate::system::SystemDescription;
1616
use nexus_inventory::CollectionBuilderRng;
1717
use nexus_types::deployment::Blueprint;
18-
use nexus_types::deployment::BlueprintZoneFilter;
1918
use nexus_types::deployment::OmicronZoneNic;
2019
use nexus_types::deployment::PlanningInput;
2120
use nexus_types::deployment::SledFilter;
@@ -490,9 +489,7 @@ impl ExampleSystemBuilder {
490489
system
491490
.sled_set_omicron_zones(
492491
*sled_id,
493-
zones.to_omicron_zones_config(
494-
BlueprintZoneFilter::ShouldBeRunning,
495-
),
492+
zones.clone().into_running_omicron_zones_config(),
496493
)
497494
.unwrap();
498495
}
@@ -546,7 +543,7 @@ impl ZoneCount {
546543
mod tests {
547544
use chrono::{NaiveDateTime, TimeZone, Utc};
548545
use nexus_sled_agent_shared::inventory::{OmicronZoneConfig, ZoneKind};
549-
use nexus_types::deployment::BlueprintZoneConfig;
546+
use nexus_types::deployment::{BlueprintZoneConfig, BlueprintZoneFilter};
550547
use omicron_test_utils::dev::test_setup_log;
551548

552549
use super::*;

nexus/reconfigurator/planning/src/planner.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,8 @@ mod test {
976976
.blueprint_zones
977977
.get(&new_sled_id)
978978
.expect("blueprint should contain zones for new sled")
979-
.to_omicron_zones_config(
980-
BlueprintZoneFilter::ShouldBeRunning,
981-
),
979+
.clone()
980+
.into_running_omicron_zones_config(),
982981
)
983982
.unwrap();
984983
let collection =

nexus/types/src/deployment.rs

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -547,33 +547,30 @@ pub struct BlueprintZonesConfig {
547547
pub zones: IdMap<BlueprintZoneConfig>,
548548
}
549549

550-
impl From<BlueprintZonesConfig> for OmicronZonesConfig {
551-
fn from(config: BlueprintZonesConfig) -> Self {
552-
Self {
553-
generation: config.generation,
554-
zones: config.zones.into_iter().map(From::from).collect(),
555-
}
556-
}
557-
}
558-
559550
impl BlueprintZonesConfig {
560-
/// Converts self to an [`OmicronZonesConfig`], applying the provided
561-
/// [`BlueprintZoneFilter`].
551+
/// Converts self into [`OmicronZonesConfig`].
562552
///
563-
/// The filter controls which zones should be exported into the resulting
564-
/// [`OmicronZonesConfig`].
565-
pub fn to_omicron_zones_config(
566-
&self,
567-
filter: BlueprintZoneFilter,
568-
) -> OmicronZonesConfig {
553+
/// [`OmicronZonesConfig`] is a format of the zones configuration that can
554+
/// be passed to Sled Agents for deployment.
555+
///
556+
/// This function is effectively a `From` implementation, but
557+
/// is named slightly more explicitly, as it filters the blueprint
558+
/// configuration to only consider zones that should be running.
559+
pub fn into_running_omicron_zones_config(self) -> OmicronZonesConfig {
569560
OmicronZonesConfig {
570561
generation: self.generation,
571562
zones: self
572563
.zones
573-
.iter()
574-
.filter(|z| z.disposition.matches(filter))
575-
.cloned()
576-
.map(OmicronZoneConfig::from)
564+
.into_iter()
565+
.filter_map(|z| {
566+
if z.disposition
567+
.matches(BlueprintZoneFilter::ShouldBeRunning)
568+
{
569+
Some(z.into())
570+
} else {
571+
None
572+
}
573+
})
577574
.collect(),
578575
}
579576
}
@@ -899,6 +896,33 @@ pub struct BlueprintPhysicalDisksConfig {
899896
pub disks: IdMap<BlueprintPhysicalDiskConfig>,
900897
}
901898

899+
impl BlueprintPhysicalDisksConfig {
900+
/// Converts self into [`OmicronPhysicalDisksConfig`].
901+
///
902+
/// [`OmicronPhysicalDisksConfig`] is a format of the disks configuration
903+
/// that can be passed to Sled Agents for deployment.
904+
///
905+
/// This function is effectively a `From` implementation, but
906+
/// is named slightly more explicitly, as it filters the blueprint
907+
/// configuration to only consider in-service disks.
908+
pub fn into_in_service_disks(self) -> OmicronPhysicalDisksConfig {
909+
OmicronPhysicalDisksConfig {
910+
generation: self.generation,
911+
disks: self
912+
.disks
913+
.into_iter()
914+
.filter_map(|d| {
915+
if d.disposition.matches(DiskFilter::InService) {
916+
Some(d.into())
917+
} else {
918+
None
919+
}
920+
})
921+
.collect(),
922+
}
923+
}
924+
}
925+
902926
impl IdMappable for BlueprintPhysicalDiskConfig {
903927
type Id = PhysicalDiskUuid;
904928

@@ -927,19 +951,6 @@ impl From<BlueprintPhysicalDiskConfig> for OmicronPhysicalDiskConfig {
927951
}
928952
}
929953

930-
impl From<BlueprintPhysicalDisksConfig> for OmicronPhysicalDisksConfig {
931-
fn from(value: BlueprintPhysicalDisksConfig) -> Self {
932-
OmicronPhysicalDisksConfig {
933-
generation: value.generation,
934-
disks: value
935-
.disks
936-
.into_iter()
937-
.map(OmicronPhysicalDiskConfig::from)
938-
.collect(),
939-
}
940-
}
941-
}
942-
943954
/// Information about Omicron datasets as recorded in a blueprint.
944955
#[derive(
945956
Debug, Clone, Eq, PartialEq, JsonSchema, Deserialize, Serialize, Diffable,
@@ -950,7 +961,7 @@ pub struct BlueprintDatasetsConfig {
950961
}
951962

952963
impl BlueprintDatasetsConfig {
953-
/// Converts [Self] into [DatasetsConfig].
964+
/// Converts self into [DatasetsConfig].
954965
///
955966
/// [DatasetsConfig] is a format of the dataset configuration that can be
956967
/// passed to Sled Agents for deployment.

sled-agent/src/rack_setup/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ impl ServiceInner {
344344
// Ensure all the physical disks are initialized
345345
self.initialize_disks_on_sled(
346346
*sled_address,
347-
config.disks.clone().into(),
347+
config.disks.clone().into_in_service_disks(),
348348
)
349349
.await?;
350350

0 commit comments

Comments
 (0)