Skip to content

Commit

Permalink
Read the CRDB address from the running zone
Browse files Browse the repository at this point in the history
  • Loading branch information
smklein committed Apr 30, 2023
1 parent ffb5fcd commit 305b758
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 4 additions & 0 deletions illumos-utils/src/running_zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I, S>(&self, args: I) -> Result<String, RunCommandError>
where
Expand Down
2 changes: 2 additions & 0 deletions sled-agent/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 17 additions & 4 deletions sled-agent/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(());
}
}

Expand Down

0 comments on commit 305b758

Please sign in to comment.