Skip to content

Commit d71ca1c

Browse files
[ip-pools] Allow multiple default IP pools per silo
Previously, each silo could only have one default IP pool. This change allows one default pool per (pool_type, ip_version) combination, enabling silos to have separate defaults for: - Unicast IPv4 - Unicast IPv6 - Multicast IPv4 - Multicast IPv6 This work previously branched off #9451, but now off `main`, involving changes that have to do with the mcast lifecycle changes. Includes: - Each default can now be set or unset and demoted independently. Unsetting the unicast IPv4 default does not affect the multicast IPv4 default, for example. - Add `pool_type` and `ip_version` columns to `ip_pool_resource` (denormalized from parent `ip_pool` for unique index) - Replace unique index with partial index on (resource_id, pool_type, ip_version) WHERE is_default = true - Rename `IpPoolResourceLink` to `IncompleteIpPoolResource` to reflect that pool_type/ip_version are actually populated by the linking query - Add `ip_version` field to API params for default pool disambiguation - API versioning for backwards compatibility with older clients
1 parent e00aaba commit d71ca1c

File tree

37 files changed

+32552
-420
lines changed

37 files changed

+32552
-420
lines changed

end-to-end-tests/src/instance_launch.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ async fn instance_launch() -> Result<()> {
7171
}),
7272
disks: Vec::new(),
7373
network_interfaces: InstanceNetworkInterfaceAttachment::Default,
74-
external_ips: vec![ExternalIpCreate::Ephemeral { pool: None }],
74+
external_ips: vec![ExternalIpCreate::Ephemeral {
75+
pool: None,
76+
ip_version: None,
77+
}],
7578
user_data: String::new(),
7679
ssh_public_keys: Some(vec![oxide_client::types::NameOrId::Name(
7780
ssh_key_name.clone(),

nexus/db-model/src/ip_pool.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ impl_enum_type!(
9191
serde::Deserialize,
9292
Eq,
9393
FromSqlRow,
94+
Hash,
9495
schemars::JsonSchema,
9596
PartialEq,
9697
serde::Serialize,
@@ -289,13 +290,32 @@ impl std::fmt::Display for IpPoolType {
289290
}
290291
}
291292

293+
/// IP pool resource type.
294+
///
295+
/// `pool_type` and `ip_version` are denormalized from [IpPool]
296+
/// for a unique index on defaults.
292297
#[derive(Queryable, Insertable, Selectable, Clone, Copy, Debug, PartialEq)]
293298
#[diesel(table_name = ip_pool_resource)]
294299
pub struct IpPoolResource {
295300
pub ip_pool_id: Uuid,
296301
pub resource_type: IpPoolResourceType,
297302
pub resource_id: Uuid,
298303
pub is_default: bool,
304+
pub pool_type: IpPoolType,
305+
pub ip_version: IpVersion,
306+
}
307+
308+
/// Input for creating an IP pool resource.
309+
///
310+
/// The `pool_type` and `ip_version` fields are populated from [IpPool]
311+
/// by the `link_ip_pool_to_external_silo_query` query, so they are not needed
312+
/// as input.
313+
#[derive(Clone, Copy, Debug)]
314+
pub struct IncompleteIpPoolResource {
315+
pub ip_pool_id: Uuid,
316+
pub resource_type: IpPoolResourceType,
317+
pub resource_id: Uuid,
318+
pub is_default: bool,
299319
}
300320

301321
impl From<IpPoolResource> for views::IpPoolSiloLink {

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(215, 0, 0);
19+
pub const SCHEMA_VERSION: Version = Version::new(216, 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(216, "multiple-default-ip-pools-per-silo"),
3132
KnownVersion::new(215, "support-up-to-12-disks"),
3233
KnownVersion::new(214, "separate-transit-ips-by-version"),
3334
KnownVersion::new(213, "fm-cases"),

0 commit comments

Comments
 (0)