Skip to content

Commit

Permalink
Put BlueprintZoneConfig into a map
Browse files Browse the repository at this point in the history
This is a largely mechanical change to store zones in a Blueprint mapped
by their zone uuid rather than in a Vec. This is primarily to support
diffs of `BlueprintZonesConfig` via diffus. Diffus doesn't handle Vecs
in a manner where inserts, removals, and modifications are tracked based
on an id.

To minimize the PR diff, the zone id was not removed from
`BlueprintZoneConfig`. The key to the map must always match the value
in `BlueprintZoneConfig`. It's a shame a mismatch is now representable,
and we can go about trying to change that if necessary. We can also
just make it part of blippy for now. FWIW, this matches the pattern in
`BlueprintDatasetsConfig`.

Putting the `BlueprintZoneConfig` into a map means we no longer require
the sort method on `BlueprintZonesConfig` as the order is stable
now. However, we still want to ensure the same display sort order as
previously, so we make sure to sort things properly before creating
the table.

We'll want similar changes for `BlueprintPhysicalDisksConfig`. That can
come in a follow up PR.
  • Loading branch information
andrewjstone committed Jan 7, 2025
1 parent 0afbd6e commit e033cd2
Show file tree
Hide file tree
Showing 19 changed files with 655 additions and 547 deletions.
88 changes: 44 additions & 44 deletions nexus/db-queries/src/db/datastore/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl DataStore {
.blueprint_zones
.iter()
.flat_map(|(sled_id, zones_config)| {
zones_config.zones.iter().map(move |zone| {
zones_config.zones.values().map(move |zone| {
BpOmicronZone::new(blueprint_id, *sled_id, zone)
.map_err(|e| Error::internal_error(&format!("{:#}", e)))
})
Expand All @@ -276,7 +276,7 @@ impl DataStore {
.blueprint_zones
.values()
.flat_map(|zones_config| {
zones_config.zones.iter().filter_map(|zone| {
zones_config.zones.values().filter_map(|zone| {
BpOmicronZoneNic::new(blueprint_id, zone)
.with_context(|| format!("zone {}", zone.id))
.map_err(|e| Error::internal_error(&format!("{:#}", e)))
Expand Down Expand Up @@ -587,7 +587,7 @@ impl DataStore {
s.sled_id.into(),
BlueprintZonesConfig {
generation: *s.generation,
zones: Vec::new(),
zones: BTreeMap::new(),
},
);
bail_unless!(
Expand Down Expand Up @@ -794,16 +794,11 @@ impl DataStore {
e.to_string()
))
})?;
sled_zones.zones.push(zone);
sled_zones.zones.insert(zone.id, zone);
}
}
}

// Sort all zones to match what blueprint builders do.
for (_, zones_config) in blueprint_zones.iter_mut() {
zones_config.sort();
}

bail_unless!(
omicron_zone_nics.is_empty(),
"found extra Omicron zone NICs: {:?}",
Expand Down Expand Up @@ -2807,43 +2802,48 @@ mod tests {
sled_id,
BlueprintZonesConfig {
generation: omicron_common::api::external::Generation::new(),
zones: vec![BlueprintZoneConfig {
disposition: BlueprintZoneDisposition::InService,
id: zone_id,
filesystem_pool: None,
zone_type: BlueprintZoneType::Nexus(
blueprint_zone_type::Nexus {
internal_address: SocketAddrV6::new(
Ipv6Addr::LOCALHOST,
0,
0,
0,
),
external_ip: OmicronZoneExternalFloatingIp {
id: ExternalIpUuid::new_v4(),
ip: "10.0.0.1".parse().unwrap(),
},
nic: NetworkInterface {
id: Uuid::new_v4(),
kind: NetworkInterfaceKind::Service {
id: *zone_id.as_untyped_uuid(),
},
name: Name::from_str("mynic").unwrap(),
ip: "fd77:e9d2:9cd9:2::8".parse().unwrap(),
mac: MacAddr::random_system(),
subnet: IpNet::host_net(IpAddr::V6(
zones: [(
zone_id,
BlueprintZoneConfig {
disposition: BlueprintZoneDisposition::InService,
id: zone_id,
filesystem_pool: None,
zone_type: BlueprintZoneType::Nexus(
blueprint_zone_type::Nexus {
internal_address: SocketAddrV6::new(
Ipv6Addr::LOCALHOST,
)),
vni: Vni::random(),
primary: true,
slot: 1,
transit_ips: vec![],
0,
0,
0,
),
external_ip: OmicronZoneExternalFloatingIp {
id: ExternalIpUuid::new_v4(),
ip: "10.0.0.1".parse().unwrap(),
},
nic: NetworkInterface {
id: Uuid::new_v4(),
kind: NetworkInterfaceKind::Service {
id: *zone_id.as_untyped_uuid(),
},
name: Name::from_str("mynic").unwrap(),
ip: "fd77:e9d2:9cd9:2::8".parse().unwrap(),
mac: MacAddr::random_system(),
subnet: IpNet::host_net(IpAddr::V6(
Ipv6Addr::LOCALHOST,
)),
vni: Vni::random(),
primary: true,
slot: 1,
transit_ips: vec![],
},
external_tls: false,
external_dns_servers: vec![],
},
external_tls: false,
external_dns_servers: vec![],
},
),
}],
),
},
)]
.into_iter()
.collect(),
},
);

Expand Down
Loading

0 comments on commit e033cd2

Please sign in to comment.