Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blueprint planner: add nexus on every sled #4959

Merged
merged 14 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/sled-agent-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition = "2021"
license = "MPL-2.0"

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
chrono.workspace = true
omicron-common.workspace = true
Expand Down
72 changes: 71 additions & 1 deletion clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

//! Interface for making API requests to a Sled Agent

use anyhow::Context;
use async_trait::async_trait;
use std::convert::TryFrom;
use std::net::IpAddr;
use std::net::SocketAddr;
use uuid::Uuid;

progenitor::generate_api!(
Expand Down Expand Up @@ -86,6 +89,74 @@ impl types::OmicronZoneType {
| types::OmicronZoneType::Oximeter { .. } => false,
}
}

/// Identifies whether this is a Nexus zone
pub fn is_nexus(&self) -> bool {
match self {
types::OmicronZoneType::Nexus { .. } => true,

types::OmicronZoneType::BoundaryNtp { .. }
| types::OmicronZoneType::InternalNtp { .. }
| types::OmicronZoneType::Clickhouse { .. }
| types::OmicronZoneType::ClickhouseKeeper { .. }
| types::OmicronZoneType::CockroachDb { .. }
| types::OmicronZoneType::Crucible { .. }
| types::OmicronZoneType::CruciblePantry { .. }
| types::OmicronZoneType::ExternalDns { .. }
| types::OmicronZoneType::InternalDns { .. }
| types::OmicronZoneType::Oximeter { .. } => false,
}
}

/// This zone's external IP
pub fn external_ip(&self) -> anyhow::Result<Option<IpAddr>> {
match self {
types::OmicronZoneType::Nexus { external_ip, .. } => {
Ok(Some(*external_ip))
}

types::OmicronZoneType::ExternalDns { dns_address, .. } => {
let dns_address =
dns_address.parse::<SocketAddr>().with_context(|| {
format!(
"failed to parse ExternalDns address {dns_address}"
)
})?;
Ok(Some(dns_address.ip()))
}

types::OmicronZoneType::BoundaryNtp { snat_cfg, .. } => {
Ok(Some(snat_cfg.ip))
}

types::OmicronZoneType::InternalNtp { .. }
| types::OmicronZoneType::Clickhouse { .. }
| types::OmicronZoneType::ClickhouseKeeper { .. }
| types::OmicronZoneType::CockroachDb { .. }
| types::OmicronZoneType::Crucible { .. }
| types::OmicronZoneType::CruciblePantry { .. }
| types::OmicronZoneType::InternalDns { .. }
| types::OmicronZoneType::Oximeter { .. } => Ok(None),
}
}

/// The service vNIC providing external connectivity to this zone
pub fn service_vnic(&self) -> Option<&types::NetworkInterface> {
match self {
types::OmicronZoneType::Nexus { nic, .. }
| types::OmicronZoneType::ExternalDns { nic, .. }
| types::OmicronZoneType::BoundaryNtp { nic, .. } => Some(nic),

types::OmicronZoneType::InternalNtp { .. }
| types::OmicronZoneType::Clickhouse { .. }
| types::OmicronZoneType::ClickhouseKeeper { .. }
| types::OmicronZoneType::CockroachDb { .. }
| types::OmicronZoneType::Crucible { .. }
| types::OmicronZoneType::CruciblePantry { .. }
| types::OmicronZoneType::InternalDns { .. }
| types::OmicronZoneType::Oximeter { .. } => None,
}
}
}

impl omicron_common::api::external::ClientError for types::Error {
Expand Down Expand Up @@ -351,7 +422,6 @@ impl From<std::net::Ipv6Addr> for types::Ipv6Net {

impl From<std::net::IpAddr> for types::IpNet {
fn from(s: std::net::IpAddr) -> Self {
use std::net::IpAddr;
match s {
IpAddr::V4(v4) => Self::V4(v4.into()),
IpAddr::V6(v6) => Self::V6(v6.into()),
Expand Down
12 changes: 12 additions & 0 deletions common/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,18 @@ impl TryFrom<(Ipv6Addr, Ipv6Addr)> for IpRange {
}
}

impl From<Ipv4Range> for IpRange {
fn from(value: Ipv4Range) -> Self {
Self::V4(value)
}
}

impl From<Ipv6Range> for IpRange {
fn from(value: Ipv6Range) -> Self {
Self::V6(value)
}
}

/// A non-decreasing IPv4 address range, inclusive of both ends.
///
/// The first address must be less than or equal to the last address.
Expand Down
17 changes: 15 additions & 2 deletions nexus/db-queries/src/db/datastore/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,11 @@ mod tests {
use std::mem;
use std::net::Ipv6Addr;

static EMPTY_POLICY: Policy = Policy { sleds: BTreeMap::new() };
static EMPTY_POLICY: Policy = Policy {
sleds: BTreeMap::new(),
service_ip_pool_ranges: Vec::new(),
target_nexus_zone_count: 0,
};

// This is a not-super-future-maintainer-friendly helper to check that all
// the subtables related to blueprints have been pruned of a specific
Expand Down Expand Up @@ -1131,6 +1135,11 @@ mod tests {
)
})
.collect(),
service_ip_pool_ranges: Vec::new(),
target_nexus_zone_count: collection
.all_omicron_zones()
.filter(|z| z.zone_type.is_nexus())
.count(),
}
}

Expand Down Expand Up @@ -1320,7 +1329,8 @@ mod tests {

// Create a builder for a child blueprint.
let mut builder =
BlueprintBuilder::new_based_on(&blueprint1, &policy, "test");
BlueprintBuilder::new_based_on(&blueprint1, &policy, "test")
.expect("failed to create builder");

// Add zones to our new sled.
assert_eq!(
Expand Down Expand Up @@ -1465,9 +1475,11 @@ mod tests {
.unwrap();
let blueprint2 =
BlueprintBuilder::new_based_on(&blueprint1, &EMPTY_POLICY, "test2")
.expect("failed to create builder")
.build();
let blueprint3 =
BlueprintBuilder::new_based_on(&blueprint1, &EMPTY_POLICY, "test3")
.expect("failed to create builder")
.build();
assert_eq!(blueprint1.parent_blueprint_id, None);
assert_eq!(blueprint2.parent_blueprint_id, Some(blueprint1.id));
Expand Down Expand Up @@ -1559,6 +1571,7 @@ mod tests {
// with enabled=false, that status is serialized.
let blueprint4 =
BlueprintBuilder::new_based_on(&blueprint3, &EMPTY_POLICY, "test3")
.expect("failed to create builder")
.build();
assert_eq!(blueprint4.parent_blueprint_id, Some(blueprint3.id));
datastore.blueprint_insert(&opctx, &blueprint4).await.unwrap();
Expand Down
Loading
Loading