Skip to content

Commit ca9abfd

Browse files
authored
OmicronSledConfig: Just one Generation (#8067)
This is somewhat extracted from #8064, but can be landed independently and will make some of the followup sled-agent-config-reconciler PRs a little cleaner. We don't yet ledger `OmicronSledConfig`s to disk, so we're free to fiddle with the details of its fields without worrying about backwards compatibility. Fixes #7774.
1 parent 8116ce7 commit ca9abfd

File tree

18 files changed

+260
-154
lines changed

18 files changed

+260
-154
lines changed

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dropshot.workspace = true
2525
futures.workspace = true
2626
hex.workspace = true
2727
http.workspace = true
28+
id-map.workspace = true
2829
ipnetwork.workspace = true
2930
lldp_protocol.workspace = true
3031
macaddr.workspace = true

common/src/disk.rs

+17
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use anyhow::bail;
88
use camino::{Utf8Path, Utf8PathBuf};
99
use daft::Diffable;
10+
use id_map::IdMappable;
1011
use omicron_uuid_kinds::DatasetUuid;
1112
use omicron_uuid_kinds::PhysicalDiskUuid;
1213
use omicron_uuid_kinds::ZpoolUuid;
@@ -42,6 +43,14 @@ pub struct OmicronPhysicalDiskConfig {
4243
pub pool_id: ZpoolUuid,
4344
}
4445

46+
impl IdMappable for OmicronPhysicalDiskConfig {
47+
type Id = PhysicalDiskUuid;
48+
49+
fn id(&self) -> Self::Id {
50+
self.id
51+
}
52+
}
53+
4554
#[derive(
4655
Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq, Eq, Hash,
4756
)]
@@ -337,6 +346,14 @@ pub struct DatasetConfig {
337346
pub inner: SharedDatasetConfig,
338347
}
339348

349+
impl IdMappable for DatasetConfig {
350+
type Id = DatasetUuid;
351+
352+
fn id(&self) -> Self::Id {
353+
self.id
354+
}
355+
}
356+
340357
#[derive(
341358
Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq, Eq, Hash,
342359
)]

nexus-sled-agent-shared/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ workspace = true
88

99
[dependencies]
1010
daft.workspace = true
11+
id-map.workspace = true
1112
illumos-utils.workspace = true
1213
omicron-common.workspace = true
1314
omicron-passwords.workspace = true

nexus-sled-agent-shared/src/inventory.rs

+17-8
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
use std::net::{IpAddr, Ipv6Addr, SocketAddr, SocketAddrV6};
88

99
use daft::Diffable;
10+
use id_map::IdMap;
11+
use id_map::IdMappable;
1012
use omicron_common::{
1113
api::{
1214
external::{ByteCount, Generation},
1315
internal::shared::{NetworkInterface, SourceNatConfig},
1416
},
1517
disk::{
16-
DatasetManagementStatus, DatasetsConfig, DiskManagementStatus,
17-
DiskVariant, OmicronPhysicalDisksConfig,
18+
DatasetConfig, DatasetManagementStatus, DiskManagementStatus,
19+
DiskVariant, OmicronPhysicalDiskConfig,
1820
},
1921
zpool_name::ZpoolName,
2022
};
@@ -130,13 +132,12 @@ pub enum SledRole {
130132
/// Describes the set of Reconfigurator-managed configuration elements of a sled
131133
// TODO this struct should have a generation number; at the moment, each of
132134
// the fields has a separete one internally.
133-
#[derive(
134-
Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq, Eq, Hash,
135-
)]
135+
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema, PartialEq, Eq)]
136136
pub struct OmicronSledConfig {
137-
pub disks_config: OmicronPhysicalDisksConfig,
138-
pub datasets_config: DatasetsConfig,
139-
pub zones_config: OmicronZonesConfig,
137+
pub generation: Generation,
138+
pub disks: IdMap<OmicronPhysicalDiskConfig>,
139+
pub datasets: IdMap<DatasetConfig>,
140+
pub zones: IdMap<OmicronZoneConfig>,
140141
}
141142

142143
/// Result of the currently-synchronous `omicron_config_put` endpoint.
@@ -190,6 +191,14 @@ pub struct OmicronZoneConfig {
190191
pub image_source: OmicronZoneImageSource,
191192
}
192193

