Skip to content

Unrolling saga actions for external IPs and NICs #1474

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

Merged
merged 2 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
42 changes: 39 additions & 3 deletions nexus/src/app/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
//! Virtual Machine Instances

use super::MAX_DISKS_PER_INSTANCE;
use super::MAX_EXTERNAL_IPS_PER_INSTANCE;
use super::MAX_NICS_PER_INSTANCE;
use crate::app::sagas;
use crate::authn;
use crate::authz;
Expand Down Expand Up @@ -59,6 +61,37 @@ impl super::Nexus {
MAX_DISKS_PER_INSTANCE
)));
}
if params.external_ips.len() > MAX_EXTERNAL_IPS_PER_INSTANCE {
return Err(Error::invalid_request(&format!(
"An instance may not have more than {} external IP addresses",
MAX_EXTERNAL_IPS_PER_INSTANCE,
)));
}
if let params::InstanceNetworkInterfaceAttachment::Create(ref ifaces) =
params.network_interfaces
{
if ifaces.len() > MAX_NICS_PER_INSTANCE {
return Err(Error::invalid_request(&format!(
"An instance may not have more than {} network interfaces",
MAX_NICS_PER_INSTANCE,
)));
}
// Check that all VPC names are the same.
//
// This isn't strictly necessary, as the queries to create these
// interfaces would fail in the saga, but it's easier to handle here.
if ifaces
.iter()
.map(|iface| &iface.vpc_name)
.collect::<std::collections::BTreeSet<_>>()
.len()
!= 1
{
return Err(Error::invalid_request(
"All interfaces must be in the same VPC",
));
}
}

// Reject instances where the memory is not at least
// MIN_MEMORY_SIZE_BYTES
Expand Down Expand Up @@ -217,6 +250,9 @@ impl super::Nexus {
self.db_datastore
.project_delete_instance(opctx, &authz_instance)
.await?;
self.db_datastore
.instance_delete_all_network_interfaces(opctx, &authz_instance)
.await?;
// Ignore the count of addresses deleted
self.db_datastore
.deallocate_instance_external_ip_by_instance_id(
Expand Down Expand Up @@ -502,12 +538,12 @@ impl super::Nexus {
.partition(|ip| ip.kind == IpKind::SNat);

// Sanity checks on the number and kind of each IP address.
if external_ips.len() > crate::app::MAX_EPHEMERAL_IPS_PER_INSTANCE {
if external_ips.len() > MAX_EXTERNAL_IPS_PER_INSTANCE {
return Err(Error::internal_error(
format!(
"Expected the number of external IPs to be limited to \
{}, but found {}",
crate::app::MAX_EPHEMERAL_IPS_PER_INSTANCE,
{}, but found {}",
MAX_EXTERNAL_IPS_PER_INSTANCE,
external_ips.len(),
)
.as_str(),
Expand Down
6 changes: 3 additions & 3 deletions nexus/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ mod sagas;

pub(crate) const MAX_DISKS_PER_INSTANCE: u32 = 8;

pub(crate) const MAX_NICS_PER_INSTANCE: u32 = 8;
pub(crate) const MAX_NICS_PER_INSTANCE: usize = 8;

// TODO-completness: Support multiple Ephemeral IPs
pub(crate) const MAX_EPHEMERAL_IPS_PER_INSTANCE: usize = 1;
// TODO-completness: Support multiple external IPs
pub(crate) const MAX_EXTERNAL_IPS_PER_INSTANCE: usize = 1;

/// Manages an Oxide fleet -- the heart of the control plane
pub struct Nexus {
Expand Down
Loading