From 305b758040879a4b9935d1d99046b1c1ac16ec9d Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Sun, 30 Apr 2023 00:21:40 -0400 Subject: [PATCH] Read the CRDB address from the running zone --- illumos-utils/src/running_zone.rs | 4 ++++ sled-agent/src/params.rs | 2 ++ sled-agent/src/services.rs | 21 +++++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/illumos-utils/src/running_zone.rs b/illumos-utils/src/running_zone.rs index f26aa82721b..eda6b00ef92 100644 --- a/illumos-utils/src/running_zone.rs +++ b/illumos-utils/src/running_zone.rs @@ -147,6 +147,10 @@ impl RunningZone { format!("{}/root", self.inner.zonepath.display()) } + pub fn control_interface(&self) -> AddrObject { + AddrObject::new(self.inner.get_control_vnic_name(), "omicron6").unwrap() + } + /// Runs a command within the Zone, return the output. pub fn run_cmd(&self, args: I) -> Result where diff --git a/sled-agent/src/params.rs b/sled-agent/src/params.rs index 0b80c434b4d..84ba8a083a8 100644 --- a/sled-agent/src/params.rs +++ b/sled-agent/src/params.rs @@ -521,6 +521,8 @@ impl std::fmt::Display for ZoneType { )] pub struct ServiceZoneRequest { // The UUID of the zone to be initialized. + // TODO: Should this be removed? If we have UUIDs on the services, what's + // the point of this? pub id: Uuid, // The type of the zone to be created. pub zone_type: ZoneType, diff --git a/sled-agent/src/services.rs b/sled-agent/src/services.rs index da20294c4d2..c7d9c59a921 100644 --- a/sled-agent/src/services.rs +++ b/sled-agent/src/services.rs @@ -169,6 +169,9 @@ pub enum Error { #[error("Services already configured for this Sled Agent")] ServicesAlreadyConfigured, + #[error("Failed to get address: {0}")] + GetAddressFailure(#[from] illumos_utils::zone::GetAddressError), + #[error("NTP zone not ready")] NtpZoneNotReady, @@ -1871,13 +1874,18 @@ impl ServiceManager { pub async fn cockroachdb_initialize(&self) -> Result<(), Error> { let log = &self.inner.log; - // TODO: Can we confirm this address is okay? - let host = &format!("[::1]:{COCKROACH_PORT}"); let dataset_zones = self.inner.dataset_zones.lock().await; for zone in dataset_zones.iter() { // TODO: We could probably store the ZoneKind in the running zone to - // make this a bit safer. - if zone.name().contains("cockroach") { + // make this "comparison to existing zones by name" mechanism a bit + // safer. + if zone.name().contains(&ZoneType::CockroachDb.to_string()) { + let address = Zones::get_address( + Some(zone.name()), + &zone.control_interface(), + )? + .network(); + let host = &format!("[{address}]:{COCKROACH_PORT}"); info!(log, "Initializing CRDB Cluster"); zone.run_cmd(&[ "/opt/oxide/cockroachdb/bin/cockroach", @@ -1909,6 +1917,11 @@ impl ServiceManager { ]) .map_err(|err| Error::CockroachInit { err })?; info!(log, "Formatting CRDB - Completed"); + + // In the single-sled case, if there are multiple CRDB nodes on + // a single device, we'd still only want to send the + // initialization requests to a single dataset. + return Ok(()); } }