Skip to content

Commit

Permalink
probes as sled-agent rpw
Browse files Browse the repository at this point in the history
  • Loading branch information
rcgoodfellow committed Dec 11, 2023
1 parent 3e9782a commit 81d8ee9
Show file tree
Hide file tree
Showing 47 changed files with 1,019 additions and 464 deletions.
7 changes: 3 additions & 4 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -590,3 +590,7 @@ branch = "oxide/omicron"
# to it.
[patch.crates-io.omicron-workspace-hack]
path = "workspace-hack"

[patch.crates-io.zone]
git = 'https://github.com/oxidecomputer/zone'
branch = 'state-derive-eq-hash'
1 change: 1 addition & 0 deletions clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ impl From<omicron_common::api::internal::shared::NetworkInterfaceKind>
match s {
Instance { id } => Self::Instance(id),
Service { id } => Self::Service(id),
Probe { id } => Self::Probe(id),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions common/src/api/internal/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub enum NetworkInterfaceKind {
Instance { id: Uuid },
/// A vNIC associated with an internal service
Service { id: Uuid },
/// A vNIC associated with a probe
Probe { id: Uuid },
}

/// Information required to construct a virtual network interface
Expand Down
14 changes: 0 additions & 14 deletions common/src/nexus_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,6 @@ pub struct BackgroundTaskConfig {
pub inventory: InventoryConfig,
/// configuration for phantom disks task
pub phantom_disks: PhantomDiskConfig,
/// Configuration for probes task
pub probes: ProbesConfig,
}

#[serde_as]
Expand Down Expand Up @@ -451,14 +449,6 @@ pub struct PackageConfig {
pub default_region_allocation_strategy: RegionAllocationStrategy,
}

#[serde_as]
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct ProbesConfig {
/// period (in seconds) for periodic activations of this background task
#[serde_as(as = "DurationSeconds<u64>")]
pub period_secs: Duration,
}

#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct Config {
/// Configuration parameters known at compile-time.
Expand Down Expand Up @@ -534,7 +524,6 @@ mod test {
};
use crate::address::{Ipv6Subnet, RACK_PREFIX};
use crate::api::internal::shared::SwitchLocation;
use crate::nexus_config::ProbesConfig;
use dropshot::ConfigDropshot;
use dropshot::ConfigLogging;
use dropshot::ConfigLoggingIfExists;
Expand Down Expand Up @@ -791,9 +780,6 @@ mod test {
phantom_disks: PhantomDiskConfig {
period_secs: Duration::from_secs(30),
},
probes: ProbesConfig {
period_secs: Duration::from_secs(1),
},
},
default_region_allocation_strategy:
crate::nexus_config::RegionAllocationStrategy::Random {
Expand Down
33 changes: 10 additions & 23 deletions dev-tools/omdb/tests/successes.out
Original file line number Diff line number Diff line change
Expand Up @@ -59,43 +59,30 @@ note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=d
note: database schema version matches expected (<redacted database version>)
=============================================
EXECUTING COMMAND: omdb ["db", "services", "list-instances"]
termination: Exited(0)
termination: Exited(1)
---------------------------------------------
stdout:
SERVICE INSTANCE_ID ADDR SLED_SERIAL
CruciblePantry REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT sim-b6d65341
Dendrite REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT sim-b6d65341
Dendrite REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT sim-b6d65341
ExternalDns REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT sim-b6d65341
InternalDns REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT sim-b6d65341
Nexus REDACTED_UUID_REDACTED_UUID_REDACTED [::ffff:127.0.0.1]:REDACTED_PORT sim-b6d65341
Mgd REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT sim-b6d65341
Mgd REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT sim-b6d65341
---------------------------------------------
stderr:
note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=disable
note: database schema version matches expected (<redacted database version>)
Error: listing instances of kind Probe

Caused by:
Internal Error: unexpected database error: error in argument for $1: invalid input value for enum service_kind: "probe"
=============================================
EXECUTING COMMAND: omdb ["db", "services", "list-by-sled"]
termination: Exited(0)
termination: Exited(1)
---------------------------------------------
stdout:
sled: sim-b6d65341 (id REDACTED_UUID_REDACTED_UUID_REDACTED)

SERVICE INSTANCE_ID ADDR
CruciblePantry REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT
Dendrite REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT
Dendrite REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT
ExternalDns REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT
InternalDns REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT
Nexus REDACTED_UUID_REDACTED_UUID_REDACTED [::ffff:127.0.0.1]:REDACTED_PORT
Mgd REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT
Mgd REDACTED_UUID_REDACTED_UUID_REDACTED [::1]:REDACTED_PORT

---------------------------------------------
stderr:
note: using database URL postgresql://root@[::1]:REDACTED_PORT/omicron?sslmode=disable
note: database schema version matches expected (<redacted database version>)
Error: listing instances of kind Probe

Caused by:
Internal Error: unexpected database error: error in argument for $1: invalid input value for enum service_kind: "probe"
=============================================
EXECUTING COMMAND: omdb ["db", "sleds"]
termination: Exited(0)
Expand Down
4 changes: 2 additions & 2 deletions installinator/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ struct InstallOpts {
#[clap(long)]
install_on_gimlet: bool,

//TODO(ry) this probably needs to get plumbed somewhere instead of relying
//TODO this probably needs to get plumbed somewhere instead of relying
//on a default.
/// The first gimlet data link to use.
#[clap(long, default_value = "cxgbe0")]
data_link0: String,

//TODO(ry) this probably needs to get plumbed somewhere instead of relying
//TODO this probably needs to get plumbed somewhere instead of relying
//on a default.
/// The second gimlet data link to use.
#[clap(long, default_value = "cxgbe1")]
Expand Down
14 changes: 12 additions & 2 deletions nexus/db-model/src/external_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use nexus_types::external_api::views;
use omicron_common::address::NUM_SOURCE_NAT_PORTS;
use omicron_common::api::external::Error;
use omicron_common::api::external::IdentityMetadata;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
use std::convert::TryFrom;
Expand All @@ -32,7 +33,7 @@ impl_enum_type!(
#[diesel(postgres_type(name = "ip_kind"))]
pub struct IpKindEnum;

#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, PartialEq)]
#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, PartialEq, Serialize, Deserialize, JsonSchema)]
#[diesel(sql_type = IpKindEnum)]
pub enum IpKind;

Expand All @@ -51,7 +52,16 @@ impl_enum_type!(
/// addresses and port ranges, while source NAT IPs are not discoverable in the
/// API at all, and only provide outbound connectivity to instances, not
/// inbound.
#[derive(Debug, Clone, Selectable, Queryable, Insertable)]
#[derive(
Debug,
Clone,
Selectable,
Queryable,
Insertable,
Serialize,
Deserialize,
JsonSchema,
)]
#[diesel(table_name = external_ip)]
pub struct ExternalIp {
pub id: Uuid,
Expand Down
2 changes: 2 additions & 0 deletions nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ table! {
last_port -> Int4,

project_id -> Nullable<Uuid>,

is_probe -> Bool,
}
}

Expand Down
2 changes: 2 additions & 0 deletions nexus/db-model/src/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use diesel::deserialize::{self, FromSql};
use diesel::pg::Pg;
use diesel::serialize::{self, ToSql};
use diesel::sql_types;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::convert::TryFrom;

Expand Down Expand Up @@ -76,6 +77,7 @@ where
FromSqlRow,
Serialize,
Deserialize,
JsonSchema,
)]
#[diesel(sql_type = sql_types::Int4)]
#[repr(transparent)]
Expand Down
1 change: 1 addition & 0 deletions nexus/db-queries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pq-sys = "*"
rand.workspace = true
ref-cast.workspace = true
samael.workspace = true
schemars.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_urlencoded.workspace = true
Expand Down
69 changes: 69 additions & 0 deletions nexus/db-queries/src/db/datastore/external_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,32 @@ impl DataStore {
self.allocate_external_ip(opctx, data).await
}

/// Create an Ephemeral IP address for a probe.
pub async fn allocate_probe_ephemeral_ip(
&self,
opctx: &OpContext,
ip_id: Uuid,
probe_id: Uuid,
pool_name: Option<Name>,
) -> CreateResult<ExternalIp> {
let pool = match pool_name {
Some(name) => {
let (.., pool) = LookupPath::new(opctx, &self)
.ip_pool_name(&name)
.fetch_for(authz::Action::CreateChild)
.await?;
pool
}
// If no name given, use the default pool
None => self.ip_pools_fetch_default(&opctx).await?,
};

let pool_id = pool.identity.id;
let data =
IncompleteExternalIp::for_ephemeral(ip_id, probe_id, pool_id);
self.allocate_external_ip(opctx, data).await
}

/// Create an Ephemeral IP address for an instance.
pub async fn allocate_instance_ephemeral_ip(
&self,
Expand Down Expand Up @@ -341,6 +367,7 @@ impl DataStore {
diesel::update(dsl::external_ip)
.filter(dsl::time_deleted.is_null())
.filter(dsl::is_service.eq(false))
.filter(dsl::is_probe.eq(false))
.filter(dsl::parent_id.eq(instance_id))
.filter(dsl::kind.ne(IpKind::Floating))
.set(dsl::time_deleted.eq(now))
Expand All @@ -349,6 +376,30 @@ impl DataStore {
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))
}

/// Delete all external IP addresses associated with the provided probe
/// ID.
///
/// This method returns the number of records deleted, rather than the usual
/// `DeleteResult`. That's mostly useful for tests, but could be important
/// if callers have some invariants they'd like to check.
pub async fn deallocate_external_ip_by_probe_id(
&self,
opctx: &OpContext,
probe_id: Uuid,
) -> Result<usize, Error> {
use db::schema::external_ip::dsl;
let now = Utc::now();
diesel::update(dsl::external_ip)
.filter(dsl::time_deleted.is_null())
.filter(dsl::is_probe.eq(true))
.filter(dsl::parent_id.eq(probe_id))
.filter(dsl::kind.ne(IpKind::Floating))
.set(dsl::time_deleted.eq(now))
.execute_async(&*self.pool_connection_authorized(opctx).await?)
.await
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))
}

