Skip to content

Commit 31b52a7

Browse files
committed
Refuse to enact a sled plan unless it's on the explicit set
1 parent 5752a83 commit 31b52a7

File tree

2 files changed

+10
-63
lines changed

2 files changed

+10
-63
lines changed

sled-agent/src/rack_setup/plan/sled.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::rack_setup::config::SetupServiceConfig as Config;
1313
use serde::{Deserialize, Serialize};
1414
use slog::Logger;
1515
use sprockets_host::Ed25519Certificate;
16-
use std::collections::HashMap;
16+
use std::collections::{HashMap, HashSet};
1717
use std::net::{Ipv6Addr, SocketAddrV6};
1818
use std::path::{Path, PathBuf};
1919
use thiserror::Error;
@@ -119,7 +119,7 @@ impl Plan {
119119
pub async fn create(
120120
log: &Logger,
121121
config: &Config,
122-
bootstrap_addrs: Vec<Ipv6Addr>,
122+
bootstrap_addrs: HashSet<Ipv6Addr>,
123123
) -> Result<Self, PlanError> {
124124
let rack_id = Uuid::new_v4();
125125

sled-agent/src/rack_setup/service.rs

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -438,56 +438,6 @@ impl ServiceInner {
438438
Ok(())
439439
}
440440

441-
/// Waits for sufficient neighbors to exist so the initial set of requests
442-
/// can be sent out.
443-
async fn wait_for_peers(
444-
&self,
445-
expectation: &HashSet<Ipv6Addr>,
446-
our_bootstrap_address: Ipv6Addr,
447-
) -> Result<Vec<Ipv6Addr>, DdmError> {
448-
let ddm_admin_client = DdmAdminClient::localhost(&self.log)?;
449-
let addrs = retry_notify(
450-
retry_policy_internal_service_aggressive(),
451-
|| async {
452-
let peer_addrs = ddm_admin_client
453-
.derive_bootstrap_addrs_from_prefixes(&[
454-
BootstrapInterface::GlobalZone,
455-
])
456-
.await
457-
.map_err(|err| {
458-
BackoffError::transient(format!(
459-
"Failed getting peers from mg-ddm: {err}"
460-
))
461-
})?;
462-
463-
let all_addrs = peer_addrs
464-
.chain(iter::once(our_bootstrap_address))
465-
.collect::<HashSet<_>>();
466-
467-
if all_addrs.is_superset(expectation) {
468-
Ok(all_addrs.into_iter().collect())
469-
} else {
470-
Err(BackoffError::transient(
471-
"Waiting for a set of peers not found yet".to_string(),
472-
))
473-
}
474-
},
475-
|message, duration| {
476-
info!(
477-
self.log,
478-
"{} (will retry after {:?})", message, duration
479-
);
480-
},
481-
)
482-
// `retry_policy_internal_service_aggressive()` retries indefinitely on
483-
// transient errors (the only kind we produce), allowing us to
484-
// `.unwrap()` without panicking
485-
.await
486-
.unwrap();
487-
488-
Ok(addrs)
489-
}
490-
491441
async fn sled_timesync(
492442
&self,
493443
sled_address: &SocketAddrV6,
@@ -897,7 +847,7 @@ impl ServiceInner {
897847
// Wait for either:
898848
// - All the peers to re-load an old plan (if one exists)
899849
// - Enough peers to create a new plan (if one does not exist)
900-
let expected_peers = match &config.bootstrap_discovery {
850+
let bootstrap_addrs = match &config.bootstrap_discovery {
901851
BootstrapAddressDiscovery::OnlyOurs => {
902852
HashSet::from([local_bootstrap_agent.our_address()])
903853
}
@@ -907,18 +857,15 @@ impl ServiceInner {
907857
if let Some(plan) = &maybe_sled_plan {
908858
let stored_peers: HashSet<Ipv6Addr> =
909859
plan.sleds.keys().map(|a| *a.ip()).collect();
910-
if stored_peers != expected_peers {
860+
if stored_peers != bootstrap_addrs {
911861
return Err(SetupServiceError::BadConfig("Set of sleds requested does not match those in existing sled plan".to_string()));
912862
}
913863
}
914-
915-
let addrs = self
916-
.wait_for_peers(
917-
&expected_peers,
918-
local_bootstrap_agent.our_address(),
919-
)
920-
.await?;
921-
info!(self.log, "Enough peers exist to enact RSS plan");
864+
if bootstrap_addrs.is_empty() {
865+
return Err(SetupServiceError::BadConfig(
866+
"Must request at least one peer".to_string(),
867+
));
868+
}
922869

923870
// If we created a plan, reuse it. Otherwise, create a new plan.
924871
//
@@ -931,7 +878,7 @@ impl ServiceInner {
931878
plan
932879
} else {
933880
info!(self.log, "Creating new allocation plan");
934-
SledPlan::create(&self.log, config, addrs).await?
881+
SledPlan::create(&self.log, config, bootstrap_addrs).await?
935882
};
936883
let config = &plan.config;
937884

0 commit comments

Comments
 (0)