194+
impl IdMappable for OmicronZoneConfig {
195+
type Id = OmicronZoneUuid;
196+
197+
fn id(&self) -> Self::Id {
198+
self.id
199+
}
200+
}
201+
193202
impl OmicronZoneConfig {
194203
/// Returns the underlay IP address associated with this zone.
195204
///

nexus/inventory/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ clickhouse-admin-types.workspace = true
1717
futures.workspace = true
1818
gateway-client.workspace = true
1919
gateway-messages.workspace = true
20+
id-map.workspace = true
2021
nexus-sled-agent-shared.workspace = true
2122
nexus-types.workspace = true
2223
omicron-common.workspace = true

nexus/inventory/src/collector.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,13 @@ mod test {
408408
use super::Collector;
409409
use crate::StaticSledAgentEnumerator;
410410
use gateway_messages::SpPort;
411+
use id_map::IdMap;
411412
use nexus_sled_agent_shared::inventory::OmicronSledConfig;
412413
use nexus_sled_agent_shared::inventory::OmicronZoneConfig;
413414
use nexus_sled_agent_shared::inventory::OmicronZoneImageSource;
414415
use nexus_sled_agent_shared::inventory::OmicronZoneType;
415-
use nexus_sled_agent_shared::inventory::OmicronZonesConfig;
416416
use nexus_types::inventory::Collection;
417417
use omicron_common::api::external::Generation;
418-
use omicron_common::disk::DatasetsConfig;
419-
use omicron_common::disk::OmicronPhysicalDisksConfig;
420418
use omicron_common::zpool_name::ZpoolName;
421419
use omicron_sled_agent::sim;
422420
use omicron_uuid_kinds::OmicronZoneUuid;
@@ -595,19 +593,19 @@ mod test {
595593
let zone_address = SocketAddrV6::new(Ipv6Addr::LOCALHOST, 123, 0, 0);
596594
client
597595
.omicron_config_put(&OmicronSledConfig {
598-
disks_config: OmicronPhysicalDisksConfig::default(),
599-
datasets_config: DatasetsConfig::default(),
600-
zones_config: OmicronZonesConfig {
601-
generation: Generation::from(3),
602-
zones: vec![OmicronZoneConfig {
603-
id: zone_id,
604-
zone_type: OmicronZoneType::Oximeter {
605-
address: zone_address,
606-
},
607-
filesystem_pool: Some(filesystem_pool),
608-
image_source: OmicronZoneImageSource::InstallDataset,
609-
}],
610-
},
596+
generation: Generation::from(3),
597+
disks: IdMap::default(),
598+
datasets: IdMap::default(),
599+
zones: [OmicronZoneConfig {
600+
id: zone_id,
601+
zone_type: OmicronZoneType::Oximeter {
602+
address: zone_address,
603+
},
604+
filesystem_pool: Some(filesystem_pool),
605+
image_source: OmicronZoneImageSource::InstallDataset,
606+
}]
607+
.into_iter()
608+
.collect(),
611609
})
612610
.await
613611
.expect("failed to write initial zone version to fake sled agent");

nexus/reconfigurator/execution/src/omicron_sled_config.rs

+31-4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ fn parse_config_result(
145145
mod tests {
146146
use super::*;
147147
use id_map::IdMap;
148+
use nexus_sled_agent_shared::inventory::OmicronZonesConfig;
148149
use nexus_sled_agent_shared::inventory::SledRole;
149150
use nexus_test_utils_macros::nexus_test;
150151
use nexus_types::deployment::BlueprintDatasetConfig;
@@ -163,7 +164,9 @@ mod tests {
163164
use omicron_common::api::external::Generation;
164165
use omicron_common::api::internal::shared::DatasetKind;
165166
use omicron_common::disk::CompressionAlgorithm;
167+
use omicron_common::disk::DatasetsConfig;
166168
use omicron_common::disk::DiskIdentity;
169+
use omicron_common::disk::OmicronPhysicalDisksConfig;
167170
use omicron_common::zpool_name::ZpoolName;
168171
use omicron_uuid_kinds::DatasetUuid;
169172
use omicron_uuid_kinds::OmicronZoneUuid;
@@ -189,6 +192,8 @@ mod tests {
189192
_ => panic!("Unexpected address type for sled agent (wanted IPv6)"),
190193
};
191194
let sim_sled_agent = &cptestctx.sled_agents[0].sled_agent();
195+
let sim_sled_agent_config_generation =
196+
sim_sled_agent.omicron_zones_list().generation;
192197

193198
let sleds_by_id = BTreeMap::from([(
194199
sim_sled_agent.id,
@@ -306,7 +311,7 @@ mod tests {
306311

307312
let sled_config = BlueprintSledConfig {
308313
state: SledState::Active,
309-
sled_agent_generation: Generation::new().next(),
314+
sled_agent_generation: sim_sled_agent_config_generation.next(),
310315
disks,
311316
datasets,
312317
zones,
@@ -328,9 +333,31 @@ mod tests {
328333

329334
let in_service_config =
330335
sled_config.clone().into_in_service_sled_config();
331-
assert_eq!(observed_disks, in_service_config.disks_config);
332-
assert_eq!(observed_datasets, in_service_config.datasets_config);
333-
assert_eq!(observed_zones, in_service_config.zones_config);
336+
assert_eq!(
337+
observed_disks,
338+
OmicronPhysicalDisksConfig {
339+
generation: in_service_config.generation,
340+
disks: in_service_config.disks.into_iter().collect(),
341+
}
342+
);
343+
assert_eq!(
344+
observed_datasets,
345+
DatasetsConfig {
346+
generation: in_service_config.generation,
347+
datasets: in_service_config
348+
.datasets
349+
.into_iter()
350+
.map(|d| (d.id, d))
351+
.collect(),
352+
}
353+
);
354+
assert_eq!(
355+
observed_zones,
356+
OmicronZonesConfig {
357+
generation: in_service_config.generation,
358+
zones: in_service_config.zones.into_iter().collect(),
359+
}
360+
);
334361

335362
// We expect to see each single in-service item we supplied as input.
336363
assert_eq!(observed_disks.disks.len(), 1);

nexus/reconfigurator/planning/src/example.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::planner::rng::PlannerRng;
1414
use crate::system::SledBuilder;
1515
use crate::system::SystemDescription;
1616
use nexus_inventory::CollectionBuilderRng;
17+
use nexus_sled_agent_shared::inventory::OmicronZonesConfig;
1718
use nexus_types::deployment::Blueprint;
1819
use nexus_types::deployment::OmicronZoneNic;
1920
use nexus_types::deployment::PlanningInput;
@@ -484,10 +485,14 @@ impl ExampleSystemBuilder {
484485
}
485486

486487
for (sled_id, sled_cfg) in &blueprint.sleds {
488+
let sled_cfg = sled_cfg.clone().into_in_service_sled_config();
487489
system
488490
.sled_set_omicron_zones(
489491
*sled_id,
490-
sled_cfg.clone().into_in_service_sled_config().zones_config,
492+
OmicronZonesConfig {
493+
generation: sled_cfg.generation,
494+
zones: sled_cfg.zones.into_iter().collect(),
495+
},
491496
)
492497
.unwrap();
493498
}

nexus/reconfigurator/planning/src/planner.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ pub(crate) mod test {
996996
use clickhouse_admin_types::ClickhouseKeeperClusterMembership;
997997
use clickhouse_admin_types::KeeperId;
998998
use expectorate::assert_contents;
999+
use nexus_sled_agent_shared::inventory::OmicronZonesConfig;
9991000
use nexus_types::deployment::BlueprintDatasetDisposition;
10001001
use nexus_types::deployment::BlueprintDiffSummary;
10011002
use nexus_types::deployment::BlueprintPhysicalDiskDisposition;
@@ -1180,16 +1181,18 @@ pub(crate) mod test {
11801181
// example.collection -- this should be addressed via API improvements.
11811182
example
11821183
.system
1183-
.sled_set_omicron_zones(
1184-
new_sled_id,
1185-
blueprint4
1184+
.sled_set_omicron_zones(new_sled_id, {
1185+
let sled_cfg = blueprint4
11861186
.sleds
11871187
.get(&new_sled_id)
11881188
.expect("blueprint should contain zones for new sled")
11891189
.clone()
1190-
.into_in_service_sled_config()
1191-
.zones_config,
1192-
)
1190+
.into_in_service_sled_config();
1191+
OmicronZonesConfig {
1192+
generation: sled_cfg.generation,
1193+
zones: sled_cfg.zones.into_iter().collect(),
1194+
}
1195+
})
11931196
.unwrap();
11941197
let collection =
11951198
example.system.to_collection_builder().unwrap().build();

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,6 @@ mod test {
949949
use nexus_test_utils::SLED_AGENT_UUID;
950950
use nexus_test_utils_macros::nexus_test;
951951
use omicron_common::api::external::ByteCount;
952-
use omicron_common::api::external::Generation;
953952
use omicron_common::api::internal::shared::DatasetKind;
954953
use omicron_common::disk::DatasetConfig;
955954
use omicron_common::disk::DatasetName;
@@ -1155,8 +1154,15 @@ mod test {
11551154
)
11561155
})
11571156
.collect();
1157+
1158+
// Read current sled config generation from zones (this will change
1159+
// slightly once the simulator knows how to keep the unified config
1160+
// and be a little less weird)
1161+
let current_generation =
1162+
cptestctx.first_sled_agent().omicron_zones_list().generation;
1163+
11581164
let dataset_config = DatasetsConfig {
1159-
generation: Generation::new().next(),
1165+
generation: current_generation.next(),
11601166
datasets,
11611167
};
11621168

0 commit comments

Comments
 (0)