/// Detach an individual Floating IP address from its parent instance.
///
/// As in `deallocate_external_ip_by_instance_id`, this method returns the
Expand Down Expand Up @@ -379,6 +430,7 @@ impl DataStore {
use db::schema::external_ip::dsl;
dsl::external_ip
.filter(dsl::is_service.eq(false))
.filter(dsl::is_probe.eq(false))
.filter(dsl::parent_id.eq(instance_id))
.filter(dsl::time_deleted.is_null())
.select(ExternalIp::as_select())
Expand All @@ -387,6 +439,23 @@ impl DataStore {
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))
}

/// Fetch all external IP addresses of any kind for the provided probe
pub async fn probe_lookup_external_ips(
&self,
opctx: &OpContext,
probe_id: Uuid,
) -> LookupResult<Vec<ExternalIp>> {
use db::schema::external_ip::dsl;
dsl::external_ip
.filter(dsl::is_probe.eq(true))
.filter(dsl::parent_id.eq(probe_id))
.filter(dsl::time_deleted.is_null())
.select(ExternalIp::as_select())
.get_results_async(&*self.pool_connection_authorized(opctx).await?)
.await
.map_err(|e| public_error_from_diesel(e, ErrorHandler::Server))
}

/// Fetch all Floating IP addresses for the provided project.
pub async fn floating_ips_list(
&self,
Expand Down
1 change: 1 addition & 0 deletions nexus/db-queries/src/db/datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub use db_metadata::{
pub use dns::DnsVersionUpdateBuilder;
pub use instance::InstanceAndActiveVmm;
pub use inventory::DataStoreInventoryTest;
pub use probe::ProbeInfo;
pub use rack::RackInit;
pub use silo::Discoverability;
pub use switch_port::SwitchPortSettingsCombinedResult;
Expand Down
Loading

0 comments on commit 81d8ee9

Please sign in to comment.