Skip to content

Commit c940eec

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 Now, each default can be set or unset and demoted independently. Unsetting the unicast IPv4 default does not affect the multicast IPv4 default, for example. Key changes: - 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 populated by the linking query
1 parent 68a0df3 commit c940eec

File tree

17 files changed

+869
-106
lines changed

17 files changed

+869
-106
lines changed

nexus/db-model/src/ip_pool.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,32 @@ impl std::fmt::Display for IpPoolType {
289289
}
290290
}
291291

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

301320
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(213, 0, 0);
19+
pub const SCHEMA_VERSION: Version = Version::new(214, 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(214, "multiple-default-ip-pools-per-silo"),
3132
KnownVersion::new(213, "multicast-drop-mvlan"),
3233
KnownVersion::new(212, "multicast-member-ip-and-indexes"),
3334
KnownVersion::new(211, "blueprint-sled-config-subnet"),

0 commit comments

Comments
 (0)